update: add zustand store and basic setup

This commit is contained in:
purp1e
2024-09-21 02:25:23 +08:00
parent 6625e0c57d
commit b3973fd101
10 changed files with 202 additions and 1 deletions

45
src/store/steam.ts Normal file
View File

@@ -0,0 +1,45 @@
import { SteamUser } from '@/types/steam'
import { create } from 'zustand'
const mock_user: SteamUser = {
steamID64: "76561198052315353",
steamID32: "STEAM_0:0:46157676",
accountName: "wrr",
personaName: "wrr",
recent: 0,
avatar: "",
// "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/0d/0d1d4b9e1a9e8b2b3d4d0a7e1b3d6b1e3f8f4f7.jpg",
}
interface SteamState {
dir: string,
csDir: string,
users: SteamUser[],
currentUser: () => SteamUser,
isDirValid: boolean,
isCsDirValid: boolean,
init: () => void,
updateDir: (dir: string) => void,
updateCsDir: (dir: string) => void,
}
const useSteamStore = create<SteamState>()((set, get) => ({
// 路径
dir: "C:\\Program Files (x86)\\Steam",
csDir: "",
users: [mock_user] as SteamUser[],
currentUser: () => {
return get().users[0] || mock_user
},
// 路径是否可用
isDirValid: false,
isCsDirValid: false,
init: () => {
console.log('init')
},
updateDir: (dir: string) => set(() => ({ dir: dir })),
updateCsDir: (dir: string) => set(() => ({ csDir: dir })),
// increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
}))
export default useSteamStore