Skip to content

Commit

Permalink
fix: settings title, helper text, and saved data (#75)
Browse files Browse the repository at this point in the history
* fix(style): fix big header

close #72

* fix: add hint for answer setting

close #74

* fix: show previous data to user

close #73

* fix: add initial answer state
  • Loading branch information
juancarlosfarah authored Mar 13, 2024
1 parent 85e9085 commit 48a70ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/answers/AnswersView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const AnswersView: FC = () => {

return (
<Stack spacing={2}>
<Typography variant="h1">{t('TITLE')}</Typography>
<Typography variant="h3">{t('TITLE')}</Typography>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="answers table">
<TableHead>
Expand Down
29 changes: 16 additions & 13 deletions src/modules/main/PlayerView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useMemo, useState } from 'react';
import { ChangeEvent, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { Box, Grid, TextField, Typography } from '@mui/material';
Expand Down Expand Up @@ -30,20 +30,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<string>('');
const [savedAnswer, setSavedAnswer] = useState<string>('');

if (appData) {
// only show the last answer
const savedAnswerObject = sortBy(appData, ['createdAt'])
.reverse()
.find(isAnswer) as AppData<UserAnswer>;
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<UserAnswer>;
if (savedAnswerObject) {
const savedAnswerText = savedAnswerObject.data.answer ?? '';
setAnswer(savedAnswerText);
setSavedAnswer(savedAnswerText);
}
}
}

const [answer, setAnswer] = useState<string>(savedAnswer);
}, [appData]);

const disableSave = useMemo(() => {
// disable if there is no user (logged out or anonymous)
Expand Down
1 change: 1 addition & 0 deletions src/modules/settings/AnswersSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const AnswerSettings: FC<PropTypes> = ({ answer, onChange }) => {
}}
value={answerContent}
onChange={(e) => onChange({ content: e.target.value })}
helperText={t('SETTINGS.ANSWER.HELPER_TEXT')}
/>
</Stack>
);
Expand Down

0 comments on commit 48a70ad

Please sign in to comment.