Commit 7bc423a8 authored by Adam Parák's avatar Adam Parák 💬
Browse files

Merge branch '687-fix' into 'main'

Resolve "Make the email channel highlighted as long as there are unread emails"

Closes #687

See merge request inject/frontend!582
parents bfd4131d 0014be20
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ import type { LinkType } from '@/components/LinkButton'
import LinkButton from '@/components/LinkButton'
import { canBeReviewed } from '@/instructor/InstructorQuestionnaire/utils'
import { type IconName } from '@blueprintjs/core'
import type { Channel, TeamQuestionnaireState } from '@inject/graphql'
import type { Channel, Email, TeamQuestionnaireState } from '@inject/graphql'
import {
  GetTeamChannelLogs,
  setIsUnreadChannel,
@@ -118,7 +118,7 @@ const ChannelButton: FC<ChannelButtonProps> = ({
      channelId: channel.id,
      teamId,
    },
    pause: channel.type !== 'FORM',
    pause: channel.type !== 'FORM' && channel.type !== 'EMAIL',
    context: useMemo(
      () => ({
        suspense: true,
@@ -133,14 +133,18 @@ const ChannelButton: FC<ChannelButtonProps> = ({
  })

  const isUnread = useMemo(() => {
    if (channel.type !== 'FORM') {
      const needle = channel.readReceipt.find(
        readReceipt => readReceipt.teamId === teamId
      )
      return needle?.isUnread
    } else {
    switch (channel.type) {
      case 'EMAIL': {
        const filteredLogs = data?.teamChannelLogs
          .filter(log => log.details.__typename === 'EmailType')
          .map(log => log.details as Email)
        return filteredLogs?.some(email => !email.readReceipt)
      }
      case 'FORM': {
        const filteredLogs = data?.teamChannelLogs
        .filter(log => log.details.__typename === 'TeamQuestionnaireStateType')
          .filter(
            log => log.details.__typename === 'TeamQuestionnaireStateType'
          )
          .map(log => log.details) as TeamQuestionnaireState[]
        if (linkTo === 'instructor') {
          return filteredLogs.some(
@@ -152,6 +156,13 @@ const ChannelButton: FC<ChannelButtonProps> = ({
          return filteredLogs.some(form => !form.timestampAnswered)
        }
      }
      default: {
        const needle = channel.readReceipt.find(
          readReceipt => readReceipt.teamId === teamId
        )
        return needle?.isUnread
      }
    }
  }, [channel.readReceipt, channel.type, data?.teamChannelLogs, linkTo, teamId])

  useEffect(() => {
+9 −15
Original line number Diff line number Diff line
@@ -125,21 +125,15 @@ const cache: Exchange = offlineExchange<GraphCacheConfig>({

          const teamId = args.teamId as string
          return emailThreads.filter(emailThread => {
            if (received) {
              return (
                !isEmailThreadArchived(cache, emailThread) &&
                isEmailThreadReceived(cache, emailThread)
              )
            }
            if (sent) {
            const archivedFlag = isEmailThreadArchived(cache, emailThread)
            const receivedFlag = isEmailThreadReceived(cache, emailThread)
            const sentFlag = isEmailThreadSent(cache, emailThread, teamId)

            return (
                !isEmailThreadArchived(cache, emailThread) &&
                isEmailThreadSent(cache, emailThread, teamId)
              (received && !archivedFlag && receivedFlag) ||
              (sent && !archivedFlag && sentFlag) ||
              (archived && archivedFlag)
            )
            }
            if (archived) {
              return isEmailThreadArchived(cache, emailThread)
            }
          })
        } else {
          console.error('Directive for unsupported query', info)