import React, { FC, memo, useCallback, } from 'react'; import Link from 'next/link'; import { useUserUISettings } from '~/client/services/user-ui-settings'; import { SidebarContentsType } from '~/interfaces/ui'; import { useIsAdmin, useGrowiCloudUri } from '~/stores/context'; import { useCurrentSidebarContents } from '~/stores/ui'; import styles from './SidebarNav.module.scss'; type PrimaryItemProps = { contents: SidebarContentsType, label: string, iconName: string, onItemSelected: (contents: SidebarContentsType) => void, } const PrimaryItem: FC = (props: PrimaryItemProps) => { const { contents, label, iconName, onItemSelected, } = props; const { data: currentContents, mutate } = useCurrentSidebarContents(); const { scheduleToPut } = useUserUISettings(); const isSelected = contents === currentContents; const itemSelectedHandler = useCallback(() => { if (onItemSelected != null) { onItemSelected(contents); } mutate(contents, false); scheduleToPut({ currentSidebarContents: contents }); }, [contents, mutate, onItemSelected, scheduleToPut]); const labelForTestId = label.toLowerCase().replace(' ', '-'); return ( ); }; type SecondaryItemProps = { label: string, href: string, iconName: string, isBlank?: boolean, } const SecondaryItem: FC = memo((props: SecondaryItemProps) => { const { iconName, href, isBlank } = props; return ( {iconName} ); }); SecondaryItem.displayName = 'SecondaryItem'; type Props = { onItemSelected: (contents: SidebarContentsType) => void, } export const SidebarNav: FC = (props: Props) => { const { data: isAdmin } = useIsAdmin(); const { data: growiCloudUri } = useGrowiCloudUri(); const { onItemSelected } = props; return (
{/* eslint-disable max-len */} {/* */} {/* */} {/* */} {/* eslint-enable max-len */}
{isAdmin && } {/* */}
); };