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.
|
* Creates new progress document.
|
||||||
* @param {object} data The data passed to the function.
|
* @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 {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.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.
|
* @return {string} The ID of the created progress document.
|
||||||
*/
|
*/
|
||||||
exports.createProgress = functions.https.onCall((data, context) => {
|
exports.createProgress = functions.https.onCall((data, context) => {
|
||||||
@@ -237,6 +238,7 @@ exports.createProgress = functions.https.onCall((data, context) => {
|
|||||||
setIds: setIds,
|
setIds: setIds,
|
||||||
set_titles: setIds.map((setId) => setTitlesDict[setId]),
|
set_titles: setIds.map((setId) => setTitlesDict[setId]),
|
||||||
typo: false,
|
typo: false,
|
||||||
|
ignoreCaps: data.ignoreCaps,
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -462,9 +464,14 @@ function arraysHaveSameMembers(arr1, arr2) {
|
|||||||
* @param {string} item The term/definition to remove the characters that should be ignored from.
|
* @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.
|
* @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;
|
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) {
|
if (index !== -1) {
|
||||||
cleansedDoneSplitCorrectAnswers.push(
|
cleansedDoneSplitCorrectAnswers.push(
|
||||||
cleanseVocabString(
|
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 cleansedSplitCorrectAnswers = cleansedNotDoneSplitCorrectAnswers.concat(cleansedDoneSplitCorrectAnswers);
|
||||||
const cleansedInputAnswer = cleanseVocabString(inputAnswer);
|
const cleansedInputAnswer = cleanseVocabString(inputAnswer, docData.ignoreCaps);
|
||||||
|
|
||||||
let isCorrectAnswer = false;
|
let isCorrectAnswer = false;
|
||||||
let correctAnswerIndex;
|
let correctAnswerIndex;
|
||||||
|
|||||||
@@ -61,6 +61,15 @@ export default function ClassicTestStart(props) {
|
|||||||
<span>Switch language</span>
|
<span>Switch language</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<Checkbox
|
||||||
|
checked={props.ignoreCaps}
|
||||||
|
onChange={props.handleIgnoreCapsChange}
|
||||||
|
inputProps={{ 'aria-label': 'checkbox' }}
|
||||||
|
/>
|
||||||
|
<span>Ignore capitals</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => props.startTest("questions")}
|
onClick={() => props.startTest("questions")}
|
||||||
icon={<ArrowForwardRoundedIcon />}
|
icon={<ArrowForwardRoundedIcon />}
|
||||||
|
|||||||
@@ -61,6 +61,15 @@ export default function LivesTestStart(props) {
|
|||||||
<span>Switch language</span>
|
<span>Switch language</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<Checkbox
|
||||||
|
checked={props.ignoreCaps}
|
||||||
|
onChange={props.handleIgnoreCapsChange}
|
||||||
|
inputProps={{ 'aria-label': 'checkbox' }}
|
||||||
|
/>
|
||||||
|
<span>Ignore capitals</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => props.startTest("lives")}
|
onClick={() => props.startTest("lives")}
|
||||||
icon={<ArrowForwardRoundedIcon />}
|
icon={<ArrowForwardRoundedIcon />}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export default withRouter(class LoggedInHome extends React.Component {
|
|||||||
showLivesTestStart: false,
|
showLivesTestStart: false,
|
||||||
sliderValue: 1,
|
sliderValue: 1,
|
||||||
switchLanguage: false,
|
switchLanguage: false,
|
||||||
|
ignoreCaps: false,
|
||||||
totalTestQuestions: 1,
|
totalTestQuestions: 1,
|
||||||
pendingDeletions: {},
|
pendingDeletions: {},
|
||||||
};
|
};
|
||||||
@@ -199,6 +200,7 @@ export default withRouter(class LoggedInHome extends React.Component {
|
|||||||
switch_language: this.state.switchLanguage,
|
switch_language: this.state.switchLanguage,
|
||||||
mode: mode,
|
mode: mode,
|
||||||
limit: this.state.sliderValue,
|
limit: this.state.sliderValue,
|
||||||
|
ignoreCaps: this.state.ignoreCaps,
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
const progressId = result.data;
|
const progressId = result.data;
|
||||||
this.stopLoading();
|
this.stopLoading();
|
||||||
@@ -351,6 +353,12 @@ export default withRouter(class LoggedInHome extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleIgnoreCapsChange = (event) => {
|
||||||
|
this.setState({
|
||||||
|
ignoreCaps: event.target.checked,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -570,7 +578,9 @@ export default withRouter(class LoggedInHome extends React.Component {
|
|||||||
sliderValue={this.state.sliderValue}
|
sliderValue={this.state.sliderValue}
|
||||||
onSliderChange={this.changeSliderValue}
|
onSliderChange={this.changeSliderValue}
|
||||||
switchLanguage={this.state.switchLanguage}
|
switchLanguage={this.state.switchLanguage}
|
||||||
|
ignoreCaps={this.state.ignoreCaps}
|
||||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||||
|
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||||
loading={this.state.loading}
|
loading={this.state.loading}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -583,7 +593,9 @@ export default withRouter(class LoggedInHome extends React.Component {
|
|||||||
sliderValue={this.state.sliderValue}
|
sliderValue={this.state.sliderValue}
|
||||||
onSliderChange={this.changeSliderValue}
|
onSliderChange={this.changeSliderValue}
|
||||||
switchLanguage={this.state.switchLanguage}
|
switchLanguage={this.state.switchLanguage}
|
||||||
|
ignoreCaps={this.state.ignoreCaps}
|
||||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||||
|
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||||
loading={this.state.loading}
|
loading={this.state.loading}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export default withRouter(class Progress extends React.Component {
|
|||||||
pageLoaded: false,
|
pageLoaded: false,
|
||||||
startTime: null,
|
startTime: null,
|
||||||
sound: false,
|
sound: false,
|
||||||
|
ignoreCaps: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export default withRouter(class SetPage extends React.Component {
|
|||||||
showLivesTestStart: false,
|
showLivesTestStart: false,
|
||||||
sliderValue: 1,
|
sliderValue: 1,
|
||||||
switchLanguage: false,
|
switchLanguage: false,
|
||||||
|
ignoreCaps: false,
|
||||||
totalTestQuestions: 1,
|
totalTestQuestions: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,6 +135,7 @@ export default withRouter(class SetPage extends React.Component {
|
|||||||
switch_language: this.state.switchLanguage,
|
switch_language: this.state.switchLanguage,
|
||||||
mode: mode,
|
mode: mode,
|
||||||
limit: this.state.sliderValue,
|
limit: this.state.sliderValue,
|
||||||
|
ignoreCaps: this.state.ignoreCaps,
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
const progressId = result.data;
|
const progressId = result.data;
|
||||||
this.stopLoading();
|
this.stopLoading();
|
||||||
@@ -332,6 +334,12 @@ export default withRouter(class SetPage extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleIgnoreCapsChange = (event) => {
|
||||||
|
this.setState({
|
||||||
|
ignoreCaps: event.target.checked,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -479,7 +487,9 @@ export default withRouter(class SetPage extends React.Component {
|
|||||||
sliderValue={this.state.sliderValue}
|
sliderValue={this.state.sliderValue}
|
||||||
onSliderChange={this.changeSliderValue}
|
onSliderChange={this.changeSliderValue}
|
||||||
switchLanguage={this.state.switchLanguage}
|
switchLanguage={this.state.switchLanguage}
|
||||||
|
ignoreCaps={this.state.ignoreCaps}
|
||||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||||
|
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||||
loading={this.state.loading}
|
loading={this.state.loading}
|
||||||
disabled={!this.state.canStartTest}
|
disabled={!this.state.canStartTest}
|
||||||
/>
|
/>
|
||||||
@@ -493,7 +503,9 @@ export default withRouter(class SetPage extends React.Component {
|
|||||||
sliderValue={this.state.sliderValue}
|
sliderValue={this.state.sliderValue}
|
||||||
onSliderChange={this.changeSliderValue}
|
onSliderChange={this.changeSliderValue}
|
||||||
switchLanguage={this.state.switchLanguage}
|
switchLanguage={this.state.switchLanguage}
|
||||||
|
ignoreCaps={this.state.ignoreCaps}
|
||||||
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
handleSwitchLanguageChange={this.handleSwitchLanguageChange}
|
||||||
|
handleIgnoreCapsChange={this.handleIgnoreCapsChange}
|
||||||
loading={this.state.loading}
|
loading={this.state.loading}
|
||||||
disabled={!this.state.canStartTest}
|
disabled={!this.state.canStartTest}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user