Add ability to ignore capitals during tests
This commit is contained in:
@@ -140,10 +140,11 @@ exports.getGroupMembers = functions.https.onCall((data, context) => {
|
||||
/**
|
||||
* Creates new progress document.
|
||||
* @param {object} data The data passed to the function.
|
||||
* @param {boolean} data.ignoreCaps Whether capitalisation of answers should matter during the test.
|
||||
* @param {boolean} data.limit The maximum number of lives/questions for the test.
|
||||
* @param {boolean} data.mode The mode to be tested in. Valid options are "questions" and "lives".
|
||||
* @param {array} data.sets An array of IDs of the desired sets.
|
||||
* @param {boolean} data.switch_language Whether or not the languages should be reversed.
|
||||
* @param {boolean} data.mode The mode to be tested in. Valid options are "questions" and "lives".
|
||||
* @param {boolean} data.limit The maximum number of lives/questions for the test.
|
||||
* @return {string} The ID of the created progress document.
|
||||
*/
|
||||
exports.createProgress = functions.https.onCall((data, context) => {
|
||||
@@ -237,6 +238,7 @@ exports.createProgress = functions.https.onCall((data, context) => {
|
||||
setIds: setIds,
|
||||
set_titles: setIds.map((setId) => setTitlesDict[setId]),
|
||||
typo: false,
|
||||
ignoreCaps: data.ignoreCaps,
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -462,9 +464,14 @@ function arraysHaveSameMembers(arr1, arr2) {
|
||||
* @param {string} item The term/definition to remove the characters that should be ignored from.
|
||||
* @return {string} The original string with the unwanted characters removed.
|
||||
*/
|
||||
function cleanseVocabString(item) {
|
||||
function cleanseVocabString(item, ignoreCaps=false) {
|
||||
const chars = /[\p{P}\p{S} ]+/ug;
|
||||
return item.replace(chars, "");
|
||||
const cleansed = item.replace(chars, "");
|
||||
if (ignoreCaps) {
|
||||
return cleansed.toLowerCase();
|
||||
} else {
|
||||
return cleansed;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -541,15 +548,16 @@ exports.processAnswer = functions.https.onCall((data, context) => {
|
||||
if (index !== -1) {
|
||||
cleansedDoneSplitCorrectAnswers.push(
|
||||
cleanseVocabString(
|
||||
notDoneSplitCorrectAnswers.splice(index, 1)[0]
|
||||
notDoneSplitCorrectAnswers.splice(index, 1)[0],
|
||||
docData.ignoreCaps
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
const cleansedNotDoneSplitCorrectAnswers = notDoneSplitCorrectAnswers.map((answer) => cleanseVocabString(answer));
|
||||
const cleansedNotDoneSplitCorrectAnswers = notDoneSplitCorrectAnswers.map((answer) => cleanseVocabString(answer, docData.ignoreCaps));
|
||||
|
||||
const cleansedSplitCorrectAnswers = cleansedNotDoneSplitCorrectAnswers.concat(cleansedDoneSplitCorrectAnswers);
|
||||
const cleansedInputAnswer = cleanseVocabString(inputAnswer);
|
||||
const cleansedInputAnswer = cleanseVocabString(inputAnswer, docData.ignoreCaps);
|
||||
|
||||
let isCorrectAnswer = false;
|
||||
let correctAnswerIndex;
|
||||
|
||||
@@ -61,6 +61,15 @@ export default function ClassicTestStart(props) {
|
||||
<span>Switch language</span>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<Checkbox
|
||||
checked={props.ignoreCaps}
|
||||
onChange={props.handleIgnoreCapsChange}
|
||||
inputProps={{ 'aria-label': 'checkbox' }}
|
||||
/>
|
||||
<span>Ignore capitals</span>
|
||||
</label>
|
||||
|
||||
<Button
|
||||
onClick={() => props.startTest("questions")}
|
||||
icon={<ArrowForwardRoundedIcon />}
|
||||
|
||||
@@ -61,6 +61,15 @@ export default function LivesTestStart(props) {
|
||||
<span>Switch language</span>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<Checkbox
|
||||
checked={props.ignoreCaps}
|
||||
onChange={props.handleIgnoreCapsChange}
|
||||
inputProps={{ 'aria-label': 'checkbox' }}
|
||||
/>
|
||||
<span>Ignore capitals</span>
|
||||
</label>
|
||||
|
||||
<Button
|
||||
onClick={() => props.startTest("lives")}
|
||||
icon={<ArrowForwardRoundedIcon />}
|
||||
|
||||
@@ -72,6 +72,7 @@ export default withRouter(class LoggedInHome extends React.Component {
|
||||
showLivesTestStart: false,
|
||||
sliderValue: 1,
|
||||
switchLanguage: false,
|
||||
ignoreCaps: false,
|
||||
totalTestQuestions: 1,
|
||||
pendingDeletions: {},
|
||||
};
|
||||
@@ -199,6 +200,7 @@ export default withRouter(class LoggedInHome extends React.Component {
|
||||
switch_language: this.state.switchLanguage,
|
||||
mode: mode,
|
||||
limit: this.state.sliderValue,
|
||||
ignoreCaps: this.state.ignoreCaps,
|
||||
}).then((result) => {
|
||||
const progressId = result.data;
|
||||
this.stopLoading();
|
||||
@@ -351,6 +353,12 @@ export default withRouter(class LoggedInHome extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleIgnoreCapsChange = (event) => {
|
||||
this.setState({
|
||||
ignoreCaps: event.target.checked,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
@@ -570,7 +578,9 @@ export default withRouter(class LoggedInHome extends React.Component {
|
||||
sliderValue={this.state.sliderValue}
|
||||
onSliderChange={this.changeSliderValue}
|
||||
switchLanguage={this.state.switchLanguage}
|
||||
ignoreCaps={this.state.ignoreCaps}
|
||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||
loading={this.state.loading}
|
||||
/>
|
||||
}
|
||||
@@ -583,7 +593,9 @@ export default withRouter(class LoggedInHome extends React.Component {
|
||||
sliderValue={this.state.sliderValue}
|
||||
onSliderChange={this.changeSliderValue}
|
||||
switchLanguage={this.state.switchLanguage}
|
||||
ignoreCaps={this.state.ignoreCaps}
|
||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||
loading={this.state.loading}
|
||||
/>
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ export default withRouter(class Progress extends React.Component {
|
||||
pageLoaded: false,
|
||||
startTime: null,
|
||||
sound: false,
|
||||
ignoreCaps: false,
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
|
||||
@@ -53,6 +53,7 @@ export default withRouter(class SetPage extends React.Component {
|
||||
showLivesTestStart: false,
|
||||
sliderValue: 1,
|
||||
switchLanguage: false,
|
||||
ignoreCaps: false,
|
||||
totalTestQuestions: 1,
|
||||
};
|
||||
|
||||
@@ -134,6 +135,7 @@ export default withRouter(class SetPage extends React.Component {
|
||||
switch_language: this.state.switchLanguage,
|
||||
mode: mode,
|
||||
limit: this.state.sliderValue,
|
||||
ignoreCaps: this.state.ignoreCaps,
|
||||
}).then((result) => {
|
||||
const progressId = result.data;
|
||||
this.stopLoading();
|
||||
@@ -332,6 +334,12 @@ export default withRouter(class SetPage extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleIgnoreCapsChange = (event) => {
|
||||
this.setState({
|
||||
ignoreCaps: event.target.checked,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
@@ -479,7 +487,9 @@ export default withRouter(class SetPage extends React.Component {
|
||||
sliderValue={this.state.sliderValue}
|
||||
onSliderChange={this.changeSliderValue}
|
||||
switchLanguage={this.state.switchLanguage}
|
||||
ignoreCaps={this.state.ignoreCaps}
|
||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||
loading={this.state.loading}
|
||||
disabled={!this.state.canStartTest}
|
||||
/>
|
||||
@@ -493,7 +503,9 @@ export default withRouter(class SetPage extends React.Component {
|
||||
sliderValue={this.state.sliderValue}
|
||||
onSliderChange={this.changeSliderValue}
|
||||
switchLanguage={this.state.switchLanguage}
|
||||
ignoreCaps={this.state.ignoreCaps}
|
||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||
loading={this.state.loading}
|
||||
disabled={!this.state.canStartTest}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user