Files
workspace/code/allapp/allapp-rn/src/store/space.ts
T
2026-03-03 17:28:56 +08:00

34 lines
849 B
TypeScript

import AsyncStorage from '@react-native-async-storage/async-storage'
import { create } from 'zustand'
import { createJSONStorage, persist } from 'zustand/middleware'
interface Space {
space_id: number
role: number
}
interface SpaceState {
currentSpace: Space | null
setCurrentSpace: (space: Space | null) => void
clear: () => void
inSpace: () => boolean
}
export const useSpaceStore = create<SpaceState>()(
persist(
(set, get) => ({
currentSpace: null,
setCurrentSpace: space => set({ currentSpace: space }),
clear: () => set({ currentSpace: null }),
inSpace: () => {
const currentSpace = get().currentSpace
return currentSpace !== null && currentSpace.space_id !== 0
},
}),
{
name: 'space-storage',
storage: createJSONStorage(() => AsyncStorage),
},
),
)