Skip to content
Snippets Groups Projects
Commit 37008f69 authored by Björn Modée's avatar Björn Modée
Browse files

Add max value for score value

parent baa9a15a
Branches
No related tags found
1 merge request!140Resolve "timer-score-max"
Pipeline #45024 passed with warnings
...@@ -17610,7 +17610,8 @@ ...@@ -17610,7 +17610,8 @@
}, },
"ssri": { "ssri": {
"version": "6.0.1", "version": "6.0.1",
"resolved": "", "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
"integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==",
"requires": { "requires": {
"figgy-pudding": "^3.5.1" "figgy-pudding": "^3.5.1"
} }
......
...@@ -13,6 +13,7 @@ type QuestionSettingsProps = { ...@@ -13,6 +13,7 @@ type QuestionSettingsProps = {
const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps) => { const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps) => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const maxScore = 1000
const updateQuestion = async ( const updateQuestion = async (
updateTitle: boolean, updateTitle: boolean,
...@@ -29,15 +30,34 @@ const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps) ...@@ -29,15 +30,34 @@ const QuestionSettings = ({ activeSlide, competitionId }: QuestionSettingsProps)
}) })
.catch(console.log) .catch(console.log)
} else { } else {
setScore(+event.target.value) if (+event.target.value > maxScore) {
await axios setScore(maxScore)
.put(`/api/competitions/${competitionId}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`, { await axios
total_score: event.target.value, .put(
}) `/api/competitions/${competitionId}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`,
.then(() => { {
dispatch(getEditorCompetition(competitionId)) total_score: maxScore,
}) }
.catch(console.log) )
.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) ...@@ -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." helperText="Välj hur många poäng frågan ska ge för rätt svar."
label="Poäng" label="Poäng"
type="number" type="number"
InputProps={{ inputProps: { min: 0 } }} InputProps={{ inputProps: { min: 0, max: maxScore } }}
value={score || 0} value={score || 0}
onChange={(event) => updateQuestion(false, event)} onChange={(event) => updateQuestion(false, event)}
/> />
......
...@@ -12,9 +12,21 @@ type TimerProps = { ...@@ -12,9 +12,21 @@ type TimerProps = {
} }
const Timer = ({ activeSlide, competitionId }: TimerProps) => { const Timer = ({ activeSlide, competitionId }: TimerProps) => {
const maxTime = 1000
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const updateTimer = async (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => { 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) { if (activeSlide) {
await axios await axios
.put(`/api/competitions/${competitionId}/slides/${activeSlide.id}`, { timer: event.target.value || null }) .put(`/api/competitions/${competitionId}/slides/${activeSlide.id}`, { timer: event.target.value || null })
...@@ -24,6 +36,7 @@ const Timer = ({ activeSlide, competitionId }: TimerProps) => { ...@@ -24,6 +36,7 @@ const Timer = ({ activeSlide, competitionId }: TimerProps) => {
.catch(console.log) .catch(console.log)
} }
} }
const [timer, setTimer] = useState<number | undefined>(activeSlide?.timer) const [timer, setTimer] = useState<number | undefined>(activeSlide?.timer)
useEffect(() => { useEffect(() => {
setTimer(activeSlide?.timer) setTimer(activeSlide?.timer)
...@@ -40,6 +53,7 @@ const Timer = ({ activeSlide, competitionId }: TimerProps) => { ...@@ -40,6 +53,7 @@ const Timer = ({ activeSlide, competitionId }: TimerProps) => {
label="Timer" label="Timer"
type="number" type="number"
onChange={updateTimer} onChange={updateTimer}
inputProps={{ max: maxTime }}
value={timer || ''} value={timer || ''}
/> />
</Center> </Center>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment