From 7635a5cd3a1166f3981aa81c3fc4fd1718eeece9 Mon Sep 17 00:00:00 2001 From: Nick Savage Date: Sat, 5 Oct 2024 15:06:00 -0400 Subject: [PATCH] frontend: implement tabbed interface for details --- .../src/pages/cards/ViewPage.tsx | 84 +++++++++++++++---- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/zettelkasten-front/src/pages/cards/ViewPage.tsx b/zettelkasten-front/src/pages/cards/ViewPage.tsx index 0cf0bec..b70aee1 100644 --- a/zettelkasten-front/src/pages/cards/ViewPage.tsx +++ b/zettelkasten-front/src/pages/cards/ViewPage.tsx @@ -51,6 +51,14 @@ export function ViewPage({}: ViewPageProps) { const { setLastCard } = usePartialCardContext(); const { tags } = useTagContext(); + const [activeTab, setActiveTab] = useState("Children"); + + const tabs = [ + { label: "Children" }, + { label: "References" }, + { label: "Related" }, + ]; + function onFileDelete(file_id: number) {} function handleViewCard(card_id: number) {} function openRenameModal(file: File) {} @@ -147,6 +155,10 @@ export function ViewPage({}: ViewPageProps) { } } + function handleTabClick(label: string) { + setActiveTab(label); + } + // For initial fetch and when id changes useEffect(() => { setError(""); @@ -264,26 +276,62 @@ export function ViewPage({}: ViewPageProps) { /> ))} - - - compareCardIds(a.card_id, b.card_id), +
+
+ {tabs.map((tab) => ( + handleTabClick(tab.label)} + className={` + cursor-pointer font-medium py-1.5 px-3 rounded-md flex items-center + ${ + activeTab === tab.label + ? "text-blue-600 border-b-4 border-blue-600" + : "text-gray-600 hover:text-gray-800 hover:bg-gray-100" + } + `} + > + {tab.label} + + {tab.label === "Children" && viewingCard.children.length} + {tab.label === "References" && viewingCard.references.length} + {tab.label === "Related" && relatedCards.length} + + + ))} +
+ {activeTab === "References" && ( +
+ + + compareCardIds(a.card_id, b.card_id), + )} + /> +
)} - /> - {viewingCard.children.length > 0 && ( -
- - - compareCardIds(a.card_id, b.card_id), + {activeTab === "Children" && ( +
+ {viewingCard.children.length > 0 && ( +
+ + + compareCardIds(a.card_id, b.card_id), + )} + card={viewingCard} + /> +
)} - card={viewingCard} - /> -
- )} - - - +
+ )} + {activeTab === "Related" && ( +
+ + +
+ )} +
)}