diff --git a/src/contents/sections.tsx b/src/components/sections.tsx similarity index 93% rename from src/contents/sections.tsx rename to src/components/sections.tsx index 72027fdcaa32784456dd2b3f1e8460af1b23b68a..5d23303fee8eefdb70849aa8836647e3da24e2e4 100644 --- a/src/contents/sections.tsx +++ b/src/components/sections.tsx @@ -1,4 +1,4 @@ -import { H2 } from "../components/Headings" +import { H2 } from "./Headings" export function Section({id, title, children}: {id: string, title: string, children: React.ReactNode}){ diff --git a/src/contents/Home.tsx b/src/contents/Home.tsx index d9ee5a7584640d9ca7caf6abf322164be9fa019d..59564d1a6d838abc13c3eece22b4bd0ea4aa236e 100644 --- a/src/contents/Home.tsx +++ b/src/contents/Home.tsx @@ -1,8 +1,10 @@ import { FadeIn } from "../components/FadeIn"; import { Breathe } from "../components/Breathe"; import { Problems } from "../components/Problems"; +import { useNavigateTabs } from "../utils/navigation"; export function Home() { + useNavigateTabs(); return ( <div className="row mt-4"> <div className="col"> diff --git a/src/contents/contribution.tsx b/src/contents/contribution.tsx index a35e3dbccb5dd80d39e623c5d0821322c4e5663b..6726f6a18890f55b128d527e4b8d122ed37a65dc 100644 --- a/src/contents/contribution.tsx +++ b/src/contents/contribution.tsx @@ -1,45 +1,14 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { BFHTimeline } from "../components/BFH-Timeline"; import BFHGallery from "../components/Photo-grid"; import BFHpdf, { GuidePDF } from "../components/Pdfs"; import { H2} from "../components/Headings"; import { OLDBFHStyleTabs } from "../components/Tabs"; import { BlockQuoteB } from "../components/Quotes"; -import { handleScrollToCollapse, openNestedTab, openTab } from "../utils/TabNavigation"; +import { useNavigateTabs } from "../utils/navigation"; export function Contribution() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - const subTabId = params.get('subTab'); // Neues Parameter für verschachtelte Tabs - - // Open the tab specified by tabId (and subTab if nested) - if (tabId) { - if (subTabId) { - // If subTab is provided, open the nested tab - openNestedTab(tabId, subTabId); - } else { - // Otherwise, just open the main tab - openTab(tabId); - } - } - - // Scroll to the section specified by collapseId after opening the tab - if (collapseId) { - handleScrollToCollapse(collapseId); - } - - // Open the tab from another page - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); + useNavigateTabs(); return ( <> diff --git a/src/contents/description.tsx b/src/contents/description.tsx index a4af87212dc5fff97e136398d5553d13e7af4dbc..e52957e866c482f084296c1d923699ef5fae39df 100644 --- a/src/contents/description.tsx +++ b/src/contents/description.tsx @@ -1,4 +1,3 @@ -import { useLocation } from "react-router-dom"; import { InfoBox } from "../components/Boxes"; import { TabButtonRow } from "../components/Buttons"; import Collapsible from "../components/Collapsible"; @@ -8,43 +7,12 @@ import { LoremMedium, LoremShort } from "../components/Loremipsum"; import { Circle } from "../components/Shapes"; import { Complex } from "../components/Svgs"; import { ButtonRowTabs } from "../components/Tabs"; -import { useEffect } from "react"; import PieChart from "../components/Graph"; import PreCyse from "../components/precyse"; -import { handleScrollToCollapse, openNestedTab, openTab } from "../utils/TabNavigation"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; +import { useNavigateTabs } from "../utils/navigation"; export function Description() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - const subTabId = params.get('subTab'); // Neues Parameter für verschachtelte Tabs - - // Open the tab specified by tabId (and subTab if nested) - if (tabId) { - if (subTabId) { - // If subTab is provided, open the nested tab - openNestedTab(tabId, subTabId); - } else { - // Otherwise, just open the main tab - openTab(tabId); - } - } - - // Scroll to the section specified by collapseId after opening the tab - if (collapseId) { - handleScrollToCollapse(collapseId); - } - - // Open the tab from another page - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <div className="row mt-4"> <div className="col"> diff --git a/src/contents/example.tsx b/src/contents/example.tsx index d3b38ddedfc3a328a88ebed7f33f57eebc7dde50..9a6037276508aff78b6fc9e6b948be10debf23c4 100644 --- a/src/contents/example.tsx +++ b/src/contents/example.tsx @@ -10,6 +10,7 @@ import React from 'react'; import { Bar, Doughnut, PolarArea } from 'react-chartjs-2'; import { Chart as ChartJS, Tooltip, Legend, BarElement, CategoryScale, LinearScale, Title, RadialLinearScale } from 'chart.js'; import ProteinViewer from '../components/Fanzorviewer.tsx'; +import { useNavigateTabs } from "../utils/navigation.ts"; ChartJS.register( @@ -23,6 +24,7 @@ ChartJS.register( ); export function Example() { + useNavigateTabs(); return ( <> <div className="container"> diff --git a/src/contents/experiments.tsx b/src/contents/experiments.tsx index a87e7aeb543d14c65614b479d2137098ae8c534a..05bb3f8943a09ee238adc20ad099ff92d38d9506 100644 --- a/src/contents/experiments.tsx +++ b/src/contents/experiments.tsx @@ -1,37 +1,8 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { H2 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Experiments() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <H2 id="heading" text="Heading" ></H2> diff --git a/src/contents/human-practices.tsx b/src/contents/human-practices.tsx index 569000b68159ed2bb5e81f77b87a894e5dac040c..89a475a3871581693fccd96cabf1ccf084c7780c 100644 --- a/src/contents/human-practices.tsx +++ b/src/contents/human-practices.tsx @@ -49,46 +49,18 @@ <p></p> */ import { ButtonOne } from "../components/Buttons"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { BlockQuoteB } from "../components/Quotes"; -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; import { useNavigation } from "../utils/useNavigation"; import { openElement } from "../utils/openElement"; import { HPTimeline } from "../components/HP-timeline"; import { H2, H3 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function HumanPractices() { - const { goToPagesAndOpenTab/* , goToTextsAndOpenCollapsible */ } = useNavigation(); + useNavigateTabs(); + const { goToPagesAndOpenTab } = useNavigation(); openElement({buttonClass: "tabbutton", elementToOpen: "All", classToHide: "timelinecardtabs", }); - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); return ( <div className="row mt-4"> diff --git a/src/contents/igem-bielefeld.tsx b/src/contents/igem-bielefeld.tsx index 3410f8fad98cd19d6ca329e79a1d9ee9f37bf536..ce2a81c1e5704b4002b6cb0d1943ed158a62a50c 100644 --- a/src/contents/igem-bielefeld.tsx +++ b/src/contents/igem-bielefeld.tsx @@ -1,36 +1,7 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; +import { useNavigateTabs } from "../utils/navigation"; export function igemBielefeld() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <div className="row mt-4"> diff --git a/src/contents/impressum.tsx b/src/contents/impressum.tsx index 1368a8b8b687fbd8d5f0d62e09aaf4e3039a06c5..dcfe7f922a0c86af01374a92fdf78ff3e48c6134 100644 --- a/src/contents/impressum.tsx +++ b/src/contents/impressum.tsx @@ -1,37 +1,8 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { H2 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Impressum() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <div className="row"> diff --git a/src/contents/judging.tsx b/src/contents/judging.tsx index 37bb08eb177c62a8f9041e7df8e5d1fce4b66385..65979d6414e4bf304f29b3c2209c18f49b38b991 100644 --- a/src/contents/judging.tsx +++ b/src/contents/judging.tsx @@ -1,36 +1,7 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { H2 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Judging() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <H2 text="Overview" id="overview"/> diff --git a/src/contents/notebook.tsx b/src/contents/notebook.tsx index a7c02531ac91d917b598187df9ab963f62d538f9..a123cd9be597e807f38a2fd1eb3119e3fa3c7a23 100644 --- a/src/contents/notebook.tsx +++ b/src/contents/notebook.tsx @@ -1,37 +1,8 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import H1 from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Notebook() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <div className="row mt-4"> diff --git a/src/contents/partners.tsx b/src/contents/partners.tsx index 01d4d1b788e2111bc2253efc82bf7eba29a3b362..219a906c8ba6b443eb51baa3156210337308142f 100644 --- a/src/contents/partners.tsx +++ b/src/contents/partners.tsx @@ -1,37 +1,8 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import H1, { H2 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Partners() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <div id="sidebarbox" className="col-1 d-none d-lg-block"> </div> diff --git a/src/contents/parts.tsx b/src/contents/parts.tsx index 4a0606a96fcc60e57b0a212046a3fbc5847b6342..9cbcd009e85bc00767ec257e314bb83ed38b506a 100644 --- a/src/contents/parts.tsx +++ b/src/contents/parts.tsx @@ -1,35 +1,6 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; +import { useNavigateTabs } from "../utils/navigation"; export function Parts() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <div className="row"> diff --git a/src/contents/project-documentation.tsx b/src/contents/project-documentation.tsx index d510479f9cdf4802a645380e74bca8df6b52fee9..cfa32d5f974d95d4674b51956b8da9c6029136d5 100644 --- a/src/contents/project-documentation.tsx +++ b/src/contents/project-documentation.tsx @@ -1,36 +1,7 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; +import { useNavigateTabs } from "../utils/navigation"; export function ProDesc() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <></> ); diff --git a/src/contents/results.tsx b/src/contents/results.tsx index 5fef62c39269682eff3d680551d709409aafb6fc..02f7553222cc487e259780ce3ac9076cc23aa662 100644 --- a/src/contents/results.tsx +++ b/src/contents/results.tsx @@ -1,37 +1,8 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { H2 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Results() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> diff --git a/src/contents/safety.tsx b/src/contents/safety.tsx index acc561de746796aa52739819567eaaf464eb71ec..94c8849a6104e4b02332e685648e8ad0808e0be8 100644 --- a/src/contents/safety.tsx +++ b/src/contents/safety.tsx @@ -1,6 +1,6 @@ import { LoremMedium } from "../components/Loremipsum"; -import { Section, Subesction } from "./sections"; +import { Section, Subesction } from "../components/sections"; import { useNavigateTabs } from "../utils/navigation"; export const Safety: React.FC = () =>{ diff --git a/src/contents/supplementary-material.tsx b/src/contents/supplementary-material.tsx index 1a2d5b571f0ca0ad2c7f673e8318316ec8e119c3..84303c3463b6102208708b45a218fbb9ce65929b 100644 --- a/src/contents/supplementary-material.tsx +++ b/src/contents/supplementary-material.tsx @@ -1,35 +1,6 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; +import { useNavigateTabs } from "../utils/navigation"; export function Supplementary() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <> <div className="row"> diff --git a/src/contents/team.tsx b/src/contents/team.tsx index 2b1735ab9a089255304e73c84c115ba35b47afdc..2e4dc4990d57797e8b41748a0f1d128823ca4b7d 100644 --- a/src/contents/team.tsx +++ b/src/contents/team.tsx @@ -1,37 +1,8 @@ -import { useEffect } from "react"; -import { useLocation } from "react-router-dom"; -import { openFromOtherPage } from "../utils/openFromOtherpAge"; import { H2 } from "../components/Headings"; +import { useNavigateTabs } from "../utils/navigation"; export function Team() { - const location = useLocation(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); - - // Scroll to the section specified by collapseId - if (collapseId) { - const collapseElement = document.getElementById(collapseId); - if (collapseElement) { - const elementTop = collapseElement.getBoundingClientRect().top + window.pageYOffset; - const offset = window.innerHeight / 2 - collapseElement.offsetHeight / 2; - const scrollPosition = elementTop - offset; - - window.scrollTo({ - top: scrollPosition, - behavior: 'smooth', - }); - } - } - - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); - + useNavigateTabs(); return ( <>