From e7f369e2b4afe9041a1112f9c4a4857a8a09992e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 27 Aug 2022 21:40:22 -0500 Subject: [PATCH] Load recommended markets even when navigating from home --- web/pages/[username]/[contractSlug].tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index d70f711b..026597e3 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -154,7 +154,7 @@ export function ContractPageContent( user?: User | null } ) { - const { backToHome, comments, user, recommendedContracts } = props + const { backToHome, comments, user } = props const contract = useContractWithPreload(props.contract) ?? props.contract @@ -186,6 +186,17 @@ export function ContractPageContent( setShowConfetti(shouldSeeConfetti) }, [contract, user]) + const [recommendedContracts, setRecommendedMarkets] = useState( + props.recommendedContracts + ) + useEffect(() => { + if (recommendedContracts.length === 0) { + getRandTopCreatorContracts(contract.creatorId, 4, [contract.id]).then( + setRecommendedMarkets + ) + } + }, [contract.id, contract.creatorId, recommendedContracts]) + const { isResolved, question, outcomeType } = contract const allowTrade = tradingAllowed(contract)