Skip to content

Commit

Permalink
refactor: persist tab state
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 10, 2024
1 parent c42c9f4 commit 7def04b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/layout/drawer/Extras.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const RaidQuickSelect = () => {
)
return (
<CollapsibleItem open={enabled}>
<MultiSelectorList>
<MultiSelectorList tabKey="raids">
<SelectorListMemo
key="eggs"
category="gyms"
Expand Down Expand Up @@ -208,7 +208,7 @@ const BaseQuestSet = () => {
items={QUEST_SETS}
/>
</ListItem>
<MultiSelectorList>
<MultiSelectorList tabKey="quests">
<SelectorListMemo
key="items"
category="pokestops"
Expand Down Expand Up @@ -250,7 +250,7 @@ const BaseInvasion = () => {
</ListItem>
)}
{hasConfirmed ? (
<MultiSelectorList>
<MultiSelectorList tabKey="invasions">
<SelectorListMemo
key="invasions"
category="pokestops"
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/drawer/Pokemon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function PokemonDrawer() {
const filterMode = useStorage((s) => s.getPokemonFilterMode())
const [ivOr, setIvOr] = useDeepStore('filters.pokemon.ivOr')
const { t } = useTranslation()
const [openTab, setOpenTab] = React.useState(0)
const [openTab, setOpenTab] = useDeepStore(`tabs.pokemon`, 0)
const ui = useMemory((s) => s.ui.pokemon)
const selectRef = React.useRef(/** @type {HTMLDivElement | null} */ (null))

Expand Down
8 changes: 4 additions & 4 deletions src/components/layout/drawer/SelectorList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useTranslation } from 'react-i18next'
import { useTranslateById } from '@hooks/useTranslateById'
import { useMemory } from '@hooks/useMemory'
import { useLayoutStore } from '@hooks/useLayoutStore'
import { useStorage } from '@hooks/useStorage'
import { useDeepStore, useStorage } from '@hooks/useStorage'

import { BoolToggle } from './BoolToggle'
import { GenericSearchMemo } from './ItemSearch'
Expand Down Expand Up @@ -202,10 +202,10 @@ export const SelectorListMemo = React.memo(
prev.height === next.height,
)

/** @param {{ children: React.ReactElement[] }} props */
export function MultiSelectorList({ children }) {
/** @param {{ children: React.ReactElement[], tabKey: string }} props */
export function MultiSelectorList({ children, tabKey }) {
const { t } = useTranslation()
const [openTab, setOpenTab] = React.useState(0)
const [openTab, setOpenTab] = useDeepStore(`tabs.${tabKey}`, 0)

const handleTabChange = (_e, newValue) => setOpenTab(newValue)

Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { persist, createJSONStorage } from 'zustand/middleware'
* tileServers: string
* },
* searches: Record<string, string>,
* tabs: Record<string, number>,
* menus: Record<string, boolean>,
* holidayEffects: Record<string, boolean>,
* motdIndex: number
Expand Down Expand Up @@ -111,6 +112,7 @@ export const useStorage = create(
holidayEffects: {},
settings: {},
searches: {},
tabs: {},
userSettings: {},
icons: {},
audio: {},
Expand Down

0 comments on commit 7def04b

Please sign in to comment.