This commit is contained in:
oneao committed 2026-01-26 22:31:12 +08:00
1 parent 5a79414319
commit 8663cb2e3d
28 files changed
+744 -756

No files matched your search

+39 -11
View File
@@ -1,21 +1,49 @@
import type { icons } from 'lucide-react-native'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { router } from 'expo-router'
// store/navigation.ts
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
}
export const useNavStore = create<NavState>(set => ({
pathname: '/',
setPathname: (p: string) => set({ pathname: p }),
navigateToAuth: () => {
const pathname = useNavStore.getState().pathname
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' },
]
if (!pathname.startsWith('/auth')) {
router.replace('/auth')
}
},
}))
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.startsWith('/auth')) {
router.replace('/auth')
}
},
setNavMenus: navMenus => set({ navMenus }),
}),
{
name: 'nav-storage',
storage: createJSONStorage(() => AsyncStorage),
},
),
)