51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import type { icons } from 'lucide-react-native'
|
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
import { router } from 'expo-router'
|
|
import { create } from 'zustand'
|
|
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
|
|
export interface NavItem {
|
|
label: string
|
|
path: string
|
|
icon: keyof typeof icons
|
|
}
|
|
|
|
interface NavState {
|
|
navMenus: NavItem[]
|
|
pathname: string
|
|
setPathname: (p: string) => void
|
|
navigateToAuth: () => void
|
|
setNavMenus: (menus: NavItem[]) => void
|
|
}
|
|
|
|
const DEFAULT_NAV_MENUS: NavItem[] = [
|
|
{ label: '记账', path: '/money', icon: 'CircleDollarSign' },
|
|
{ label: '恋爱记', path: '/love', icon: 'Heart' },
|
|
{ label: '聊天', path: '/chat', icon: 'MessageCircle' },
|
|
{ label: '个人中心', path: '/user', icon: 'CircleUserRound' },
|
|
{ label: '我的空间', path: '/auth/space', icon: 'Earth' },
|
|
]
|
|
|
|
export const useNavStore = create<NavState>()(
|
|
persist(
|
|
(set, get) => ({
|
|
pathname: '/',
|
|
navMenus: DEFAULT_NAV_MENUS,
|
|
|
|
setPathname: (p: string) => set({ pathname: p }),
|
|
navigateToAuth: () => {
|
|
const pathname = useNavStore.getState().pathname
|
|
|
|
if (pathname !== '/auth') {
|
|
router.replace('/auth')
|
|
}
|
|
},
|
|
setNavMenus: navMenus => set({ navMenus }),
|
|
}),
|
|
{
|
|
name: 'nav-storage',
|
|
storage: createJSONStorage(() => AsyncStorage),
|
|
},
|
|
),
|
|
)
|