feat: add all source files - services, store, hooks, components, screens

This commit is contained in:
Developer
2026-03-05 18:02:54 +08:00
parent bbe0df6ed2
commit a0e53bd073
15 changed files with 755 additions and 0 deletions

42
store/authStore.ts Normal file
View File

@@ -0,0 +1,42 @@
import { create } from 'zustand';
import AsyncStorage from '@react-native-async-storage/async-storage';
interface AuthState {
sessdata: string | null;
uid: string | null;
username: string | null;
isLoggedIn: boolean;
login: (sessdata: string, uid: string, username?: string) => Promise<void>;
logout: () => Promise<void>;
restore: () => Promise<void>;
}
export const useAuthStore = create<AuthState>((set) => ({
sessdata: null,
uid: null,
username: null,
isLoggedIn: false,
login: async (sessdata, uid, username) => {
await AsyncStorage.multiSet([
['SESSDATA', sessdata],
['UID', uid],
['USERNAME', username ?? ''],
]);
set({ sessdata, uid, username: username ?? null, isLoggedIn: true });
},
logout: async () => {
await AsyncStorage.multiRemove(['SESSDATA', 'UID', 'USERNAME']);
set({ sessdata: null, uid: null, username: null, isLoggedIn: false });
},
restore: async () => {
const sessdata = await AsyncStorage.getItem('SESSDATA');
const uid = await AsyncStorage.getItem('UID');
const username = await AsyncStorage.getItem('USERNAME');
if (sessdata) {
set({ sessdata, uid, username, isLoggedIn: true });
}
},
}));