From 80f11bec867dad3905accc4bc1a5385d3997d4bb Mon Sep 17 00:00:00 2001 From: Henriette Moe <35261194+henriettemoe@users.noreply.github.com> Date: Fri, 21 Apr 2023 12:30:52 +0200 Subject: [PATCH] feat: add next page constant (#153) * feat: add next page constant * only choose random words when randomize is true * severalPages => multiplePages --- library.json.d.ts | 2 +- semantics.json.d.ts | 2 +- src/components/VocabularyDrill/VocabularyDrill.tsx | 10 ++++++---- src/utils/word.utils.ts | 11 +++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/library.json.d.ts b/library.json.d.ts index 107e0a2f..51f732a3 100644 --- a/library.json.d.ts +++ b/library.json.d.ts @@ -42,4 +42,4 @@ declare const json: { ] } -export default json; +export default json; \ No newline at end of file diff --git a/semantics.json.d.ts b/semantics.json.d.ts index b0c9fc6b..6981c934 100644 --- a/semantics.json.d.ts +++ b/semantics.json.d.ts @@ -519,4 +519,4 @@ declare const json: [ } ] -export default json; +export default json; \ No newline at end of file diff --git a/src/components/VocabularyDrill/VocabularyDrill.tsx b/src/components/VocabularyDrill/VocabularyDrill.tsx index 9d3d8905..3925d7c7 100644 --- a/src/components/VocabularyDrill/VocabularyDrill.tsx +++ b/src/components/VocabularyDrill/VocabularyDrill.tsx @@ -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'; @@ -147,6 +147,8 @@ export const VocabularyDrill: FC = ({ const initialLanguageMode = previousState?.activeLanguageMode ?? LanguageModeType.Target; + const enableMultiplePages = false; + const { t } = useTranslation(); const contentId = useContentId(); @@ -180,10 +182,10 @@ export const VocabularyDrill: FC = ({ ? 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'); @@ -358,7 +360,7 @@ export const VocabularyDrill: FC = ({ disableTools={disableTools} />
- {severalPages && ( + {enableMultiplePages && multiplePages && ( )}
diff --git a/src/utils/word.utils.ts b/src/utils/word.utils.ts index bf3e5594..33fc2264 100644 --- a/src/utils/word.utils.ts +++ b/src/utils/word.utils.ts @@ -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, + pageSize: number, +): Array => { + 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*`.