import classNames from 'clsx'; import React, { useEffect, useRef, useState } from 'react'; import { matchPath, Route, Switch, useHistory } from 'react-router-dom'; import { Stack } from 'soapbox/components/ui'; import { useOwnAccount } from 'soapbox/hooks'; import ChatPageMain from './components/chat-page-main'; import ChatPageNew from './components/chat-page-new'; import ChatPageSettings from './components/chat-page-settings'; import ChatPageSidebar from './components/chat-page-sidebar'; import Welcome from './components/welcome'; interface IChatPage { chatId?: string, } const ChatPage: React.FC = ({ chatId }) => { const account = useOwnAccount(); const history = useHistory(); const isOnboarded = account?.chats_onboarded; const path = history.location.pathname; const isSidebarHidden = matchPath(path, { path: ['/chats/settings', '/chats/new', '/chats/:chatId'], exact: true, }); 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(() => { calculateHeight(); }, [containerRef.current]); useEffect(() => { window.addEventListener('resize', calculateHeight); return () => { window.removeEventListener('resize', calculateHeight); }; }, []); return (
{isOnboarded ? (
) : ( )}
); }; export default ChatPage;