[feat] better store operation

This commit is contained in:
2025-03-17 11:48:30 +08:00
parent 47dc77732f
commit db3cf9aef2
15 changed files with 169 additions and 127 deletions

View File

@@ -1,18 +1,16 @@
"use client"
import { appStore } from "@/store/app"
import { useSnapshot } from "valtio"
import { useAppStore } from "@/store/app"
export default function Page() {
void appStore.start()
const app = useSnapshot(appStore.state)
const app = useAppStore()
return (
<div className="flex flex-col items-start gap-3 pt-2 pb-1">
<p>{app.version}</p>
<p>{app.hasUpdate ? "有" : "无"}</p>
<p>{app.inited ? "是" : "否"}</p>
<p>{app.notice}</p>
<p>使{app.useMirror ? "是" : "否"}</p>
<p>{app.state.version}</p>
<p>{app.state.hasUpdate ? "有" : "无"}</p>
<p>{app.state.inited ? "是" : "否"}</p>
<p>{app.state.notice}</p>
<p>使{app.state.useMirror ? "是" : "否"}</p>
</div>
)
}

View File

@@ -1,18 +1,16 @@
"use client"
import { currentUser, steamStore } from "@/store/steam"
import { useSnapshot } from "valtio"
import { useSteamStore } from "@/store/steam"
export default function Page() {
void steamStore.start()
const steam = useSnapshot(steamStore.state)
const steam = useSteamStore()
return (
<div className="flex flex-col items-start gap-3 pt-2 pb-1">
<p>Steam路径{steam.dir}</p>
<p>{steam.csDir}</p>
<p>Steam路径有效{steam.isDirValid ? "是" : "否"}</p>
<p>{steam.isCsDirValid ? "是" : "否"}</p>
<p>Steam账号{currentUser().accountName}</p>
<p>Steam路径{steam.state.dir}</p>
<p>{steam.state.csDir}</p>
<p>Steam路径有效{steam.state.isDirValid ? "是" : "否"}</p>
<p>{steam.state.isCsDirValid ? "是" : "否"}</p>
<p>Steam账号{steam.currentUser().accountName}</p>
</div>
)
}

View File

@@ -1,18 +1,16 @@
"use client"
import { currentUser, setCsDir, setDir, steamStore } from "@/store/steam"
import { useSteamStore } from "@/store/steam"
import { useEffect, useState } from "react"
import { useSnapshot } from "valtio"
export default function Page() {
void steamStore.start()
const steam = useSnapshot(steamStore.state)
const [steamDir, setSteamDir] = useState(steam.dir)
const [cs2Dir, setCs2Dir] = useState(steam.csDir)
const steam = useSteamStore()
const [steamDir, setSteamDir] = useState(steam.state.dir)
const [cs2Dir, setCs2Dir] = useState(steam.state.csDir)
useEffect(() => {
setSteamDir(steam.dir)
setCs2Dir(steam.csDir)
}, [steam.dir, steam.csDir])
setSteamDir(steam.state.dir)
setCs2Dir(steam.state.csDir)
}, [steam.state.dir, steam.state.csDir])
return (
<div
@@ -29,7 +27,7 @@ export default function Page() {
value={steamDir}
onChange={(e) => {
setSteamDir(e.target.value)
setDir(e.target.value)
steam.setDir(e.target.value)
}}
/>
<p>CS2所在文件夹</p>
@@ -38,10 +36,10 @@ export default function Page() {
value={cs2Dir}
onChange={(e) => {
setCs2Dir(e.target.value)
setCsDir(e.target.value)
steam.setCsDir(e.target.value)
}}
/>
<p>64SteamID{currentUser().steamID64}</p>
<p>64SteamID{steam.currentUser().steamID64}</p>
</div>
</div>
)