Skip to content

Commit

Permalink
feat: multiple pages score view (#186)
Browse files Browse the repository at this point in the history
* feat: add last page and restart button

* feat: add ScoreBar and ScorePage

* use overallFeedback

* refactor: adjust ScorePage

* fix: make Statusbar visible on ScorePage

* refactor: ScoreBar

* chore: add typing for `H5P.JoubelUI`

* refactor: group all h5p extensions in one declaration file

* refactor: use `reference` to import JoubelUI types

* refactor: include h5p-extensions.d.ts in tsconfig

* fix: add translations

* refactor: use JoubelProgressbar

* fix: re-add margin-top

* chore: update `h5p-types-joubel-ui`

* chore: update `h5p-types-joubel-ui`

* fix: translation in nn.json

* fix: make sure to trim list of words

* fix: ensure color contrast on next button

* bump patch version

---------

Co-authored-by: Sindre Bøyum <[email protected]>
  • Loading branch information
henriettemoe and boyum authored May 10, 2023
1 parent 5799490 commit 129cfbf
Show file tree
Hide file tree
Showing 21 changed files with 409 additions and 52 deletions.
13 changes: 8 additions & 5 deletions .h5pignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
.github
build_info
node_modules
src
.github
.eslintignore
.eslintrc.json
.gitignore
.h5pignore
h5p-extensions.d.ts
jest.config.js
semantics.json.d.ts
library.json.d.ts
build_info
package.json
package-lock.json
package.json
README.md
webpack.config.js
semantics.json.d.ts
tsconfig.json
webpack.config.js
2 changes: 2 additions & 0 deletions build_info/repos
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
https://github.com/h5p/h5p-blanks.git
https://github.com/h5p/h5p-drag-text.git
https://github.com/h5p/h5p-editor-radio-group.git
https://github.com/h5p/h5p-joubel-ui.git
https://github.com/h5p/h5p-question.git
https://github.com/NDLANO/h5p-editor-csv-to-text.git
1 change: 1 addition & 0 deletions h5p-extensions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'h5p-types-joubel-ui';
28 changes: 28 additions & 0 deletions language/.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@
"label": "Changed language mode aria",
"default": "Swapped language from @sourceLanguage to @targetLanguage"
},
{
"label": "Text for \"Next\" button",
"default": "Next"
},
{
"label": "Text for \"Finish\" button",
"default": "Finish"
},
{
"label": "Text for \"Restart\" button",
"default": "Restart"
},
{
"label": "Score label",
"default": "Score"
},
{
"label": "Textual representation of the score bar for those using a readspeaker",
"default": "You got @score out of @maxScore points"
},
{
"label": "Textual representation of the page numbers for those using a readspeaker",
"default": "Page @page of @totalPages"
},
{
"label": "Feedback text",
"default": "Your total score"
},
{
"label": "English",
"default": "English"
Expand Down
28 changes: 28 additions & 0 deletions language/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@
"label": "Endret språkmodus aria",
"default": "Byttet språk fra @sourceLanguage til @targetLanguage"
},
{
"label": "Tekst for \"Neste\" knapp",
"default": "Neste"
},
{
"label": "Tekst for \"Fullfør\" knapp",
"default": "Fullfør"
},
{
"label": "Tekst for \"Start på nytt\" knapp",
"default": "Start på nytt"
},
{
"label": "Resultat etikett",
"default": "Resultat"
},
{
"label": "Tekstlig representasjon av resultatlinjen for de som bruker en skjermleser",
"default": "Du fikk @score av @maxScore poeng"
},
{
"label": "Tekstlig representasjon av sidetall for de som bruker en skjermleser",
"default": "Side @page av @totalPages"
},
{
"label": "Tilbakemelding-tekst",
"default": "Ditt resultat"
},
{
"label": "Engelsk",
"default": "Engelsk"
Expand Down
28 changes: 28 additions & 0 deletions language/nn.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@
"label": "Endret språkmodus aria",
"default": "Bytte språk frå @sourceLanguage til @targetLanguage"
},
{
"label": "Tekst for \"Neste\" knapp",
"default": "Neste"
},
{
"label": "Tekst for \"Fullfør\" knapp",
"default": "Fullfør"
},
{
"label": "Tekst for \"Start på nytt\" knapp",
"default": "Start på nytt"
},
{
"label": "Resultat etikett",
"default": "Resultat"
},
{
"label": "Tekstleg representasjon av resultatlinja for dei som bruker ein skjermlesar",
"default": "Du fekk @score av @maxScore poeng"
},
{
"label": "Tekstleg representasjon av sidetal for dei som bruker ein skjermlesar",
"default": "Side @page av @totalPages"
},
{
"label": "Tilbakemelding-tekst",
"default": "Ditt resultat"
},
{
"label": "Engelsk",
"default": "Engelsk"
Expand Down
12 changes: 11 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"machineName": "H5P.VocabularyDrill",
"majorVersion": 1,
"minorVersion": 0,
"patchVersion": 18,
"patchVersion": 19,
"runnable": 1,
"license": "MIT",
"author": "NDLA",
Expand All @@ -18,6 +18,16 @@
"machineName": "H5P.DragText",
"majorVersion": 1,
"minorVersion": 10
},
{
"machineName": "H5P.Question",
"majorVersion": 1,
"minorVersion": 5
},
{
"machineName": "H5P.JoubelUI",
"majorVersion": 1,
"minorVersion": 3
}
],
"editorDependencies": [
Expand Down
12 changes: 11 additions & 1 deletion library.json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare const json: {
"machineName": "H5P.VocabularyDrill",
"majorVersion": 1,
"minorVersion": 0,
"patchVersion": 18,
"patchVersion": 19,
"runnable": 1,
"license": "MIT",
"author": "NDLA",
Expand All @@ -18,6 +18,16 @@ declare const json: {
"machineName": "H5P.DragText",
"majorVersion": 1,
"minorVersion": 10
},
{
"machineName": "H5P.Question",
"majorVersion": 1,
"minorVersion": 5
},
{
"machineName": "H5P.JoubelUI",
"majorVersion": 1,
"minorVersion": 3
}
],
"editorDependencies": [
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"eslint": "^8.39.0",
"eslint-config-ndla-h5p": "github:ndlano/eslint-config-ndla-h5p",
"h5p-types": "^1.17.0",
"h5p-types-joubel-ui": "^1.0.4",
"jest": "^29.5.0",
"mini-css-extract-plugin": "^2.7.5",
"sass": "^1.62.1",
Expand Down
42 changes: 42 additions & 0 deletions semantics.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,48 @@
"default": "Swapped language from @sourceLanguage to @targetLanguage",
"type": "text"
},
{
"label": "Text for \"Next\" button",
"name": "next",
"default": "Next",
"type": "text"
},
{
"label": "Text for \"Finish\" button",
"name": "finish",
"default": "Finish",
"type": "text"
},
{
"label": "Text for \"Restart\" button",
"name": "restart",
"default": "Restart",
"type": "text"
},
{
"label": "Score label",
"name": "scoreLabel",
"default": "Score",
"type": "text"
},
{
"label": "Textual representation of the score bar for those using a readspeaker",
"name": "scoreBarLabel",
"default": "You got @score out of @maxScore points",
"type": "text"
},
{
"label": "Textual representation of the page numbers for those using a readspeaker",
"name": "pageNumberLabel",
"default": "Page @page of @totalPages",
"type": "text"
},
{
"label": "Feedback text",
"name": "feedbackText",
"default": "Your total score",
"type": "text"
},
{
"label": "English",
"name": "lang_en",
Expand Down
42 changes: 42 additions & 0 deletions semantics.json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,48 @@ declare const json: [
"default": "Swapped language from @sourceLanguage to @targetLanguage",
"type": "text"
},
{
"label": "Text for \"Next\" button",
"name": "next",
"default": "Next",
"type": "text"
},
{
"label": "Text for \"Finish\" button",
"name": "finish",
"default": "Finish",
"type": "text"
},
{
"label": "Text for \"Restart\" button",
"name": "restart",
"default": "Restart",
"type": "text"
},
{
"label": "Score label",
"name": "scoreLabel",
"default": "Score",
"type": "text"
},
{
"label": "Textual representation of the score bar for those using a readspeaker",
"name": "scoreBarLabel",
"default": "You got @score out of @maxScore points",
"type": "text"
},
{
"label": "Textual representation of the page numbers for those using a readspeaker",
"name": "pageNumberLabel",
"default": "Page @page of @totalPages",
"type": "text"
},
{
"label": "Feedback text",
"name": "feedbackText",
"default": "Your total score",
"type": "text"
},
{
"label": "English",
"name": "lang_en",
Expand Down
24 changes: 16 additions & 8 deletions src/components/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FC } from 'react';
import { H5P } from 'h5p-utils';
import React, { FC, useEffect, useRef } from 'react';

type ProgressBarProps = {
page: number;
Expand All @@ -8,13 +9,20 @@ type ProgressBarProps = {
export const ProgressBar: FC<ProgressBarProps> = ({
page, totalPages
}) => {
const progress = (page / Math.max(1, totalPages)) * 100;
const ref = useRef<HTMLDivElement>(null);

// Page progress is also available in StatusBar
const disableAria = true;
const progressBar = useRef(H5P.JoubelUI.createProgressbar(totalPages, { disableAria }));
progressBar.current.setProgress(page);

useEffect(() => {
if (ref.current && !ref.current.firstChild) {
progressBar.current.appendTo(ref.current);
}
}, [ref.current]);

return (
<div className="h5p-vocabulary-drill-progressbar">
<div
className="h5p-vocabulary-drill-progressbar-front"
style={{ width: `${progress}%` }}
/>
</div>
<div ref={ref} className="h5p-vocabulary-drill-progressbar" />
);
};
31 changes: 31 additions & 0 deletions src/components/ScoreBar/ScoreBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { H5P } from 'h5p-utils';
import React, { FC, useEffect, useRef } from 'react';
import { useTranslation } from '../../hooks/useTranslation/useTranslation';

type ScoreBarProps = {
maxScore: number,
score: number,
};

export const ScoreBar: FC<ScoreBarProps> = ({
maxScore,
score,
}) => {
const { t } = useTranslation();
const scoreBarLabel = t('scoreBarLabel').replaceAll('@score', score.toString()).replaceAll('@maxScore', maxScore.toString());

const ref = useRef<HTMLDivElement>(null);

const scoreBar = useRef(H5P.JoubelUI.createScoreBar(maxScore, scoreBarLabel));
scoreBar.current.setScore(score);

useEffect(() => {
if (ref.current && !ref.current.firstChild) {
scoreBar.current.appendTo(ref.current);
}
}, [ref.current]);

return (
<div ref={ref} />
);
};
Loading

0 comments on commit 129cfbf

Please sign in to comment.