Skip to content

Commit

Permalink
Sync sweep filter <-> context <-> play query
Browse files Browse the repository at this point in the history
Resolves MAN-1710, MAN-1702
  • Loading branch information
sipec committed Sep 20, 2024
1 parent 0845a91 commit 92a784f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions web/components/contract/twomba-contract-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ export function TwombaContractPageContent(props: ContractParams) {
cash,
} = props

// sync query state with context
const { isPlay, setIsPlay } = useSweepstakes()
const router = useRouter()
useEffect(() => {
if (router.isReady) {
setIsPlay(router.query.play !== 'false')
}
}, [router.isReady])
useEffect(() => {
router.replace(
{ query: { ...router.query, play: isPlay ? 'true' : 'false' } },
undefined,
{ shallow: true }
)
}, [isPlay])

const livePlayContract = useLiveContractWithAnswers(props.contract)
const liveCashContract = props.cash
Expand Down
7 changes: 7 additions & 0 deletions web/components/supabase-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { LoadMoreUntilNotVisible } from './widgets/visibility-observer'
import { BinaryDigit, TierParamsType } from 'common/tier'
import { useIsMobile } from 'web/hooks/use-is-mobile'
import { Spacer } from './layout/spacer'
import { useSweepstakes } from './sweestakes-context'

const USERS_PER_PAGE = 100
const TOPICS_PER_PAGE = 100
Expand Down Expand Up @@ -237,6 +238,7 @@ export function SupabaseSearch(props: {
} = props

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

const [searchParams, setSearchParams, isReady] = useSearchQueryState({
defaultSort,
Expand All @@ -246,6 +248,7 @@ export function SupabaseSearch(props: {
defaultForYou,
useUrlParams,
persistPrefix,
defaultSweepies: isPlay ? '0' : '1',
})

const query = searchParams[QUERY_KEY]
Expand All @@ -260,6 +263,10 @@ export function SupabaseSearch(props: {
const marketTiers = searchParams[MARKET_TIER_KEY]
const topicFilter = searchParams[TOPIC_FILTER_KEY]

useEffect(() => {
if (isWholePage) setIsPlay(sweepiesState === '0')
}, [isWholePage, sweepiesState])

const [userResults, setUserResults] = usePersistentInMemoryState<
FullUser[] | undefined
>(undefined, `${persistPrefix}-queried-user-results`)
Expand Down

0 comments on commit 92a784f

Please sign in to comment.