import classNames from 'clsx'; import React, { useEffect, useRef, useState } from 'react'; import { Route, Switch } from 'react-router-dom'; import { Stack } from 'soapbox/components/ui'; import { useChatContext } from 'soapbox/contexts/chat-context'; import { useChat } from 'soapbox/queries/chats'; import ChatPageMain from './components/chat-page-main'; import ChatPageNew from './components/chat-page-new'; import ChatPageSidebar from './components/chat-page-sidebar'; import Welcome from './components/welcome'; interface IChatPage { chatId?: string, } const ChatPage: React.FC = ({ chatId }) => { const { chat, setChat } = useChatContext(); const { chat: chatQueryResult } = useChat(chatId); const containerRef = useRef(null); const [height, setHeight] = useState('100%'); const calculateHeight = () => { if (!containerRef.current) { return null; } const { top } = containerRef.current.getBoundingClientRect(); const fullHeight = document.body.offsetHeight; // On mobile, account for bottom navigation. const offset = document.body.clientWidth < 976 ? -61 : 0; setHeight(fullHeight - top + offset); }; useEffect(() => { const data = chatQueryResult?.data; if (data) { setChat(data); } }, [chatQueryResult?.isLoading]); useEffect(() => { calculateHeight(); }, [containerRef.current]); useEffect(() => { window.addEventListener('resize', calculateHeight); return () => { window.removeEventListener('resize', calculateHeight); }; }, []); return (
); }; export default ChatPage;