From 8d624271864ae67854eeb2aa3fba13c823fdc748 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 24 Sep 2024 09:18:07 -0700 Subject: [PATCH] Actually persist sweeps state --- web/components/search/contract-filters.tsx | 10 +++++++--- web/components/supabase-search.tsx | 9 ++++++--- web/components/sweestakes-context.tsx | 8 +------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/web/components/search/contract-filters.tsx b/web/components/search/contract-filters.tsx index d71a6dac8b..dc40317afd 100644 --- a/web/components/search/contract-filters.tsx +++ b/web/components/search/contract-filters.tsx @@ -52,6 +52,7 @@ import { import { LiteGroup } from 'common/group' import { TWOMBA_ENABLED } from 'common/envs/constants' import { SweepiesCoin } from 'web/public/custom-components/sweepiesCoin' +import { useSweepstakes } from '../sweestakes-context' export function ContractFilters(props: { className?: string @@ -71,6 +72,8 @@ export function ContractFilters(props: { tf: topicFilter, sw: isSweepiesString, } = params + const isSweeps = isSweepiesString === '1' + const { setIsPlay } = useSweepstakes() const selectFilter = (selection: Filter) => { if (selection === filter) return @@ -107,8 +110,9 @@ export function ContractFilters(props: { } const toggleSweepies = () => { + setIsPlay(isSweeps) updateParams({ - sw: isSweepiesString == '1' ? '0' : '1', + sw: isSweeps ? '0' : '1', }) } @@ -154,14 +158,14 @@ export function ContractFilters(props: { {TWOMBA_ENABLED && ( diff --git a/web/components/supabase-search.tsx b/web/components/supabase-search.tsx index 353fb7219d..880bf2af91 100644 --- a/web/components/supabase-search.tsx +++ b/web/components/supabase-search.tsx @@ -239,7 +239,6 @@ export function SupabaseSearch(props: { const isMobile = useIsMobile() const { isPlay, setIsPlay } = useSweepstakes() - const [searchParams, setSearchParams, isReady] = useSearchQueryState({ defaultSort, defaultFilter, @@ -264,8 +263,12 @@ export function SupabaseSearch(props: { const topicFilter = searchParams[TOPIC_FILTER_KEY] useEffect(() => { - if (isWholePage) setIsPlay(sweepiesState === '0') - }, [isWholePage, sweepiesState]) + const isSweeps = sweepiesState === '1' + if (isPlay !== isSweeps) return + setSearchParams({ + [SWEEPIES_KEY]: isPlay ? '0' : '1', + }) + }, [isPlay, sweepiesState]) const [userResults, setUserResults] = usePersistentInMemoryState< FullUser[] | undefined diff --git a/web/components/sweestakes-context.tsx b/web/components/sweestakes-context.tsx index c486dc6a9c..1772167d6f 100644 --- a/web/components/sweestakes-context.tsx +++ b/web/components/sweestakes-context.tsx @@ -13,13 +13,7 @@ const SweepstakesContext = createContext( export const SweepstakesProvider: React.FC<{ children: React.ReactNode }> = ({ children, }) => { - const [queryPlay, setQueryPlay] = usePersistentLocalState('play', 'true') - - const isPlay = !queryPlay || queryPlay === 'true' - const setIsPlay = (isPlay: boolean) => { - setQueryPlay(isPlay ? 'true' : 'false') - } - + const [isPlay, setIsPlay] = usePersistentLocalState(false, 'play') return ( {children}