Skip to content

Commit

Permalink
Use local storage to persist tab state, instead of hash values
Browse files Browse the repository at this point in the history
  • Loading branch information
shobensack committed Jun 20, 2024
1 parent c9a87ec commit c72d078
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const Home: NextPage = () => {
return;

// on tab change, update hash
window.location.hash = TabNames[currentTab];
localStorage.setItem("currentTab", TabNames[currentTab]);
}, [currentTab]);

useEffect(() => {
// on page load, check for hash and change tab, if applicable
var hashValue = window.location.hash ? window.location.hash.replace('#', '') : '';
var selectedTab = hashValue as keyof typeof TabNames;
const storedCurrentTab = localStorage.getItem("currentTab");
const selectedTab = storedCurrentTab as keyof typeof TabNames;

if (hashValue && selectedTab in TabNames) {
if (storedCurrentTab && selectedTab in TabNames) {
setCurrentTab(TabNames[selectedTab])
} else {
setCurrentTab(TabNames.Quests)
Expand Down

0 comments on commit c72d078

Please sign in to comment.