From 8145b128ad22ee9fff7841a4c234018529c75d3c Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Tue, 20 Sep 2022 14:03:52 -0700 Subject: [PATCH] Move recommended contracts to own widget (#896) --- web/pages/[username]/[contractSlug].tsx | 47 +++++++++++++------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index a0b2ed50..84cc271a 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -205,18 +205,6 @@ export function ContractPageContent( setShowConfetti(shouldSeeConfetti) }, [contract, user]) - const [recommendedContracts, setRecommendedContracts] = useState( - [] - ) - useEffect(() => { - if (contract && user) { - getRecommendedContracts(contract, user.id, 6).then( - setRecommendedContracts - ) - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [contract.id, user?.id]) - const { isResolved, question, outcomeType } = contract const allowTrade = tradingAllowed(contract) @@ -301,16 +289,31 @@ export function ContractPageContent( comments={comments} /> - - {recommendedContracts.length > 0 && ( - - - <ContractsGrid - contracts={recommendedContracts} - trackingPostfix=" recommended" - /> - </Col> - )} + <RecommendedContractsWidget contract={contract} /> </Page> ) } + +function RecommendedContractsWidget(props: { contract: Contract }) { + const { contract } = props + const user = useUser() + const [recommendations, setRecommendations] = useState<Contract[]>([]) + useEffect(() => { + if (user) { + getRecommendedContracts(contract, user.id, 6).then(setRecommendations) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [contract.id, user?.id]) + if (recommendations.length === 0) { + return null + } + return ( + <Col className="mt-2 gap-2 px-2 sm:px-0"> + <Title className="text-gray-700" text="Recommended" /> + <ContractsGrid + contracts={recommendations} + trackingPostfix=" recommended" + /> + </Col> + ) +}