Skip to content

Commit

Permalink
Merge 9d84be9 into 761360a
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach authored Nov 6, 2024
2 parents 761360a + 9d84be9 commit 41d6140
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChartType } from '@klicker-uzh/shared-components/src/constants'
import Leaderboard, {
LeaderboardCombinedEntry,
} from '@klicker-uzh/shared-components/src/Leaderboard'
import useEvaluationInitialization from '@lib/hooks/useEvaluationInitialization'
import { UserNotification } from '@uzh-bf/design-system'
import { useTranslations } from 'next-intl'
import Head from 'next/head'
Expand Down Expand Up @@ -53,10 +54,19 @@ function ActivityEvaluation({
const [chartType, setChartType] = useState<ChartType>(ChartType.UNSET)
const [textSize, setTextSize] = useReducer(sizeReducer, TextSizes['md'])

// TODO: add use Effect hook logic that directly jumps to a certain instance / leaderboard / ... for PPT integration

const instanceResults = stacks.flatMap((stack) => stack.instances)

// automatically switch to correct instance and use correct settings depending on URL params
useEvaluationInitialization({
setActiveInstance,
setActiveStack,
setShowSolution,
questionIx: router.query.questionIx as string | null,
showLeaderboard: router.query.leaderboard === 'true',
showSolution: router.query.showSolution === 'true',
type,
})

// compute a map between stack and instance indices {stackIx: [instanceIx1, instanceIx2], ...}
const stackInstanceMap = useStackInstanceMap({ stacks })

Expand Down
39 changes: 39 additions & 0 deletions apps/frontend-manage/src/lib/hooks/useEvaluationInitialization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Dispatch, SetStateAction, useEffect } from 'react'
import { ActivityEvaluationType } from '../../components/evaluation/ActivityEvaluation'

function useEvaluationInitialization({
setActiveInstance,
setActiveStack,
setShowSolution,
questionIx,
showLeaderboard,
showSolution,
type,
}: {
setActiveInstance: Dispatch<SetStateAction<number>>
setActiveStack: Dispatch<
SetStateAction<number | 'feedbacks' | 'confusion' | 'leaderboard'>
>
setShowSolution: Dispatch<SetStateAction<boolean>>
questionIx?: string | null
showLeaderboard?: boolean
showSolution?: boolean
type: ActivityEvaluationType
}) {
useEffect(() => {
if (type === 'LiveQuiz') {
if (typeof questionIx === 'string' && questionIx !== null) {
setActiveInstance(parseInt(questionIx))
} else if (showLeaderboard) {
setActiveStack('leaderboard')
}
if (showSolution) {
setShowSolution(true)
}
}
}, [type, questionIx, showLeaderboard, showSolution])

return null
}

export default useEvaluationInitialization
7 changes: 4 additions & 3 deletions packages/util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ export function getInitialElementResults(
total: 0,
}
} else if (
element.type === PrismaElementType.SC ||
element.type === PrismaElementType.MC ||
element.type === PrismaElementType.KPRIM
(element.type === PrismaElementType.SC ||
element.type === PrismaElementType.MC ||
element.type === PrismaElementType.KPRIM) &&
'choices' in element.options
) {
const choices = element.options.choices.reduce(
(acc: Record<string, number>, choice: Choice) => ({
Expand Down

0 comments on commit 41d6140

Please sign in to comment.