Sketch cleanup
This commit is contained in:
@@ -1,21 +1,12 @@
|
||||
export enum Group {
|
||||
Wayfinding = 'wayfinding',
|
||||
Composer = 'composer',
|
||||
}
|
||||
/**
|
||||
* NEVER CHANGE THE ORDER OF THIS MAP, the compression step depends on the
|
||||
* other of the keys!
|
||||
*/
|
||||
export const flags = {
|
||||
newThreadgate: false,
|
||||
activitySubscriptionAlert: false,
|
||||
} as const
|
||||
|
||||
export type Flags = {
|
||||
'wayfinding:settings': boolean
|
||||
'wayfinding:settings:moderation': boolean
|
||||
'composer:threadgate_20250204': boolean
|
||||
}
|
||||
|
||||
export type Flag = keyof Flags
|
||||
|
||||
// existing users?
|
||||
export const flags: Flags = {
|
||||
'wayfinding:settings': true,
|
||||
'wayfinding:settings:moderation': true,
|
||||
'composer:threadgate_20250204': false,
|
||||
}
|
||||
export type Flag = keyof typeof flags
|
||||
|
||||
export const flagKeys = Object.keys(flags) as (keyof typeof flags)[]
|
||||
|
||||
@@ -1,36 +1,37 @@
|
||||
import {useMemo, useCallback} from 'react'
|
||||
import {useCallback, useMemo} from 'react'
|
||||
|
||||
import {flags, flagKeys, Flag} from '#/state/queries/nudges/flags'
|
||||
import {pack, unpack} from '#/state/queries/nudges/compression'
|
||||
|
||||
const TEST = pack(flags)
|
||||
import {type Flag, flagKeys, flags} from '#/state/queries/nudges/flags'
|
||||
|
||||
export function useNudges() {
|
||||
const data = TEST // TODO
|
||||
const data = pack(flags) // TODO fetch from API
|
||||
|
||||
return useMemo(() => {
|
||||
return data ? unpack(data, flagKeys) : flags
|
||||
}, [data])
|
||||
}
|
||||
|
||||
export function useNudgesGroup() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
export function useNudge(flag: Flag) {
|
||||
const nudges = useNudges()
|
||||
const nudge = nudges[flag]
|
||||
|
||||
const complete = useCallback(() => {
|
||||
const next = {...nudges}
|
||||
next[flag] = true
|
||||
const data = pack(next)
|
||||
// TODO update
|
||||
}, [nudge])
|
||||
pack(next) // TODO write to API
|
||||
}, [flag, nudges])
|
||||
|
||||
const reset = useCallback(() => {
|
||||
const next = {...nudges}
|
||||
next[flag] = false
|
||||
const data = pack(next)
|
||||
// TODO update
|
||||
}, [nudge])
|
||||
return useMemo(() => ({
|
||||
}), [nudge, complete, reset])
|
||||
pack(next) // TODO write to API
|
||||
}, [flag, nudges])
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
nudge: nudges[flag],
|
||||
complete,
|
||||
reset,
|
||||
}),
|
||||
[flag, nudges, complete, reset],
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user