diff --git a/client/package-lock.json b/client/package-lock.json index ef036354b4d491cbe3fcc19a13e6d2139759502a..d9504ac90fc03eb98692588cc0b73702abc2a5b1 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -17610,7 +17610,8 @@ }, "ssri": { "version": "6.0.1", - "resolved": "", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", + "integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", "requires": { "figgy-pudding": "^3.5.1" } diff --git a/client/src/pages/presentationEditor/components/slideSettingsComponents/QuestionSettings.tsx b/client/src/pages/presentationEditor/components/slideSettingsComponents/QuestionSettings.tsx index f714fe2343e427a281d4e08aac50b895257d6424..526a1d0f5bffcb76c8309cf423ab6be0f590fb08 100644 --- a/client/src/pages/presentationEditor/components/slideSettingsComponents/QuestionSettings.tsx +++ b/client/src/pages/presentationEditor/components/slideSettingsComponents/QuestionSettings.tsx @@ -13,6 +13,7 @@ type QuestionSettingsProps = { const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps) => { const dispatch = useAppDispatch() + const maxScore = 1000 const updateQuestion = async ( updateTitle: boolean, @@ -29,15 +30,34 @@ const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps) }) .catch(console.log) } else { - setScore(+event.target.value) - await axios - .put(`/api/competitions/${competitionId}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`, { - total_score: event.target.value, - }) - .then(() => { - dispatch(getEditorCompetition(competitionId)) - }) - .catch(console.log) + if (+event.target.value > maxScore) { + setScore(maxScore) + await axios + .put( + `/api/competitions/${competitionId}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`, + { + total_score: maxScore, + } + ) + .then(() => { + dispatch(getEditorCompetition(competitionId)) + }) + .catch(console.log) + return maxScore + } else { + setScore(+event.target.value) + await axios + .put( + `/api/competitions/${competitionId}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`, + { + total_score: event.target.value, + } + ) + .then(() => { + dispatch(getEditorCompetition(competitionId)) + }) + .catch(console.log) + } } } } @@ -73,7 +93,7 @@ const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps) helperText="Välj hur många poäng frågan ska ge för rätt svar." label="Poäng" type="number" - InputProps={{ inputProps: { min: 0 } }} + InputProps={{ inputProps: { min: 0, max: maxScore } }} value={score || 0} onChange={(event) => updateQuestion(false, event)} /> diff --git a/client/src/pages/presentationEditor/components/slideSettingsComponents/Timer.tsx b/client/src/pages/presentationEditor/components/slideSettingsComponents/Timer.tsx index a633efec7e99d9390e5104284f2735d569f1b69e..7a8208d4ecdcfccd98168a218835acf9d153697e 100644 --- a/client/src/pages/presentationEditor/components/slideSettingsComponents/Timer.tsx +++ b/client/src/pages/presentationEditor/components/slideSettingsComponents/Timer.tsx @@ -12,9 +12,21 @@ type TimerProps = { } const Timer = ({ activeSlide, competitionId }: TimerProps) => { + const maxTime = 1000 const dispatch = useAppDispatch() const updateTimer = async (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => { - setTimer(+event.target.value) + if (+event.target.value > maxTime) { + setTimer(maxTime) + await axios + .put(`/api/competitions/${competitionId}/slides/${activeSlide.id}`, { timer: maxTime || null }) + .then(() => { + dispatch(getEditorCompetition(competitionId)) + }) + .catch(console.log) + return maxTime + } else { + setTimer(+event.target.value) + } if (activeSlide) { await axios .put(`/api/competitions/${competitionId}/slides/${activeSlide.id}`, { timer: event.target.value || null }) @@ -24,6 +36,7 @@ const Timer = ({ activeSlide, competitionId }: TimerProps) => { .catch(console.log) } } + const [timer, setTimer] = useState<number | undefined>(activeSlide?.timer) useEffect(() => { setTimer(activeSlide?.timer) @@ -40,6 +53,7 @@ const Timer = ({ activeSlide, competitionId }: TimerProps) => { label="Timer" type="number" onChange={updateTimer} + inputProps={{ max: maxTime }} value={timer || ''} /> </Center>