28 lines
961 B
JavaScript
28 lines
961 B
JavaScript
import { useSubscription } from "@apollo/react-hooks";
|
|
import React from "react";
|
|
import { CONVERSATION_LIST_SUBSCRIPTION } from "../../graphql/conversations.queries";
|
|
import AlertComponent from "../alert/alert.component";
|
|
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
|
import ChatMessagesButtonComponent from "./chat-messages-button.component";
|
|
|
|
export default function ChatMessagesButtonContainer() {
|
|
const { loading, error, data } = useSubscription(
|
|
CONVERSATION_LIST_SUBSCRIPTION
|
|
);
|
|
if (loading) return <LoadingSpinner />;
|
|
if (error) return <AlertComponent message={error.message} type='error' />;
|
|
|
|
return (
|
|
<ChatMessagesButtonComponent
|
|
conversationList={(data && data.conversations) || []}
|
|
unreadCount={
|
|
(data &&
|
|
data.conversations.reduce((acc, val) => {
|
|
return (acc = acc + val.messages_aggregate.aggregate.count);
|
|
}, 0)) ||
|
|
0
|
|
}
|
|
/>
|
|
);
|
|
}
|