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