diff --git a/src/components/goto.tsx b/src/components/goto.tsx index b7ea687c8a86e2da17781a81ba8c0ba6a0d48616..5eb41f1124bcb17abcbfae6e30a00cb388b4525b 100644 --- a/src/components/goto.tsx +++ b/src/components/goto.tsx @@ -50,10 +50,12 @@ export const SupScrollLink : React.FC<SupScrollLinkProps> = ({label }) => { </sup> ); }; -const navigate = useNavigate(); + export const goToTextsAndOpenCollapsible = (collapseId: string) => { + const navigate = useNavigate(); navigate(collapseId); }; export const goToPagesAndOpenTab = (tabId: string) => { -navigate(tabId); + const navigate = useNavigate(); + navigate(tabId); }; \ No newline at end of file diff --git a/src/contents/wiki.tsx b/src/contents/wiki.tsx index 79312d8fb39adae3910b612bbfb1886e70dc7fc3..b4c2037f7882130588da1f07e574397c2c967a34 100644 --- a/src/contents/wiki.tsx +++ b/src/contents/wiki.tsx @@ -8,31 +8,31 @@ import React from "react"; export function Wiki () { const location = useLocation(); - useEffect(() => { - const params = new URLSearchParams(location.search); - const collapseId = params.get('collapseId'); - const tabId = params.get('tab'); + 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; + // Handle scroll to collapse section + 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', - }); - } - } + window.scrollTo({ + top: scrollPosition, + behavior: 'smooth', + }); + } + } - // Open the tab specified by tabId - if (tabId) { - openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); - } - }, [location.search]); + // Handle opening the tab + if (tabId) { + openFromOtherPage(tabId)({ currentTarget: document.getElementById(tabId)! }); + } + }, [location.search]); return ( <>