From 45eccb2a8b83737315d2e28cc060f304ac0a2872 Mon Sep 17 00:00:00 2001 From: Liliana Sanfilippo <liliana.sanfilippo@uni-bielefeld.de> Date: Mon, 23 Sep 2024 20:20:12 +0200 Subject: [PATCH] engineering tab routing --- src/App/App.css | 6 ++- src/sidebars/engS.tsx | 6 +-- src/utils/openThem.ts | 88 ++++++++++++++++++++++++------------------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/App/App.css b/src/App/App.css index 67e2f3e6..f1cde9bf 100644 --- a/src/App/App.css +++ b/src/App/App.css @@ -3765,4 +3765,8 @@ a{ color: var(--accent-primary) !important; margin-right: 5px; top: 5px; -} \ No newline at end of file +} + +#eng-sidebar a{ + color: var(--text-primary) !important; +} diff --git a/src/sidebars/engS.tsx b/src/sidebars/engS.tsx index 76396c8a..86253669 100644 --- a/src/sidebars/engS.tsx +++ b/src/sidebars/engS.tsx @@ -26,10 +26,10 @@ export function EngSide(){ return( - <div className="col-2 d-none d-lg-block"> + <div className="col-2 d-none d-lg-block" > <br/> <div className="sticky-top"> - <nav className="sidebar"> + <nav className="sidebar" id="eng-sidebar"> <div> <a onClick={openThem({it: "our-cycle", scrollToId: "ourcycle"})}> <div className="detail-sideitem"> @@ -187,7 +187,7 @@ export function EngSide(){ </div> </nav> <br/> - <div className="col" style={{display: "flex", alignItems: "right"}}> + <div className="col" id="eng-backup" style={{display: "flex", alignItems: "right"}}> <a href='#' className="backtotop"> Back to Top ↑ </a> diff --git a/src/utils/openThem.ts b/src/utils/openThem.ts index b515635e..ad804309 100644 --- a/src/utils/openThem.ts +++ b/src/utils/openThem.ts @@ -1,40 +1,50 @@ -export function openThem({it, scrollToId}: {it: string, scrollToId?: string}) { - const gotoandopen = (_event: React.MouseEvent<HTMLElement, MouseEvent>) => { - console.log("it classname: " + document.getElementById(it)?.className); - console.log("it: " + it); +export function openThem({ it, scrollToId }: { it: string; scrollToId?: string }) { + const gotoandopen = (_event: React.MouseEvent<HTMLElement, MouseEvent>) => { + updateTabs(it, scrollToId); - let contenttabid = "tab-" + it; - let parent = "parent-" + it; - console.log("we want to open " + it + " and " + contenttabid); - - let sideitems = document.getElementsByClassName("sideitem"); - let subtabs = document.getElementsByClassName("sidesubtab"); - let contenttabs = document.getElementsByClassName("enginneeringtab"); - - // Verstecke alle Subtabs und Content-Tabs - for (let i = 0; i < subtabs.length; i++) { - (subtabs[i] as HTMLElement).style.display = "none"; - console.log("Hiding sidebar subtab..."); - } - for (let i = 0; i < contenttabs.length; i++) { - (contenttabs[i] as HTMLElement).style.display = "none"; - console.log("Hiding content tab..."); - } - for (let i = 0; i < sideitems.length; i++) { - (sideitems[i] as HTMLElement)!.classList.remove("active-sideitem"); - console.log("Hiding sidebar subtab..."); - } - - // Zeige den aktuellen Tab und markiere das entsprechende Sidebar-Item - document.getElementById(it)!.style.display = "block"; - document.getElementById(parent)!.classList.add("active-sideitem"); - document.getElementById(contenttabid)!.style.display = "block"; - - // Scrolle zu der angegebenen ID, falls vorhanden - if (scrollToId && document.getElementById(scrollToId)) { - console.log("Scrolling to: " + scrollToId); - document.getElementById(scrollToId)!.scrollIntoView({ behavior: "smooth" }); - } - }; - return gotoandopen; -} + // Update der URL + const newUrl = `?tab=${it}`; + window.history.pushState({ tab: it }, '', newUrl); + }; + + return gotoandopen; + } + + function updateTabs(it: string, scrollToId?: string) { + let contenttabid = "tab-" + it; + let parent = "parent-" + it; + + // Verstecke alle Subtabs und Content-Tabs + const subtabs = document.getElementsByClassName("sidesubtab"); + const contenttabs = document.getElementsByClassName("enginneeringtab"); + const sideitems = document.getElementsByClassName("sideitem"); + + for (let i = 0; i < subtabs.length; i++) { + (subtabs[i] as HTMLElement).style.display = "none"; + } + for (let i = 0; i < contenttabs.length; i++) { + (contenttabs[i] as HTMLElement).style.display = "none"; + } + for (let i = 0; i < sideitems.length; i++) { + (sideitems[i] as HTMLElement)!.classList.remove("active-sideitem"); + } + + // Zeige den aktuellen Tab und markiere das entsprechende Sidebar-Item + document.getElementById(it)!.style.display = "block"; + document.getElementById(parent)!.classList.add("active-sideitem"); + document.getElementById(contenttabid)!.style.display = "block"; + + // Scrolle zu der angegebenen ID, falls vorhanden + if (scrollToId && document.getElementById(scrollToId)) { + document.getElementById(scrollToId)!.scrollIntoView({ behavior: "smooth" }); + } + } + + // Füge einen Event Listener für `popstate` hinzu + window.addEventListener('popstate', (event) => { + if (event.state) { + const tab = event.state.tab; + updateTabs(tab); + } + }); + \ No newline at end of file -- GitLab