update: game core flow pages

This commit is contained in:
Vick Scarlet
2026-08-16 20:06:16 +08:00
committed by 神戸小鳥
parent 25bd9ce2b7
commit 0c0fac5bfd
34 changed files with 890 additions and 768 deletions
+21 -21
View File
@@ -1,6 +1,6 @@
import { useCallback, useTransition } from 'react'
import { useCallback } from 'react'
import { atom, useAtom } from 'jotai'
import { useConfigInject, useProfile, useProfileInject } from '@remake/hooks'
import { useConfigInject, useRawProfile, useProfileInject } from '@remake/hooks'
import { get, set } from '@/storage'
import { config } from '@/config'
@@ -10,35 +10,35 @@ export const useInit = () => {
const configInject = useConfigInject()
const profileInject = useProfileInject()
const [inited, setInited] = useAtom(initedAtom)
const [_, startTransition] = useTransition()
const loader = useCallback(() => {
const loader = useCallback(async () => {
if (inited) return
configInject(config)
startTransition(async () => {
const { profile } = await get(['profile'])
const parsed = profile ? JSON.parse(profile) || {} : {}
profileInject({
...parsed,
times: parsed.times || 0,
achievements: new Set(parsed.achievements || []),
events: new Set(parsed.events || []),
talents: new Set(parsed.talents || []),
})
setInited(true)
const { profile } = await get(['profile'])
const parsed = profile ? JSON.parse(profile) || {} : {}
profileInject({
...parsed,
times: parsed.times || 0,
achievements: new Set(parsed.achievements || []),
events: new Set(parsed.events || []),
talents: new Set(parsed.talents || []),
})
}, [])
setInited(true)
}, [inited, configInject, profileInject, setInited])
return [inited, loader] as const
}
export const useSaver = () => {
const [profile] = useProfile()
const saver = useCallback(() => {
const [profile] = useRawProfile()
const [inited] = useAtom(initedAtom)
return useCallback(async () => {
if (!inited || !profile) return
const str = JSON.stringify({
...profile,
times: profile.times,
achievements: Array.from(profile.achievements),
events: Array.from(profile.events),
talents: Array.from(profile.talents),
})
set({ profile: str })
}, [profile])
return saver
return await set({ profile: str })
}, [inited, profile])
}