bigbuffet-rw/app/soapbox/features/chats/components/chat-page/chat-page.tsx

69 lines
2 KiB
TypeScript
Raw Normal View History

import classNames from 'clsx';
import React, { useEffect, useRef, useState } from 'react';
2022-09-13 08:18:46 -07:00
import { Stack } from 'soapbox/components/ui';
import { useChatContext } from 'soapbox/contexts/chat-context';
2022-09-13 08:18:46 -07:00
import ChatPageMain from './components/chat-page-main';
import ChatPageSidebar from './components/chat-page-sidebar';
2022-09-13 08:18:46 -07:00
const ChatPage = () => {
const { chat } = useChatContext();
const containerRef = useRef<HTMLDivElement>(null);
const [height, setHeight] = useState<string | number>('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);
};
}, []);
2022-09-13 08:18:46 -07:00
return (
<div
ref={containerRef}
style={{ height }}
className='h-screen bg-white dark:bg-primary-900 text-gray-900 dark:text-gray-100 shadow-lg dark:shadow-none overflow-hidden sm:rounded-t-xl'
>
2022-09-13 08:18:46 -07:00
<div className='grid grid-cols-9 overflow-hidden h-full dark:divide-x-2 dark:divide-solid dark:divide-gray-800'>
2022-09-16 11:33:31 -07:00
<Stack
className={classNames('col-span-9 sm:col-span-3 bg-gradient-to-r from-white to-gray-100 dark:bg-gray-900 dark:bg-none overflow-hidden dark:inset', {
'hidden sm:block': chat,
})}
2022-09-16 11:33:31 -07:00
>
<ChatPageSidebar />
</Stack>
<Stack className={classNames('col-span-9 sm:col-span-6 h-full overflow-hidden', {
'hidden sm:block': !chat,
})}
>
2022-09-16 11:33:31 -07:00
<ChatPageMain />
</Stack>
2022-09-13 08:18:46 -07:00
</div>
</div>
2022-09-13 08:18:46 -07:00
);
};
2022-09-13 11:11:22 -07:00
export default ChatPage;