Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix settings title, helper text, and saved data #75

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading