Skip to content

Commit

Permalink
improvement to active tab
Browse files Browse the repository at this point in the history
  • Loading branch information
adunndevster2 committed Jan 29, 2024
1 parent 7723230 commit 1ba2f89
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/theme/TOC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ function useForceUpdate() {

export default function TOC({ className, ...props }) {
const isBrowser = useIsBrowser();
if(!isBrowser) return (<div></div>);
if (!isBrowser) return <div></div>;

const forceUpdate = useForceUpdate();
let activeTab, setActiveTab;
function setupUseTabState() {
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (/^docusaurus\.tab\..+/.test(key)) {
[activeTab, setActiveTab] = [activeTab, setActiveTab] && useState(localStorage.getItem(key))
[activeTab, setActiveTab] =
[activeTab, setActiveTab] && useState(localStorage.getItem(key));
}
}
}
Expand Down Expand Up @@ -61,18 +62,24 @@ export default function TOC({ className, ...props }) {
if (nonTabHeadings.length) {
hashmap["all"] = nonTabHeadings;
}

var storageEvent = new StorageEvent("storage", {
key: "docusaurus.tab.ide",
});
if(isBrowser) setTimeout(() => window.dispatchEvent(storageEvent), 1);
console.log(hashmap);
return hashmap;
}

useEffect(() => {
tocHashMap = {};
tocHashMap = !tocHashMap["all"] ? constructTOCHashmap() : tocHashMap;
forceUpdate();

const handleStorageChange = (event) => {
if (event.key.includes("docusaurus.tab")) {
const newActiveTab = localStorage.getItem(event.key);
if(setActiveTab) setActiveTab(newActiveTab);
console.log(event.key);
if (setActiveTab) setActiveTab(newActiveTab);
}
};

Expand Down

0 comments on commit 1ba2f89

Please sign in to comment.