You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
import { create } from 'zustand';
|
|
|
|
export type Mode = 'edit' | 'view'
|
|
|
|
export interface AppState {
|
|
mapTab: Record<string, {
|
|
year: number | null,
|
|
region: number | null,
|
|
district: number | null
|
|
}>,
|
|
currentTab: string | null;
|
|
}
|
|
|
|
export const useAppStore = create<AppState>(() => ({
|
|
currentTab: null,
|
|
mapTab: {}
|
|
}))
|
|
|
|
const getCurrentTab = () => useAppStore.getState().currentTab
|
|
const setCurrentTab = (id: string | null) => useAppStore.setState(() => ({ currentTab: id }))
|
|
|
|
const setMapTabYear = (id: string, year: number | null) =>
|
|
useAppStore.setState((state) => {
|
|
return {
|
|
mapTab: {
|
|
...state.mapTab,
|
|
[id]: { ...state.mapTab[id], year: year }
|
|
}
|
|
}
|
|
})
|
|
|
|
const deleteMapTab = (id: string) =>
|
|
useAppStore.setState((state) => {
|
|
const { [id]: _, ...remainingTabs } = state.mapTab;
|
|
return { mapTab: remainingTabs };
|
|
})
|
|
|
|
export {
|
|
deleteMapTab,
|
|
getCurrentTab,
|
|
setCurrentTab,
|
|
setMapTabYear
|
|
}
|