Commit 487612b4 authored by Marek Veselý's avatar Marek Veselý
Browse files

fix: only show overlay on create events

parent 0fe5dadb
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -30,16 +30,20 @@ const Layout = () => {
    [showPopup]
  )
  useEventListener('actionLogEvent', e => {
    const newActionLog = e.detail.actionLog
    const { actionLog, eventType } = e.detail

    switch (newActionLog.details.__typename) {
    if (eventType !== 'CREATE') {
      return
    }

    switch (actionLog.details.__typename) {
      case 'InjectDetailsType':
      case 'CustomInjectDetailsType':
      case 'EmailType':
        handleOverlay(newActionLog, newActionLog.details.overlay)
        handleOverlay(actionLog, actionLog.details.overlay)
        break
      case 'TeamQuestionnaireStateType':
        handleOverlay(newActionLog, newActionLog.details.questionnaire.overlay)
        handleOverlay(actionLog, actionLog.details.questionnaire.overlay)
        break
      default:
        break
+2 −3
Original line number Diff line number Diff line
import { FragmentOf } from 'gql.tada'
import { ActionLog } from '../fragments'
import { EventType } from './cache-typing'

declare global {
  interface WindowEventMap {
@@ -9,11 +10,9 @@ declare global {
  }
}

// Note: payload behaves differently depending on subscription/trainee.ts and subscription/instructor.ts
// instructor currently receives the payload whenever any change occurs
// trainee receives the payload only when a new actionlog comes in
export type ActionLogPayload = {
  actionLog: FragmentOf<typeof ActionLog>
  eventType: EventType
}

export {} //keep that for TS compiler.
+2 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ const useActionLogSubscriptionInstructor = ({
    }

    const { unsubscribe: unsubLog } = client
      .subscription(exerciseActionLogs, {
      .subscription<ResultOf<typeof exerciseActionLogs>>(exerciseActionLogs, {
        exerciseId,
      })
      .subscribe(({ data }) => {
@@ -76,6 +76,7 @@ const useActionLogSubscriptionInstructor = ({
            new CustomEvent<ActionLogPayload>('actionLogEvent', {
              detail: {
                actionLog: data.analyticsActionLogsSubscription.actionLog,
                eventType: data.analyticsActionLogsSubscription.eventType,
              },
            })
          )
+1 −3
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ import { teamAction } from '../../subscriptions'
import { useClient } from '../../urql/client'
import type { ActionLogPayload } from '../../urql/events'
import useExerciseLoopStatusSubscription from '../useExerciseLoopStatusSubscription'
import { useGenericActionLogEvent } from './utils'

const useActionLogSubscriptionTrainee = ({
  teamId,
@@ -49,6 +48,7 @@ const useActionLogSubscriptionTrainee = ({
            new CustomEvent<ActionLogPayload>('actionLogEvent', {
              detail: {
                actionLog: data.actionLogs.actionLog,
                eventType: data.actionLogs.eventType,
              },
            })
          )
@@ -59,8 +59,6 @@ const useActionLogSubscriptionTrainee = ({
      unsubLog()
    }
  }, [client, exerciseId, teamId])

  useGenericActionLogEvent()
}

export default useActionLogSubscriptionTrainee