Skip to content

Commit

Permalink
feat: add next page constant (#153)
Browse files Browse the repository at this point in the history
* feat: add next page constant

* only choose random words when randomize is true

* severalPages => multiplePages
  • Loading branch information
henriettemoe authored Apr 21, 2023
1 parent a9e49da commit 80f11be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion library.json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ declare const json: {
]
}

export default json;
export default json;
2 changes: 1 addition & 1 deletion semantics.json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,4 @@ declare const json: [
}
]

export default json;
export default json;
10 changes: 6 additions & 4 deletions src/components/VocabularyDrill/VocabularyDrill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../types/types';
import { findLibraryInfo, libraryToString } from '../../utils/h5p.utils';
import { isNil } from '../../utils/type.utils';
import { parseWords, pickWords, parseSourceAndTarget } from '../../utils/word.utils';
import { parseWords, pickWords, parseSourceAndTarget, pickRandomWords } from '../../utils/word.utils';
import { StatusBar } from '../StatusBar/StatusBar';
import { Toolbar } from '../Toolbar/Toolbar';

Expand Down Expand Up @@ -147,6 +147,8 @@ export const VocabularyDrill: FC<VocabularyDrillProps> = ({
const initialLanguageMode =
previousState?.activeLanguageMode ?? LanguageModeType.Target;

const enableMultiplePages = false;

const { t } = useTranslation();
const contentId = useContentId();

Expand Down Expand Up @@ -180,10 +182,10 @@ export const VocabularyDrill: FC<VocabularyDrillProps> = ({
? behaviour.numberOfWordsToShow
: totalNumberOfWords;

const pickedWords = pickWords(words.current, page, numberOfWordsToShow);
const pickedWords = enableMultiplePages || !randomize ? pickWords(words.current, page, numberOfWordsToShow) : pickRandomWords(words.current, numberOfWordsToShow);

const totalPages = Math.ceil(totalNumberOfWords / numberOfWordsToShow);
const severalPages = totalPages > 1;
const multiplePages = totalPages > 1;
const showNextButton = (page + 1) * numberOfWordsToShow < totalNumberOfWords;

const dragTextLibraryInfo = findLibraryInfo('H5P.DragText');
Expand Down Expand Up @@ -358,7 +360,7 @@ export const VocabularyDrill: FC<VocabularyDrillProps> = ({
disableTools={disableTools}
/>
<div ref={wrapperRef} />
{severalPages && (
{enableMultiplePages && multiplePages && (
<StatusBar page={page + 1} totalPages={totalPages} score={score} totalScore={totalNumberOfWords} showNextButton={showNextButton} disableNextButton={disableNextButton} onNext={handleNext} />
)}
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/utils/word.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export const pickWords = (
return words.slice(page * pageSize, pageSize + page * pageSize);
};

/**
* Picks a random set of words from the list of words.
*/
export const pickRandomWords = (
words: Array<string>,
pageSize: number,
): Array<string> => {
const randomWords = getRandomWords(words);
return randomWords.slice(0, pageSize);
};

/**
* Creates a word string for the H5P.Blanks content type.
* H5P.Blanks expects the input as an HTML string on the format `source *target*`.
Expand Down

0 comments on commit 80f11be

Please sign in to comment.