Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • 2024/bielefeld-cebitec
  • l-sanfilippo/bielefeld-ce-bi-tec-temp
2 results
Show changes
import { openTab } from "./openTab";
// Funktion, um verschachtelte Tabs zu öffnen
export const openNestedTab = (parentTabId: string, childTabId: string, parentClass: string, childClass: string) => {
openTab(parentTabId, parentClass);
const nestedTabs = document.querySelectorAll(`#${parentTabId} ${childClass}`);
nestedTabs.forEach((tab) => {
(tab as HTMLElement).style.display = 'none';
});
const selectedNestedTab = document.getElementById(childTabId);
if (selectedNestedTab) {
selectedNestedTab.style.display = 'block';
}
};
\ No newline at end of file
// Function to open a main tab
export const openTab = (tabId: string, tabClass: string) => {
// console.log(`Trying to find tab with ID ${tabId}`);
const selectedTab = document.querySelector(`#${tabId}`);
if (selectedTab) {
//console.log('Tab found!');
const tabs = document.getElementsByClassName(tabClass);
for (let index = 0; index < tabs.length; index++) {
(tabs[index] as HTMLElement).style.display = 'none';
}
const selectedTab = document.getElementById(tabId);
if (selectedTab) {
selectedTab.style.display = 'block';
selectedTab.style.visibility = 'visible';
selectedTab.style.position = 'relative'; // In case there's a positioning issue
selectedTab.style.zIndex = '10'; // Ensure the tab is above other elements
}
} else {
console.error(`Tab with ID ${tabId} not found.`);
}
};
export const openTabInCollapsible = (tabId: string, collapsibleId: string) => {
// Warten Sie, bis das DOM vollständig geladen wurde
setTimeout(() => {
// Holen Sie sich das Collapsible
const collapsible = document.getElementById(collapsibleId);
if (!collapsible) {
console.error(`Collapsible mit ID ${collapsibleId} nicht gefunden!`);
return;
}
// Loggen Sie das, um sicherzustellen, dass das Collapsible korrekt gefunden wird
console.log(`Collapsible mit ID ${collapsibleId} gefunden`);
// Überprüfen Sie, ob der Tab mit der gegebenen ID existiert
const tab = collapsible.querySelector(`#${tabId}`);
if (!tab) {
console.error(`Tab mit ID ${tabId} im Collapsible ${collapsibleId} wurde nicht gefunden!`);
return;
}
let tabClass = tab!.className;
const tabs = document.getElementsByClassName(tabClass);
for (let index = 0; index < tabs.length; index++) {
(tabs[index] as HTMLElement).style.display = 'none';
}
// Wenn der Tab gefunden wurde, stellen Sie sicher, dass der Tab sichtbar gemacht wird
console.log(`Tab mit ID ${tabId} im Collapsible ${collapsibleId} wird jetzt geöffnet.`);
(tab as HTMLElement).style.display = 'block';
(tab as HTMLElement).style.visibility = 'visible';
(tab as HTMLElement).style.position = 'relative'; // Falls es ein Positionierungsproblem gibt
(tab as HTMLElement).style.zIndex = '10'; // Stelle sicher, dass der Tab über anderen Elementen liegt
// Loggen Sie den Stil des Tabs, um zu überprüfen, ob er tatsächlich auf 'block' gesetzt wurde
console.log(`Tab-Display-Stil für ${tabId}: ${(tab as HTMLElement).style.display}`);
}, 100); // 100 ms Verzögerung für DOM-Ladezeit
};
import { useNavigate } from "react-router-dom";
import { useState } from "react";
export const useNavigation = () => {
const navigate = useNavigate();
const [isLoading, setIsLoading] = useState(false);
const goToPagesAndOpenTab = (tabId: string, path: string) => {
navigate(`${path}?tab=${tabId}`);
};
const goToTextsAndOpenCollapsible = (collapseId: string, path: string) => {
navigate(`${path}?collapseId=${collapseId}`);
};
const goToPageWithTabAndCollapsible = ({ path, tabId, collapseId }: { path: string, tabId: string, collapseId?: string }) => {
......@@ -52,12 +47,72 @@ export const useNavigation = () => {
const goToPageAndScroll = (scrollToId: string, path: string) => {
navigate(`${path}?scrollTo=${scrollToId}`);
};
const goToPlace = ({
path,
scrollToId,
tabId,
subTabId,
collapseId,
tabincolId
}: {
path: string;
scrollToId?: string;
tabId?: string;
subTabId?: string;
collapseId?: string;
tabincolId?: string;
}) => {
// Den vollständigen Pfad erstellen, indem wir den basePath und path kombinieren
let url = `/${path.startsWith("/") ? path.slice(1) : path}`;
let paramsAdded = false;
console.log("Found path: " + path)
// 1. Tab-Logik (tabId und subTabId)
if (tabId) {
console.log("Found tabID: " + tabId)
url += `?tab=${tabId}`;
paramsAdded = true;
if (subTabId) {
console.log("Found subTabId: " + subTabId)
url += `&subTab=${subTabId}`;
}
}
// 2. Collapse-Logik (collapseId und tabincolId)
if (collapseId) {
console.log("Found collapseId: " + collapseId)
if (!tabId) {
// Wenn kein tabId gesetzt ist, fügen wir collapseId hinzu
url += url.includes('?') ? `&collapseId=${collapseId}` : `?collapseId=${collapseId}`;
paramsAdded = true;
}
if (tabincolId) {
console.log("Found tabincolId: " + tabincolId)
url += `&colTab=${tabincolId}`;
}
}
// 3. Scroll-Logik (scrollToId)
if (scrollToId) {
console.log("Found scrollToId: " + scrollToId)
// Wenn bereits Parameter existieren, fügen wir & hinzu, ansonsten ?
const separator = paramsAdded ? '&' : '?';
paramsAdded = true;
url += `${separator}scrollTo=${scrollToId}`;
}
console.log("Final URL:", url);
// Navigiere zur URL
navigate(url);
};
return { isLoading, goToPageAndScroll, setIsLoading, goToPagesAndOpenTab, goToPageWithTabAndScroll, goToPageWithNestedTabs, goToPageWithTabAndCollapsible, goToTextsAndOpenCollapsible };
return { goToPlace, goToPageAndScroll, goToPagesAndOpenTab, goToPageWithTabAndScroll, goToPageWithNestedTabs, goToPageWithTabAndCollapsible, goToTextsAndOpenCollapsible };
};
......@@ -5,6 +5,7 @@
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"noImplicitAny": false,
/* Bundler mode */
"moduleResolution": "bundler",
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.