From a4ed4af3cf4522bb8984479a56c8422225617ac6 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 8 Mar 2022 18:39:08 -0800 Subject: [PATCH] Fixes according to James's review --- web/hooks/use-propz.ts | 10 ++++------ web/pages/[username]/[contractSlug].tsx | 2 +- web/pages/fold/[...slugs]/index.tsx | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/web/hooks/use-propz.ts b/web/hooks/use-propz.ts index 16315929..5aee4c61 100644 --- a/web/hooks/use-propz.ts +++ b/web/hooks/use-propz.ts @@ -4,6 +4,7 @@ import { useState, useEffect } from 'react' import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' type PropzProps = { + // Params from the router query params: any } @@ -12,9 +13,7 @@ type PropzProps = { // TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/ export function usePropz( initialProps: Object, - getStaticPropz: (props: PropzProps) => Promise, - // Dynamic routes will need the query params from the router - needParams?: boolean + getStaticPropz: (props: PropzProps) => Promise ) { // If props were successfully server-side generated, just use those if (!_.isEmpty(initialProps)) { @@ -27,10 +26,9 @@ export function usePropz( const [propz, setPropz] = useState(undefined) useEffect(() => { - if (needParams && _.isEmpty(params)) { - return + if (router.isReady) { + getStaticPropz({ params }).then((result) => setPropz(result.props)) } - getStaticPropz({ params }).then((result) => setPropz(result.props)) }, [params]) return propz } diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 39142378..ea985f81 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -79,7 +79,7 @@ export default function ContractPage(props: { slug: string folds: Fold[] }) { - props = usePropz(props, getStaticPropz, true) ?? { + props = usePropz(props, getStaticPropz) ?? { contract: null, username: '', comments: [], diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index 6f27c3de..03808d39 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -118,7 +118,7 @@ export default function FoldPage(props: { creatorScores: { [userId: string]: number } topCreators: User[] }) { - props = usePropz(props, getStaticPropz, true) ?? { + props = usePropz(props, getStaticPropz) ?? { fold: null, curator: null, contracts: [],