import React, { FC, memo, useCallback } from 'react'; import { scheduleToPutUserUISettings } from '~/client/services/user-ui-settings'; import { SidebarContentsType } from '~/interfaces/ui'; import { useCurrentUser, useIsSharedUser } from '~/stores/context'; import { useCurrentSidebarContents } from '~/stores/ui'; type PrimaryItemProps = { contents: SidebarContentsType, label: string, iconName: string, onItemSelected: (contents: SidebarContentsType) => void, } const PrimaryItem: FC = (props: PrimaryItemProps) => { const { contents, iconName, onItemSelected, } = props; const { data: currentContents, mutate } = useCurrentSidebarContents(); const isSelected = contents === currentContents; const itemSelectedHandler = useCallback(() => { if (onItemSelected != null) { onItemSelected(contents); } mutate(contents, false); scheduleToPutUserUISettings({ currentSidebarContents: contents }); }, [contents, mutate, onItemSelected]); return ( ); }; type SecondaryItemProps = { label: string, href: string, iconName: string, isBlank?: boolean, } const SecondaryItem: FC = memo((props: SecondaryItemProps) => { const { iconName, href, isBlank } = props; return ( {iconName} ); }); type Props = { onItemSelected: (contents: SidebarContentsType) => void, } const SidebarNav: FC = (props: Props) => { const { data: isSharedUser } = useIsSharedUser(); const { data: currentUser } = useCurrentUser(); const isAdmin = currentUser?.admin; const isLoggedIn = currentUser != null; const { onItemSelected } = props; return (
{!isSharedUser && } {!isSharedUser && } {!isSharedUser && } {/* */}
{isAdmin && } {isLoggedIn && }
); }; export default SidebarNav;