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

enhance: add direct forwarding for live quiz evaluation embedding #4359

Merged
merged 2 commits into from
Nov 6, 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
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
Loading