change to bool
This commit is contained in:
@@ -95,7 +95,7 @@ export const schema = z.object({
|
||||
isClip: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
usedStarterPacks: z.array(z.string()).optional(),
|
||||
hasCheckedForStarterPack: z.boolean().optional(),
|
||||
})
|
||||
export type Schema = z.infer<typeof schema>
|
||||
|
||||
@@ -135,5 +135,5 @@ export const defaults: Schema = {
|
||||
disableAutoplay: prefersReducedMotion,
|
||||
kawaii: false,
|
||||
currentStarterPack: undefined,
|
||||
usedStarterPacks: [],
|
||||
hasCheckedForStarterPack: false,
|
||||
}
|
||||
|
||||
@@ -2,25 +2,25 @@ import React from 'react'
|
||||
|
||||
import * as persisted from '#/state/persisted'
|
||||
|
||||
type StateContext = string[] | undefined
|
||||
type SetContext = (v: string) => void
|
||||
type StateContext = boolean | undefined
|
||||
type SetContext = (v: boolean) => void
|
||||
|
||||
const stateContext = React.createContext<StateContext>([])
|
||||
const setContext = React.createContext<SetContext>((_: string) => {})
|
||||
const stateContext = React.createContext<StateContext>(false)
|
||||
const setContext = React.createContext<SetContext>((_: boolean) => {})
|
||||
|
||||
export function Provider({children}: {children: React.ReactNode}) {
|
||||
const [state, setState] = React.useState<StateContext>(() =>
|
||||
persisted.get('usedStarterPacks'),
|
||||
persisted.get('hasCheckedForStarterPack'),
|
||||
)
|
||||
|
||||
const setStateWrapped = (v: string) => {
|
||||
persisted.write('usedStarterPacks', [...(state ? state : []), v])
|
||||
setState(prev => [...(prev ? prev : []), v])
|
||||
const setStateWrapped = (v: boolean) => {
|
||||
setState(v)
|
||||
persisted.write('hasCheckedForStarterPack', v)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
return persisted.onUpdate(() => {
|
||||
setState(persisted.get('usedStarterPacks'))
|
||||
setState(persisted.get('hasCheckedForStarterPack'))
|
||||
})
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user