Skip to content
Snippets Groups Projects
Commit 796654fb authored by Liliana Sanfilippo's avatar Liliana Sanfilippo
Browse files

fixed?

parent 6bbd61a3
No related branches found
No related tags found
No related merge requests found
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
import { openFromOtherPage } from './openFromOtherpAge'; import { openFromOtherPage } from './openFromOtherpAge';
import { handleScroll } from './handleScroll'; import { handleScroll } from './handleScroll';
import { openNestedTab } from './openNestedTab'; import { openNestedTab } from './openNestedTab';
...@@ -9,14 +9,25 @@ import { openTabInCollapsible } from './opentabincollapsible'; ...@@ -9,14 +9,25 @@ import { openTabInCollapsible } from './opentabincollapsible';
// Custom Hook for central tab navigation // Custom Hook for central tab navigation
export const useTabNavigation = () => { export const useTabNavigation = () => {
const location = useLocation(); const location = useLocation();
const navigate = useNavigate();
const [activeTab, setActiveTab] = useState<string | null>(null); const [activeTab, setActiveTab] = useState<string | null>(null);
const [activeSubTab, setActiveSubTab] = useState<string | null>(null); const [activeSubTab, setActiveSubTab] = useState<string | null>(null);
const [, setActiveCollapsible] = useState<string | null>(null); const [, setActiveCollapsible] = useState<string | null>(null);
// tab change and url update // tab change and url update
const handleTabChange = (tabId: string, subTabId?: string) => {
setActiveTab(tabId);
setActiveSubTab(subTabId || null);
// updatung the url
let newUrl = `${location.pathname}?tab=${tabId}`;
if (subTabId) {
newUrl += `&subTab=${subTabId}`;
}
navigate(newUrl, { replace: true });
}
useEffect(() => { useEffect(() => {
console.log("Use Effect") console.log("Use Effect")
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
...@@ -26,7 +37,11 @@ export const useTabNavigation = () => { ...@@ -26,7 +37,11 @@ export const useTabNavigation = () => {
const scrollToId = params.get('scrollTo'); const scrollToId = params.get('scrollTo');
const changeTo = params.get('changeTo'); const changeTo = params.get('changeTo');
const colTab = params.get('colTab'); const colTab = params.get('colTab');
// const navigate = useNavigate();
// scrolls to a specific collapsible element // scrolls to a specific collapsible element
if (collapseId) { if (collapseId) {
setActiveCollapsible(collapseId); setActiveCollapsible(collapseId);
...@@ -77,11 +92,13 @@ export const useTabNavigation = () => { ...@@ -77,11 +92,13 @@ export const useTabNavigation = () => {
} }
} }
setActiveTab(tabId); setActiveTab(tabId);
setActiveSubTab(subTabId || null); setActiveSubTab(subTabId || null);
}, [location.search]); }, [location.search]);
return { activeTab, activeSubTab }; return { activeTab, activeSubTab, handleTabChange};
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment