diff --git a/src/components/navigation/extension-item.tsx b/src/components/navigation/extension-item.tsx index 9c11487..20fc4ab 100644 --- a/src/components/navigation/extension-item.tsx +++ b/src/components/navigation/extension-item.tsx @@ -18,6 +18,51 @@ function truncate(str: string, n: number) { return str.length > n ? str.slice(0, n - 1) + "..." : str } +function ExtensionButton({ + extension, + disabled, + isCollapsed, + onClick, +}: { + extension: IExtension + disabled?: boolean + isCollapsed: boolean + onClick: (e: React.MouseEvent) => void +}) { + const truncatedName = truncate(extension.display_name, 25) + + return ( + + ) +} + export default function ExtensionItem({ extension, server_id, @@ -51,79 +96,43 @@ export default function ExtensionItem({ } }, [extension.id, router.asPath]) + const isCollapsed = + !router.asPath.includes(extension.id) || !router.asPath.includes(server_id) + + const onClick = (e: React.MouseEvent) => { + if (disabled) { + e.preventDefault() + } else { + setHash("") + } + } + return ( - {!router.asPath.includes(extension.id) || - !router.asPath.includes(server_id) ? ( + {isCollapsed ? ( 0 ? extension.menus[0].url : "" }`} - onClick={(e) => { - if (disabled) { - e.preventDefault() - } else { - setHash("") - } - }} + onClick={onClick} > - + isCollapsed={isCollapsed} + onClick={onClick} + /> ) : ( - - - + )} {router.asPath.includes(extension.id) && @@ -133,15 +142,7 @@ export default function ExtensionItem({ <> {extension.menus.map((menu: IMenu) => ( - - - + ))} @@ -149,3 +150,60 @@ export default function ExtensionItem({ ) } + +interface IMenuButtonProps { + menu: IMenu + hash: string +} + +const MenuButton: React.FC = ({ menu, hash }) => { + const [isCollapsed, setIsCollapsed] = useState(true) + + const toggleCollapsed = () => { + setIsCollapsed(!isCollapsed) + } + + useEffect(() => { + setIsCollapsed(!hash.includes(menu.url)) + }, [hash, menu.url]) + + return ( +
+ {!menu.children && ( + + + + )} + {menu.children && menu.children.length > 0 && ( + + + + + + {menu.children.map((childMenu: IMenu) => ( + + ))} + + + )} +
+ ) +} diff --git a/src/types/server.ts b/src/types/server.ts index 064ef7b..581c991 100644 --- a/src/types/server.ts +++ b/src/types/server.ts @@ -23,6 +23,7 @@ export interface IServer { export interface IMenu { name: string url: string + children?: IMenu[] } export interface IServerDetails {