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

so funktoionier es gerade

parent ad616978
No related branches found
No related tags found
No related merge requests found
Pipeline #531600 failed
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useNavigate, useLocation } from 'react-router-dom'; import { useLocation } 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';
...@@ -7,24 +7,13 @@ import { openTab } from './openTab'; ...@@ -7,24 +7,13 @@ import { openTab } from './openTab';
// Custom Hook for central tab navigation // Custom Hook for central tab navigation
export const useTabNavigation = () => { export const useTabNavigation = () => {
const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
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);
// 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")
...@@ -35,6 +24,15 @@ export const useTabNavigation = () => { ...@@ -35,6 +24,15 @@ export const useTabNavigation = () => {
const scrollToId = params.get('scrollTo'); const scrollToId = params.get('scrollTo');
const changeTo = params.get('changeTo'); const changeTo = params.get('changeTo');
// scrolls to a specific collapsible element
if (collapseId) {
const collapsible = document.getElementById(collapseId);
if (collapsible && collapsible.classList.contains('collapsed')) {
collapsible.classList.remove('collapsed'); // Open the collapsible
}
handleScroll(collapseId); // This triggers the scroll action
}
// opens main and (if necessary) subtab // opens main and (if necessary) subtab
if (tabId) { if (tabId) {
let tab = document.getElementById(tabId); let tab = document.getElementById(tabId);
...@@ -48,10 +46,7 @@ export const useTabNavigation = () => { ...@@ -48,10 +46,7 @@ export const useTabNavigation = () => {
} }
} }
// scrolls to a specific collapsible element
if (collapseId) {
handleScroll(collapseId);
}
// opens tab on another page // opens tab on another page
if (tabId) { if (tabId) {
...@@ -81,7 +76,7 @@ export const useTabNavigation = () => { ...@@ -81,7 +76,7 @@ export const useTabNavigation = () => {
setActiveSubTab(subTabId || null); setActiveSubTab(subTabId || null);
}, [location.search]); }, [location.search]);
return { activeTab, activeSubTab, handleTabChange }; return { activeTab, activeSubTab };
}; };
...@@ -5,7 +5,7 @@ export const handleScroll = (scrollId: string) => { ...@@ -5,7 +5,7 @@ export const handleScroll = (scrollId: string) => {
const elementTop = scrollElement.getBoundingClientRect().top + window.pageYOffset; const elementTop = scrollElement.getBoundingClientRect().top + window.pageYOffset;
const offset = window.innerHeight / 2 - scrollElement.offsetHeight / 2; const offset = window.innerHeight / 2 - scrollElement.offsetHeight / 2;
const scrollPosition = elementTop - offset; const scrollPosition = elementTop - offset;
window.scrollTo({ window.scrollTo({
top: scrollPosition, top: scrollPosition,
behavior: 'smooth', behavior: 'smooth',
......
import { openTab } from "./openTab";
import { handleScroll } from "./handleScroll";
// Funktion, um einen Tab in einem Collapsible zu öffnen
export const openTabInCollapsible = (
collapsibleId: string, // ID des Collapsibles
tabId: string, // ID des zu öffnenden Tabs
collapsibleClass: string, // Klasse des Collapsibles (z. B. für das Styling)
tabClass: string // Klasse des Tabs (z. B. für das Styling)
) => {
// Öffne das Collapsible (falls es geschlossen ist)
const collapsible = document.getElementById(collapsibleId);
if (collapsible && collapsible.classList.contains('collapsed')) {
collapsible.classList.remove('collapsed'); // Öffne das Collapsible
}
// Stelle sicher, dass wir zu diesem Collapsible scrollen
handleScroll(collapsibleId);
// Öffne den entsprechenden Tab innerhalb des Collapsibles
openTab(tabId, tabClass);
// Optional: Wir können auch zu diesem Tab scrollen, wenn nötig
const selectedTab = document.getElementById(tabId);
if (selectedTab) {
const elementTop = selectedTab.getBoundingClientRect().top + window.pageYOffset;
const offset = window.innerHeight / 2 - selectedTab.offsetHeight / 2;
const scrollPosition = elementTop - offset;
window.scrollTo({
top: scrollPosition,
behavior: 'smooth',
});
}
};
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