import React from "react"; import { useQuery } from "@apollo/react-hooks"; import { gql } from "apollo-boost"; import { GQLMessage } from "./gql-types"; export default function Chatroom() { const { loading: localLoading, error: localError, data: localData } = useQuery(gql` { currentChat { workspace channel } } `); const variables = { workspace: localData.currentChat?.workspace || "", channel: localData.currentChat?.channel || "" }; const { loading: remoteLoading, error: remoteError, data: remoteData } = useQuery( gql` query Messages($workspace: String!, $channel: String!) { messages( workspace: $workspace order: DATE_ASC filter: { channel: $channel } ) { messages { content username userRealname time messageId } } } `, { variables } ); if (localLoading || remoteLoading) { return
Loading
; } if (localData.currentChat == null) { return
Select a channel from the left menu
; } if (localError) { return
{localError.message}
; } if (remoteError) { return
{remoteError.message}
; } return (
); }