import { useEffect, useState } from 'react'; import { useHistory, useLocation } from 'react-router'; import { useReactiveVar } from '@apollo/client'; import { roleVar } from '../../graphql/state'; import { Box, Button, Text } from '..'; import { Wrapper } from './styles'; import { GetProjectThreadsQuery, GetProjectThreadsQueryVariables, ThreadObject, } from '../../graphql/types.support'; import { GET_PROJECT_THREADS } from '../../graphql/chat.api.support'; import { Add, Empty } from '../../assets'; import { clientSupport } from '../..'; type MessagingSidebarProps = { onClose: () => void; }; const MessagingSidebar = ({ onClose }: MessagingSidebarProps) => { const role = useReactiveVar(roleVar); const location = useLocation(); const history = useHistory(); const [projectThreads, setProjectThreads] = useState>(); useEffect(() => { (async () => { if (/\/project/i.test(location.pathname)) { const threads = await clientSupport.query< GetProjectThreadsQuery, GetProjectThreadsQueryVariables >({ query: GET_PROJECT_THREADS, variables: { projectId: location.pathname.split('/')[2]!, }, }); setProjectThreads(threads?.data?.getProjectThreads!); } })(); // eslint-disable-next-line }, [location.pathname]); return ( Messaging Support