2022-04-28 19:54:33 +03:00
|
|
|
import Sider from 'antd/lib/layout/Sider';
|
|
|
|
import { useRecoilValue } from 'recoil';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FC } from 'react';
|
2022-10-28 09:47:15 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
2023-03-14 01:23:14 +03:00
|
|
|
import { Spin } from 'antd';
|
2022-04-29 00:36:05 +03:00
|
|
|
import { ChatMessage } from '../../../interfaces/chat-message.model';
|
2022-09-07 10:00:28 +03:00
|
|
|
import styles from './Sidebar.module.scss';
|
2022-05-26 06:38:40 +03:00
|
|
|
|
2023-03-02 03:19:02 +03:00
|
|
|
import {
|
|
|
|
currentUserAtom,
|
|
|
|
visibleChatMessagesSelector,
|
|
|
|
isChatAvailableSelector,
|
|
|
|
} from '../../stores/ClientConfigStore';
|
2022-04-28 19:54:33 +03:00
|
|
|
|
2022-10-28 09:47:15 +03:00
|
|
|
// Lazy loaded components
|
2023-01-11 03:39:12 +03:00
|
|
|
const ChatContainer = dynamic(
|
|
|
|
() => import('../../chat/ChatContainer/ChatContainer').then(mod => mod.ChatContainer),
|
|
|
|
{
|
|
|
|
ssr: false,
|
|
|
|
},
|
2022-10-28 09:47:15 +03:00
|
|
|
);
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const Sidebar: FC = () => {
|
2022-10-11 02:26:09 +03:00
|
|
|
const currentUser = useRecoilValue(currentUserAtom);
|
2022-09-05 03:58:06 +03:00
|
|
|
const messages = useRecoilValue<ChatMessage[]>(visibleChatMessagesSelector);
|
2023-03-02 03:19:02 +03:00
|
|
|
const isChatAvailable = useRecoilValue(isChatAvailableSelector);
|
|
|
|
|
2022-10-11 04:33:15 +03:00
|
|
|
if (!currentUser) {
|
2023-03-14 01:23:14 +03:00
|
|
|
return (
|
|
|
|
<Sider className={styles.root} collapsedWidth={0} width={320}>
|
|
|
|
<Spin spinning size="large" />
|
|
|
|
</Sider>
|
|
|
|
);
|
2022-10-11 04:33:15 +03:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:26:09 +03:00
|
|
|
const { id, isModerator, displayName } = currentUser;
|
2022-04-28 19:54:33 +03:00
|
|
|
return (
|
2022-09-07 10:00:28 +03:00
|
|
|
<Sider className={styles.root} collapsedWidth={0} width={320}>
|
2022-06-25 07:30:54 +03:00
|
|
|
<ChatContainer
|
|
|
|
messages={messages}
|
2022-10-11 02:26:09 +03:00
|
|
|
usernameToHighlight={displayName}
|
|
|
|
chatUserId={id}
|
|
|
|
isModerator={isModerator}
|
2023-03-02 03:19:02 +03:00
|
|
|
chatAvailable={isChatAvailable}
|
2023-03-14 01:23:14 +03:00
|
|
|
showInput={!!currentUser}
|
2022-06-25 07:30:54 +03:00
|
|
|
/>
|
2022-04-29 00:36:05 +03:00
|
|
|
</Sider>
|
2022-04-28 19:54:33 +03:00
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|