Skip to content

Commit

Permalink
Actually persist sweeps state
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Sep 24, 2024
1 parent 9e6ec70 commit 8d62427
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 7 additions & 3 deletions web/components/search/contract-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -107,8 +110,9 @@ export function ContractFilters(props: {
}

const toggleSweepies = () => {
setIsPlay(isSweeps)
updateParams({
sw: isSweepiesString == '1' ? '0' : '1',
sw: isSweeps ? '0' : '1',
})
}

Expand Down Expand Up @@ -154,14 +158,14 @@ export function ContractFilters(props: {
</IconButton>
{TWOMBA_ENABLED && (
<FilterPill
selected={isSweepiesString === '1'}
selected={isSweeps}
onSelect={toggleSweepies}
type="sweepies"
>
<Row
className={clsx(
'items-center gap-1',
isSweepiesString != '1' ? 'opacity-50' : 'opacity-100'
isSweeps ? 'opacity-100' : 'opacity-50'
)}
>
<SweepiesCoin />
Expand Down
9 changes: 6 additions & 3 deletions web/components/supabase-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ export function SupabaseSearch(props: {

const isMobile = useIsMobile()
const { isPlay, setIsPlay } = useSweepstakes()

const [searchParams, setSearchParams, isReady] = useSearchQueryState({
defaultSort,
defaultFilter,
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions web/components/sweestakes-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ const SweepstakesContext = createContext<SweepstakesContextType | undefined>(
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 (
<SweepstakesContext.Provider value={{ isPlay, setIsPlay }}>
{children}
Expand Down

0 comments on commit 8d62427

Please sign in to comment.