20260507213409
This commit is contained in:
1 parent
3070eac71b
commit
4c7f516a03
204 files changed
+3623
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { create } from "zustand";
|
||||
import { createJSONStorage, persist } from "zustand/middleware";
|
||||
|
||||
interface Family {
|
||||
family_id: number;
|
||||
}
|
||||
|
||||
interface FamilyState {
|
||||
currentFamily: Family;
|
||||
|
||||
setCurrentFamily: (family: Family) => void;
|
||||
|
||||
clear: () => void;
|
||||
|
||||
inFamily: () => boolean;
|
||||
}
|
||||
|
||||
const defaultFamily: Family = {
|
||||
family_id: 0,
|
||||
};
|
||||
|
||||
export const useFamilyStore = create<FamilyState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
currentFamily: defaultFamily,
|
||||
|
||||
setCurrentFamily: (family) =>
|
||||
set({
|
||||
currentFamily: family,
|
||||
}),
|
||||
|
||||
clear: () =>
|
||||
set({
|
||||
currentFamily: defaultFamily,
|
||||
}),
|
||||
|
||||
inFamily: () => {
|
||||
const currentFamily = get().currentFamily;
|
||||
|
||||
return currentFamily.family_id !== 0;
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "family-storage",
|
||||
storage: createJSONStorage(() => AsyncStorage),
|
||||
},
|
||||
),
|
||||
);
|
||||
Reference in new issue
Block a user