From 8b654a27dec857c83a2c42abed668ecb439de7dc Mon Sep 17 00:00:00 2001
From: Liliana Sanfilippo <lsanfilippo@techfak.uni-bielefeld.de>
Date: Thu, 28 Nov 2024 16:38:53 +0100
Subject: [PATCH] Engineering Sidebar fix

---
 src/sidebars/engS.tsx | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/sidebars/engS.tsx b/src/sidebars/engS.tsx
index 25f6b1d0..95cf1d8a 100644
--- a/src/sidebars/engS.tsx
+++ b/src/sidebars/engS.tsx
@@ -9,9 +9,32 @@ export function EngSide(){
     let nums = ["rep1", "rep2", "rep3", "rep4", "rep5", "rep6", "trf1", "trf2", "trf3", "trf4", "pe1", "pe2", "pe3", "peg1", "peg2", "peg3", "peg4", "peg5",
          "nic1", "nic2", "nic3", "nic4", "nic5", "nic6","del1", "del2", "del3", "del4", "del5"]
     useEffect(() => {
-        window.addEventListener('scroll', handleScroll);
-        return () => window.removeEventListener('scroll', handleScroll);
-      }, []);
+        window.addEventListener("scroll", handleScroll);
+        return () => window.removeEventListener("scroll", handleScroll);
+      }, [nums]);
+      
+      // Restore active tab on reload
+  useEffect(() => {
+    const params = new URLSearchParams(window.location.search);
+    const tabId = params.get("tab");
+    const subTabId = params.get("subTab");
+
+    if (tabId) {
+      // Find the parent element and mark it as active
+      const parentTab = document.querySelector(`#parent-${tabId}`);
+      if (parentTab) {
+        document.querySelectorAll(".active-sideitem").forEach((el) => el.classList.remove("active-sideitem"));
+        parentTab.classList.add("active-sideitem");
+      }
+      // Optionally expand the subtab if available
+      if (subTabId) {
+        const subTab = document.querySelector(`#${subTabId}`);
+        if (subTab) {
+          subTab.classList.add("highlight-subitem"); // Add a custom class for highlighting subtabs if needed
+        }
+      }
+    }
+  }, []);
       const handleScroll = () => {
           for(let idx in nums){
             /* console.log("We are looking at 'item' = " + nums[idx]) */
-- 
GitLab