[Statsig] Typecheck gates (#3467)

* Typecheck gates

* Lint against untyped useGate()

* Alphabetic
This commit is contained in:
dan 2024-04-10 19:36:37 +01:00 committed by GitHub
parent bf974b147e
commit 427f3a848d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 45 additions and 6 deletions

View file

@ -1,3 +1,8 @@
import {useGate} from './statsig'
export const useNewSearchGate = () => useGate('new_search')
export type Gate =
// Keep this alphabetic please.
| 'autoexpand_suggestions_on_profile_follow'
| 'disable_min_shell_on_foregrounding'
| 'disable_poll_on_discover'
| 'new_search'
| 'show_follow_back_label'
| 'start_session_with_following'

View file

@ -11,6 +11,7 @@ import {
import {logger} from '#/logger'
import {useSession} from '../../state/session'
import {LogEvents} from './events'
import {Gate} from './gates'
export type {LogEvents}
@ -69,7 +70,7 @@ export function logEvent<E extends keyof LogEvents>(
}
}
export function useGate(gateName: string) {
export function useGate(gateName: Gate): boolean {
const {isLoading, value} = useStatsigGate(gateName)
if (isLoading) {
// This should not happen because of waitForInitialization={true}.

View file

@ -22,7 +22,7 @@ import {HITSLOP_10} from '#/lib/constants'
import {usePalette} from '#/lib/hooks/usePalette'
import {MagnifyingGlassIcon} from '#/lib/icons'
import {NavigationProp} from '#/lib/routes/types'
import {useNewSearchGate} from '#/lib/statsig/gates'
import {useGate} from '#/lib/statsig/statsig'
import {augmentSearchQuery} from '#/lib/strings/helpers'
import {s} from '#/lib/styles'
import {logger} from '#/logger'
@ -337,7 +337,7 @@ export function SearchScreenInner({
const {isDesktop} = useWebMediaQueries()
const {_} = useLingui()
const isNewSearch = useNewSearchGate()
const isNewSearch = useGate('new_search')
const onPageSelected = React.useCallback(
(index: number) => {