From 6441242febac53cfad75dce5c3d3580a1f69fd7e Mon Sep 17 00:00:00 2001 From: Juan Carlos Farah Date: Wed, 13 Mar 2024 10:57:40 +0100 Subject: [PATCH] fix: fix issues present in short answer app (#23) close #22 --- package.json | 2 +- src/config/i18n.ts | 1 + src/langs/en.json | 3 +- src/modules/answers/AnswersView.tsx | 2 +- src/modules/main/PlayerView.tsx | 29 +++-- src/modules/settings/AnswersSettings.tsx | 1 + yarn.lock | 155 +++++++++++------------ 7 files changed, 97 insertions(+), 96 deletions(-) diff --git a/package.json b/package.json index a9e6d1d..ca89552 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dependencies": { "@emotion/react": "11.11.3", "@emotion/styled": "11.11.0", - "@graasp/apps-query-client": "3.2.1", + "@graasp/apps-query-client": "3.4.4", "@graasp/sdk": "3.3.0", "@graasp/ui": "4.1.1", "@mui/icons-material": "5.15.10", diff --git a/src/config/i18n.ts b/src/config/i18n.ts index 80b90dd..897d383 100644 --- a/src/config/i18n.ts +++ b/src/config/i18n.ts @@ -21,6 +21,7 @@ declare module 'react-i18next' { i18n.use(initReactI18next).init({ resources, lng: 'en', + fallbackLng: 'en', // debug only when not in production debug: import.meta.env.DEV, ns: [defaultNS], diff --git a/src/langs/en.json b/src/langs/en.json index 21430a4..cb713d2 100644 --- a/src/langs/en.json +++ b/src/langs/en.json @@ -27,7 +27,8 @@ "KEY_LABEL": "Key", "VALUE_LABEL": "Value", "ANSWER_LABEL": "Answer" - } + }, + "HELPER_TEXT": "[Optional] If there is one correct answer, then you can include it here and you can automatically see who submitted a correct answer." }, "GENERAL": { "TITLE": "General" diff --git a/src/modules/answers/AnswersView.tsx b/src/modules/answers/AnswersView.tsx index 9601d40..4f723c6 100644 --- a/src/modules/answers/AnswersView.tsx +++ b/src/modules/answers/AnswersView.tsx @@ -24,7 +24,7 @@ const AnswersView: FC = () => { return ( - {t('TITLE')} + {t('TITLE')} diff --git a/src/modules/main/PlayerView.tsx b/src/modules/main/PlayerView.tsx index d6e5af5..9e17fc3 100644 --- a/src/modules/main/PlayerView.tsx +++ b/src/modules/main/PlayerView.tsx @@ -1,4 +1,4 @@ -import { ChangeEvent, useMemo, useState } from 'react'; +import { ChangeEvent, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { @@ -39,20 +39,23 @@ const PlayerView = (): JSX.Element => { const { data: appData } = hooks.useAppData(); const { mutate: postAppData } = mutations.usePostAppData(); - // use effect to get required app data - let savedAnswer = ''; + const [answer, setAnswer] = useState(''); + const [savedAnswer, setSavedAnswer] = useState(''); - if (appData) { - // only show the last answer - const savedAnswerObject = sortBy(appData, ['createdAt']) - .reverse() - .find(isAnswer) as AppData; - if (savedAnswerObject) { - savedAnswer = savedAnswerObject.data.answer ?? ''; + // use effect to get required app data + useEffect(() => { + if (appData) { + // only show the last answer + const savedAnswerObject = sortBy(appData, ['createdAt']) + .reverse() + .find(isAnswer) as AppData; + if (savedAnswerObject) { + const savedAnswerText = savedAnswerObject.data.answer ?? ''; + setAnswer(savedAnswerText); + setSavedAnswer(savedAnswerText); + } } - } - - const [answer, setAnswer] = useState(savedAnswer); + }, [appData]); const disableSave = useMemo(() => { // disable if there is no user (logged out or anonymous) diff --git a/src/modules/settings/AnswersSettings.tsx b/src/modules/settings/AnswersSettings.tsx index e0ca566..ab98ffb 100644 --- a/src/modules/settings/AnswersSettings.tsx +++ b/src/modules/settings/AnswersSettings.tsx @@ -25,6 +25,7 @@ const AnswerSettings: FC = ({ answer, onChange }) => { }} value={answerContent} onChange={(e) => onChange({ content: e.target.value })} + helperText={t('SETTINGS.ANSWER.HELPER_TEXT')} /> ); diff --git a/yarn.lock b/yarn.lock index dc8bfab..5500f0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1578,7 +1578,7 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.22.5, @babel/runtime@npm:^7.23.2, @babel/runtime@npm:^7.23.9, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.8.7": +"@babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.22.5, @babel/runtime@npm:^7.23.2, @babel/runtime@npm:^7.23.8, @babel/runtime@npm:^7.23.9, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.8.7": version: 7.23.9 resolution: "@babel/runtime@npm:7.23.9" dependencies: @@ -1985,27 +1985,6 @@ __metadata: languageName: node linkType: hard -"@emotion/react@npm:11.11.1": - version: 11.11.1 - resolution: "@emotion/react@npm:11.11.1" - dependencies: - "@babel/runtime": "npm:^7.18.3" - "@emotion/babel-plugin": "npm:^11.11.0" - "@emotion/cache": "npm:^11.11.0" - "@emotion/serialize": "npm:^1.1.2" - "@emotion/use-insertion-effect-with-fallbacks": "npm:^1.0.1" - "@emotion/utils": "npm:^1.2.1" - "@emotion/weak-memoize": "npm:^0.3.1" - hoist-non-react-statics: "npm:^3.3.1" - peerDependencies: - react: ">=16.8.0" - peerDependenciesMeta: - "@types/react": - optional: true - checksum: dfc140718d0a8051a74e51c379226d9de6b19f6a5dd595fb282ef72f4413695a2d012ba919f1e9eeff761c6659e6f7398da8e0e36eb7997a4fdf54cef88644ae - languageName: node - linkType: hard - "@emotion/react@npm:11.11.3": version: 11.11.3 resolution: "@emotion/react@npm:11.11.3" @@ -2319,7 +2298,7 @@ __metadata: languageName: node linkType: hard -"@floating-ui/react-dom@npm:^2.0.4, @floating-ui/react-dom@npm:^2.0.8": +"@floating-ui/react-dom@npm:^2.0.5, @floating-ui/react-dom@npm:^2.0.8": version: 2.0.8 resolution: "@floating-ui/react-dom@npm:2.0.8" dependencies: @@ -2338,15 +2317,15 @@ __metadata: languageName: node linkType: hard -"@graasp/apps-query-client@npm:3.2.1": - version: 3.2.1 - resolution: "@graasp/apps-query-client@npm:3.2.1" +"@graasp/apps-query-client@npm:3.4.4": + version: 3.4.4 + resolution: "@graasp/apps-query-client@npm:3.4.4" dependencies: - "@emotion/react": "npm:11.11.1" + "@emotion/react": "npm:11.11.3" "@emotion/styled": "npm:11.11.0" - "@graasp/sdk": "npm:3.3.0" - "@mui/icons-material": "npm:5.14.18" - "@mui/material": "npm:5.14.18" + "@graasp/sdk": "npm:3.6.0" + "@mui/icons-material": "npm:5.15.5" + "@mui/material": "npm:5.15.5" axios: "npm:0.27.2" dexie: "npm:3.2.4" http-status-codes: "npm:2.3.0" @@ -2354,11 +2333,14 @@ __metadata: msw: "npm:1.3.2" uuid: "npm:9.0.1" peerDependencies: + "@mui/icons-material": ^5.15.5 + "@mui/material": ^5.15.5 "@tanstack/react-query": ^4.28.0 "@tanstack/react-query-devtools": ^4.28.0 + date-fns: ^3.3.0 react: ^18.0.0 react-dom: ^18.0.0 - checksum: fb618abed5f93507a7b235e52b792fb0673069f378099082d110454d135120a02f4bd5bd885d330c674cc4b02522f141bda19df53260c912584fe3b0c9ec5c77 + checksum: 5d32654427b80ed1c8e183a8ee564c1ca462f5c191b3ad568c1c8a3be903d372bbb22a761619f2c9df5b0c9c63b40f195af3ad6a327f53c7f60260a9e17448e0 languageName: node linkType: hard @@ -2388,6 +2370,19 @@ __metadata: languageName: node linkType: hard +"@graasp/sdk@npm:3.6.0": + version: 3.6.0 + resolution: "@graasp/sdk@npm:3.6.0" + dependencies: + js-cookie: "npm:3.0.5" + validator: "npm:13.11.0" + peerDependencies: + date-fns: ^3 + uuid: ^9 + checksum: df52e11764c727e17ce69d247805fd8a2d49ba291b84e00ca390f853f0b0eb7fc4a2153e7003044cb8f84edf9c2c9cae91b79a55d1e71e71c69317e40145ad12 + languageName: node + linkType: hard + "@graasp/ui@npm:4.1.1": version: 4.1.1 resolution: "@graasp/ui@npm:4.1.1" @@ -2563,16 +2558,16 @@ __metadata: languageName: node linkType: hard -"@mui/base@npm:5.0.0-beta.24": - version: 5.0.0-beta.24 - resolution: "@mui/base@npm:5.0.0-beta.24" +"@mui/base@npm:5.0.0-beta.32": + version: 5.0.0-beta.32 + resolution: "@mui/base@npm:5.0.0-beta.32" dependencies: - "@babel/runtime": "npm:^7.23.2" - "@floating-ui/react-dom": "npm:^2.0.4" - "@mui/types": "npm:^7.2.9" - "@mui/utils": "npm:^5.14.18" + "@babel/runtime": "npm:^7.23.8" + "@floating-ui/react-dom": "npm:^2.0.5" + "@mui/types": "npm:^7.2.13" + "@mui/utils": "npm:^5.15.5" "@popperjs/core": "npm:^2.11.8" - clsx: "npm:^2.0.0" + clsx: "npm:^2.1.0" prop-types: "npm:^15.8.1" peerDependencies: "@types/react": ^17.0.0 || ^18.0.0 @@ -2581,7 +2576,7 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 65d8a428d7e863885d5d5d6513ffa64982ebd7bd3a809b3024f669b907796c94a5d19ebac42ef383277acaccf30af3158c91f65c69fb0e7b2ddab925fc3293dd + checksum: c88cd8a412ecaeaf0040e20708b2a607b9594a4462449ad06b90e96465aad0dada23295f801ed72851025fd023ababc410b6a48fcb69d7cdef90b55e62aa9a11 languageName: node linkType: hard @@ -2607,18 +2602,18 @@ __metadata: languageName: node linkType: hard -"@mui/core-downloads-tracker@npm:^5.14.18, @mui/core-downloads-tracker@npm:^5.15.10": +"@mui/core-downloads-tracker@npm:^5.15.10, @mui/core-downloads-tracker@npm:^5.15.5": version: 5.15.10 resolution: "@mui/core-downloads-tracker@npm:5.15.10" checksum: aeb16b31f60c08cc03585fedadceadd54aa48dda394fb945ab885f884c1b1692efb72309465641b6ca2367bd53d5fdce15f189d4691f42b59206622ffb2d6f0f languageName: node linkType: hard -"@mui/icons-material@npm:5.14.18": - version: 5.14.18 - resolution: "@mui/icons-material@npm:5.14.18" +"@mui/icons-material@npm:5.15.10": + version: 5.15.10 + resolution: "@mui/icons-material@npm:5.15.10" dependencies: - "@babel/runtime": "npm:^7.23.2" + "@babel/runtime": "npm:^7.23.9" peerDependencies: "@mui/material": ^5.0.0 "@types/react": ^17.0.0 || ^18.0.0 @@ -2626,15 +2621,15 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 20da1445f033edf017d7d447c74fb27e90d4a9f3a631f617252a4806b69364792e01aa7010939c90e37d8ce7adf4218ec27066bd8ec0db40295f64365fd18a5e + checksum: ce22c02dc7ed960a21f8d5ea7c4d4fc03d9f71e8a26ced02f75da1ffd6c768e6fa0682a308a03be53bffc2325a5aaf68be69f9e192b0a57c6752f7548e5b9045 languageName: node linkType: hard -"@mui/icons-material@npm:5.15.10": - version: 5.15.10 - resolution: "@mui/icons-material@npm:5.15.10" +"@mui/icons-material@npm:5.15.5": + version: 5.15.5 + resolution: "@mui/icons-material@npm:5.15.5" dependencies: - "@babel/runtime": "npm:^7.23.9" + "@babel/runtime": "npm:^7.23.8" peerDependencies: "@mui/material": ^5.0.0 "@types/react": ^17.0.0 || ^18.0.0 @@ -2642,7 +2637,7 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: ce22c02dc7ed960a21f8d5ea7c4d4fc03d9f71e8a26ced02f75da1ffd6c768e6fa0682a308a03be53bffc2325a5aaf68be69f9e192b0a57c6752f7548e5b9045 + checksum: 25feb86a76ce83c81391c95d0c1c867e988cc7bc1b5a05c5698b71cb3cd1005fd148b07c2fa8908cda9fc4e44ea8b6e0fd2197bc0abafac0ee4880b477852eea languageName: node linkType: hard @@ -2675,19 +2670,19 @@ __metadata: languageName: node linkType: hard -"@mui/material@npm:5.14.18": - version: 5.14.18 - resolution: "@mui/material@npm:5.14.18" +"@mui/material@npm:5.15.10": + version: 5.15.10 + resolution: "@mui/material@npm:5.15.10" dependencies: - "@babel/runtime": "npm:^7.23.2" - "@mui/base": "npm:5.0.0-beta.24" - "@mui/core-downloads-tracker": "npm:^5.14.18" - "@mui/system": "npm:^5.14.18" - "@mui/types": "npm:^7.2.9" - "@mui/utils": "npm:^5.14.18" - "@types/react-transition-group": "npm:^4.4.8" - clsx: "npm:^2.0.0" - csstype: "npm:^3.1.2" + "@babel/runtime": "npm:^7.23.9" + "@mui/base": "npm:5.0.0-beta.36" + "@mui/core-downloads-tracker": "npm:^5.15.10" + "@mui/system": "npm:^5.15.9" + "@mui/types": "npm:^7.2.13" + "@mui/utils": "npm:^5.15.9" + "@types/react-transition-group": "npm:^4.4.10" + clsx: "npm:^2.1.0" + csstype: "npm:^3.1.3" prop-types: "npm:^15.8.1" react-is: "npm:^18.2.0" react-transition-group: "npm:^4.4.5" @@ -2704,23 +2699,23 @@ __metadata: optional: true "@types/react": optional: true - checksum: 50c5ddbd8e6e39aa4cf904ea7061a1c9d91d906baa7b7626f3db22338872972bac8d176002e613f79e9171969e898ca268c024a143bc120f05e750035b25a8cb + checksum: a88ad1287a905549ed516742544c8ba32f0cd7e1b184564efc8ceba5f43060d37b5cd113db605f1bb5be6c74cbdad7321d3fd7df410ba33d55548cf7c5bbf8d0 languageName: node linkType: hard -"@mui/material@npm:5.15.10": - version: 5.15.10 - resolution: "@mui/material@npm:5.15.10" +"@mui/material@npm:5.15.5": + version: 5.15.5 + resolution: "@mui/material@npm:5.15.5" dependencies: - "@babel/runtime": "npm:^7.23.9" - "@mui/base": "npm:5.0.0-beta.36" - "@mui/core-downloads-tracker": "npm:^5.15.10" - "@mui/system": "npm:^5.15.9" + "@babel/runtime": "npm:^7.23.8" + "@mui/base": "npm:5.0.0-beta.32" + "@mui/core-downloads-tracker": "npm:^5.15.5" + "@mui/system": "npm:^5.15.5" "@mui/types": "npm:^7.2.13" - "@mui/utils": "npm:^5.15.9" + "@mui/utils": "npm:^5.15.5" "@types/react-transition-group": "npm:^4.4.10" clsx: "npm:^2.1.0" - csstype: "npm:^3.1.3" + csstype: "npm:^3.1.2" prop-types: "npm:^15.8.1" react-is: "npm:^18.2.0" react-transition-group: "npm:^4.4.5" @@ -2737,7 +2732,7 @@ __metadata: optional: true "@types/react": optional: true - checksum: a88ad1287a905549ed516742544c8ba32f0cd7e1b184564efc8ceba5f43060d37b5cd113db605f1bb5be6c74cbdad7321d3fd7df410ba33d55548cf7c5bbf8d0 + checksum: 2a094d94acfc8f945b6cc73b295799f3174d7292707230e9b9486d810990561778f5f228f2fdc13a064ae234d528fb28c9b53f6c487ca43e65dc17460886165c languageName: node linkType: hard @@ -2779,7 +2774,7 @@ __metadata: languageName: node linkType: hard -"@mui/system@npm:^5.14.18, @mui/system@npm:^5.15.9": +"@mui/system@npm:^5.15.5, @mui/system@npm:^5.15.9": version: 5.15.9 resolution: "@mui/system@npm:5.15.9" dependencies: @@ -2807,7 +2802,7 @@ __metadata: languageName: node linkType: hard -"@mui/types@npm:^7.2.13, @mui/types@npm:^7.2.9": +"@mui/types@npm:^7.2.13": version: 7.2.13 resolution: "@mui/types@npm:7.2.13" peerDependencies: @@ -2819,7 +2814,7 @@ __metadata: languageName: node linkType: hard -"@mui/utils@npm:^5.14.18, @mui/utils@npm:^5.15.9": +"@mui/utils@npm:^5.15.5, @mui/utils@npm:^5.15.9": version: 5.15.9 resolution: "@mui/utils@npm:5.15.9" dependencies: @@ -3376,7 +3371,7 @@ __metadata: languageName: node linkType: hard -"@types/react-transition-group@npm:^4.4.10, @types/react-transition-group@npm:^4.4.8": +"@types/react-transition-group@npm:^4.4.10": version: 4.4.10 resolution: "@types/react-transition-group@npm:4.4.10" dependencies: @@ -4663,7 +4658,7 @@ __metadata: languageName: node linkType: hard -"clsx@npm:^2.0.0, clsx@npm:^2.1.0": +"clsx@npm:^2.1.0": version: 2.1.0 resolution: "clsx@npm:2.1.0" checksum: 2e0ce7c3b6803d74fc8147c408f88e79245583202ac14abd9691e2aebb9f312de44270b79154320d10bb7804a9197869635d1291741084826cff20820f31542b @@ -6738,7 +6733,7 @@ __metadata: "@cypress/code-coverage": "npm:3.12.22" "@emotion/react": "npm:11.11.3" "@emotion/styled": "npm:11.11.0" - "@graasp/apps-query-client": "npm:3.2.1" + "@graasp/apps-query-client": "npm:3.4.4" "@graasp/sdk": "npm:3.3.0" "@graasp/ui": "npm:4.1.1" "@mui/icons-material": "npm:5.15.10"