From 42aefe306ffc83bdfea1e41df1e4b63a2bdd50ce Mon Sep 17 00:00:00 2001 From: Takeshi Kimata <117462761+kimatata@users.noreply.github.com> Date: Fri, 22 Mar 2024 23:07:16 +0900 Subject: [PATCH] Unify tabs with nextui's ListBoxItem --- frontend/app/projects/[projectId]/sidebar.tsx | 79 +++++++++++++------ 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/frontend/app/projects/[projectId]/sidebar.tsx b/frontend/app/projects/[projectId]/sidebar.tsx index 3255575..b4af631 100644 --- a/frontend/app/projects/[projectId]/sidebar.tsx +++ b/frontend/app/projects/[projectId]/sidebar.tsx @@ -1,5 +1,6 @@ "use client"; -import { Menu, MenuItem } from "@nextui-org/react"; +import { useState } from "react"; +import { Listbox, ListboxItem } from "@nextui-org/react"; import { Home, Files, FlaskConical } from "lucide-react"; import { useRouter } from "next/navigation"; import useGetCurrentIds from "@/utils/useGetCurrentIds"; @@ -7,31 +8,61 @@ import useGetCurrentIds from "@/utils/useGetCurrentIds"; export default function Sidebar() { const { projectId } = useGetCurrentIds(); const router = useRouter(); + + const [currentKey, setCurrentTab] = useState("home"); + const listBoxItemClassName = "p-3 rounded-none border-l-4 border-transparent"; + + const handleTabClick = (key: string) => { + setCurrentTab(key); + if (key === "home") { + router.push(`/projects/${projectId}/home`); + } else if (key === "cases") { + router.push(`/projects/${projectId}/folders`); + } else if (key === "runs") { + router.push(`/projects/${projectId}/runs`); + } + }; + + const tabItems = [ + { + key: "home", + text: "Home", + startContent: , + }, + { + key: "cases", + text: "Test Cases", + startContent: , + }, + { + key: "runs", + text: "Test Runs", + startContent: , + }, + ]; + return (
- - } - className="p-3" - onClick={() => router.push(`/projects/${projectId}/home`)} - > - Home - - } - className="p-3" - onClick={() => router.push(`/projects/${projectId}/folders`)} - > - Test Cases - - } - className="p-3" - onClick={() => router.push(`/projects/${projectId}/runs`)} - > - Test Runs - - + router.push(`/projects/${projectId}/home`)} + > + {tabItems.map((itr, index) => ( + handleTabClick(itr.key)} + className={ + currentKey === itr.key + ? listBoxItemClassName + " border-gray-600 " + : listBoxItemClassName + } + > + {itr.text} + + ))} +
); }