@@ -2,6 +2,8 @@ import { SubscribeToMoreOptions } from '@apollo/client'
22import {
33 ElementBlock ,
44 LiveQuiz ,
5+ LiveQuizSettingsChangedDocument ,
6+ LiveQuizStudentSettings ,
57 RunningLiveQuizUpdatedDocument ,
68} from '@klicker-uzh/graphql/dist/ops'
79import { useEffect } from 'react'
@@ -14,11 +16,10 @@ function LiveQuizSubscriber({
1416 subscribeToMore : ( doc : SubscribeToMoreOptions ) => any
1517} ) {
1618 useEffect ( ( ) => {
17- subscribeToMore ( {
19+ // update the active block on the student view through a subscription on block start / end
20+ const activeBlockChanged = subscribeToMore ( {
1821 document : RunningLiveQuizUpdatedDocument ,
19- variables : {
20- quizId : id ,
21- } ,
22+ variables : { quizId : id } ,
2223 updateQuery : (
2324 prev : { studentLiveQuiz : LiveQuiz } ,
2425 {
@@ -36,6 +37,39 @@ function LiveQuizSubscriber({
3637 } )
3738 } ,
3839 } )
40+
41+ // live quiz student settings changed (Q&A channel or confusion feedback enabled / disabled)
42+ const liveQuizSettingsChanged = subscribeToMore ( {
43+ document : LiveQuizSettingsChangedDocument ,
44+ variables : { quizId : id } ,
45+ updateQuery : (
46+ prev : { studentLiveQuiz : LiveQuiz } ,
47+ {
48+ subscriptionData,
49+ } : {
50+ subscriptionData : {
51+ data : { liveQuizSettingsChanged : LiveQuizStudentSettings }
52+ }
53+ }
54+ ) => {
55+ if ( ! subscriptionData . data ) return prev
56+ return Object . assign ( { } , prev , {
57+ studentLiveQuiz : {
58+ ...prev . studentLiveQuiz ,
59+ isLiveQAEnabled :
60+ subscriptionData . data . liveQuizSettingsChanged . isLiveQAEnabled ,
61+ isConfusionFeedbackEnabled :
62+ subscriptionData . data . liveQuizSettingsChanged
63+ . isConfusionFeedbackEnabled ,
64+ } ,
65+ } )
66+ } ,
67+ } )
68+
69+ return ( ) => {
70+ activeBlockChanged && activeBlockChanged ( )
71+ liveQuizSettingsChanged && liveQuizSettingsChanged ( )
72+ }
3973 } , [ id , subscribeToMore ] )
4074
4175 return < div />
0 commit comments