import styled from '@emotion/styled'; import { ActionIcon, Avatar, Burger, Button, Menu } from '@mantine/core'; import { useElementSize } from '@mantine/hooks'; import { useCallback, useMemo } from 'react'; import { useIntl } from 'react-intl'; import { backend } from '../../backend'; import { useAppContext } from '../../context'; import { useAppDispatch, useAppSelector } from '../../store'; import { setTab } from '../../store/settings-ui'; import { selectSidebarOpen, toggleSidebar } from '../../store/sidebar'; import RecentChats from './recent-chats'; const Container = styled.div` display: flex; flex-direction: column; height: 100%; overflow: hidden; position: relative; font-family: "Work Sans", sans-serif; box-shadow: 0px 0px 1rem 0.2rem rgb(0 0 0 / 5%); .sidebar-header { padding: 0.5rem 1rem 0.5rem 1.618rem; min-height: 2.618rem; display: flex; align-items: center; justify-content: space-between; h2 { font-size: 1rem; font-weight: bold; } } .sidebar-content { flex-grow: 1; overflow-y: scroll; /* hide scrollbars */ &::-webkit-scrollbar { display: none; } -ms-overflow-style: none; /* IE and Edge */ scrollbar-width: none; /* Firefox */ min-width: 20vw; padding-bottom: 2rem; } .sidebar-footer { border-top: thin solid rgba(255, 255, 255, 0.1); padding: 0.5rem 1.118rem; padding-left: 0.5rem; flex-shrink: 0; display: flex; align-items: center; font-size: 1rem; cursor: pointer; .user-info { max-width: calc(100% - 1.618rem * 2 - 2.5rem); margin-right: 0.5rem; } strong, span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } strong { font-weight: bold; margin-bottom: 0.2rem; } span { font-size: 0.8rem; font-weight: 100; } .mantine-Avatar-root { background: rgba(255, 255, 255, 0.2); border-radius: 50%; overflow: hidden; width: 2.5rem; height: 2.5rem; min-width: 0; flex-grow: 0; flex-shrink: 0; margin: 0.5rem; } } .spacer { flex-grow: 1; } `; export default function Sidebar(props: { className?: string; }) { const intl = useIntl(); const dispatch = useAppDispatch(); const sidebarOpen = useAppSelector(selectSidebarOpen); const onBurgerClick = useCallback(() => dispatch(toggleSidebar()), [dispatch]); const { ref, width } = useElementSize(); const burgerLabel = sidebarOpen ? intl.formatMessage({ defaultMessage: "Close sidebar" }) : intl.formatMessage({ defaultMessage: "Open sidebar" }); const elem = useMemo(() => (

Chat History

{backend.current && backend.current.isAuthenticated && (
{backend.current!.user!.name || backend.current!.user!.email} {!!backend.current!.user!.name && {backend.current.user!.email}}
{ dispatch(setTab('user')); }} icon={}> User settings {/* backend.current?.logout()} icon={}> Sign out */}
)}
), [sidebarOpen, width, ref, burgerLabel, onBurgerClick, dispatch]); return elem; }