Commit c2fa9cec authored by Marek Veselý's avatar Marek Veselý
Browse files

Merge branch '855-implement-noticeboard-subscription' into 'main'

implement noticeboard subscription

Closes #855

See merge request inject/frontend!786
parents 1c82a3ae 8ebeb3ea
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
import { Button, Section } from '@blueprintjs/core'
import { useState } from 'react'

import { NoticeboardMessagesQuery, useTypedQuery } from '@inject/graphql'
import { useNoticeboardSubscription } from '@inject/graphql'
import { NoticeboardCommentDialog } from './CommentDialog'
import { NoticeboardMessagesList } from './MessagesList'

export const Noticeboard = () => {
  const [addDialogOpened, setAddDialogOpened] = useState(false)

  const [{ fetching, data: noticebordMessagesQuery }] = useTypedQuery({
    query: NoticeboardMessagesQuery,
  })
  const [{ data, fetching }] = useNoticeboardSubscription()
  const messages = data?.noticeboardMessages ?? []

  return (
    <>
@@ -21,11 +20,7 @@ export const Noticeboard = () => {
      />

      <Section
        title={`Noticeboard${
          noticebordMessagesQuery?.noticeboardMessages
            ? ` (${noticebordMessagesQuery.noticeboardMessages.length})`
            : ''
        }`}
        title={`Noticeboard${messages.length ? ` (${messages.length})` : ''}`}
        rightElement={
          <Button
            onClick={e => {
@@ -39,10 +34,7 @@ export const Noticeboard = () => {
        }
        collapsible
      >
        <NoticeboardMessagesList
          loading={fetching}
          messages={noticebordMessagesQuery?.noticeboardMessages ?? []}
        />
        <NoticeboardMessagesList loading={fetching} messages={messages} />
      </Section>
    </>
  )
+2 −0

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -36,4 +36,5 @@ export { useChannelTypeEnabled } from './utils/useChannelTypeEnabled'
export { useLoopStatus } from './utils/useExerciseLoopStatusSubscription'
export { useExercisesSubscription } from './utils/useExercisesSubscription'
export { useGetEmailThreadUnreadCountSuspense } from './utils/useGetEmailThreadUnreadCountSuspense'
export { useNoticeboardSubscription } from './utils/useNoticeboardSubscription'
export { useUploadFiles } from './utils/useUploadFile'
+14 −0
Original line number Diff line number Diff line
@@ -79,3 +79,17 @@ export const InstructorCommentsSubscription = graphql(
  `,
  [Fragments.InstructorComment]
)

export const NoticeboardSubscription = graphql(
  `
    subscription NoticeboardSubscription {
      noticeboardSubscription {
        message {
          ...NoticeboardMessage
        }
        eventType
      }
    }
  `,
  [Fragments.NoticeboardMessage]
)
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ const constructRemoteSchema = (): SubschemaConfig => {
          ws.current.status === WebSocket.CLOSED ||
          ws.current.status === WebSocket.CLOSING
        ) {
          // TODO: fix "Websocket is closed before the connection is established"
          // ws.current.status === WebSocket.OPEN
          if (ws.current !== null) {
            ws.current.close(true, false)
            ws.current = null
Loading