diff --git a/apps/web/src/components/CollapsibleBoardList .tsx b/apps/web/src/components/CollapsibleBoardList .tsx new file mode 100644 index 000000000..dc5067131 --- /dev/null +++ b/apps/web/src/components/CollapsibleBoardList .tsx @@ -0,0 +1,157 @@ +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { + Disclosure, + DisclosureButton, + DisclosurePanel, +} from "@headlessui/react"; +import React, { useState } from "react"; +import { twMerge } from "tailwind-merge"; + +import LottieIcon from "~/components/LottieIcon"; +import { useIsMobile } from "~/hooks/useMediaQuery"; +import { + KeyboardShortcut, + useKeyboardShortcut, +} from "~/providers/keyboard-shortcuts"; +import { useWorkspace } from "~/providers/workspace"; +import { api } from "~/utils/api"; +import LoadingSpinner from "./LoadingSpinner"; + +interface CollapsibleBoardListProps { + href: string; + current: boolean; + name: string; + json: object; + isCollapsed?: boolean; + onCloseSideNav?: () => void; + keyboardShortcut: KeyboardShortcut; +} + +const CollapsibleBoardList: React.FC = ({ + href, + current, + name, + json, + isCollapsed = false, + keyboardShortcut, + onCloseSideNav, +}) => { + const { workspace } = useWorkspace(); + const [isHovered, setIsHovered] = useState(false); + const [index, setIndex] = useState(0); + const isMobile = useIsMobile(); + const { keys: shortcutKeys } = useKeyboardShortcut(keyboardShortcut); + const pathname = usePathname(); + const boardId = pathname?.split("/")[2]; + + const { data, isLoading } = api.board.all.useQuery( + { + workspacePublicId: workspace.publicId, + type: "regular", + archived: false, + }, + { enabled: workspace.publicId ? true : false }, + ); + + const handleMouseEnter = () => { + setIsHovered(true); + setIndex((index) => index + 1); + }; + + const handleClick = () => { + if (onCloseSideNav && isMobile) { + onCloseSideNav(); + } + }; + + return ( + + + +
+ + {name} +
+ {!isCollapsed && ( +
+ {shortcutKeys} +
+ )} +
+ + + {!isCollapsed && ( + + {isLoading ? ( +
+ +
+ ) : ( +
    +
    + {data?.map((board) => ( + + ))} +
+ )} +
+ )} +
+ ); +}; +export default CollapsibleBoardList; + +const CollapsibleBoardListItem: React.FC<{ + name: string; + key: string; + currentBoard: boolean; + href: string; +}> = ({ name, key, currentBoard, href }) => ( + +
  • + {name} +
  • + +); diff --git a/apps/web/src/components/SideNavigation.tsx b/apps/web/src/components/SideNavigation.tsx index ce032e69d..8bec473ea 100644 --- a/apps/web/src/components/SideNavigation.tsx +++ b/apps/web/src/components/SideNavigation.tsx @@ -31,6 +31,7 @@ import WorkspaceMenu from "~/components/WorkspaceMenu"; import { useModal } from "~/providers/modal"; import { useWorkspace } from "~/providers/workspace"; import { api } from "~/utils/api"; +import CollapsibleBoardList from "./CollapsibleBoardList "; interface SideNavigationProps { user: UserType; @@ -95,18 +96,6 @@ export default function SideNavigation({ icon: object; keyboardShortcut: KeyboardShortcut; }[] = [ - { - name: t`Boards`, - href: "/boards", - icon: isDarkMode ? boardsIconDark : boardsIconLight, - keyboardShortcut: { - type: "SEQUENCE", - strokes: [{ key: "G" }, { key: "B" }], - action: () => router.push("/boards"), - group: "NAVIGATION", - description: t`Go to boards`, - }, - }, { name: t`Templates`, href: "/templates", @@ -190,6 +179,23 @@ export default function SideNavigation({