Fixes according to James's review

This commit is contained in:
Austin Chen 2022-03-08 18:39:08 -08:00
parent 5182f69477
commit a4ed4af3cf
3 changed files with 6 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
type PropzProps = { type PropzProps = {
// Params from the router query
params: any params: any
} }
@ -12,9 +13,7 @@ type PropzProps = {
// TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/ // TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/
export function usePropz( export function usePropz(
initialProps: Object, initialProps: Object,
getStaticPropz: (props: PropzProps) => Promise<any>, getStaticPropz: (props: PropzProps) => Promise<any>
// Dynamic routes will need the query params from the router
needParams?: boolean
) { ) {
// If props were successfully server-side generated, just use those // If props were successfully server-side generated, just use those
if (!_.isEmpty(initialProps)) { if (!_.isEmpty(initialProps)) {
@ -27,10 +26,9 @@ export function usePropz(
const [propz, setPropz] = useState<any>(undefined) const [propz, setPropz] = useState<any>(undefined)
useEffect(() => { useEffect(() => {
if (needParams && _.isEmpty(params)) { if (router.isReady) {
return getStaticPropz({ params }).then((result) => setPropz(result.props))
} }
getStaticPropz({ params }).then((result) => setPropz(result.props))
}, [params]) }, [params])
return propz return propz
} }

View File

@ -79,7 +79,7 @@ export default function ContractPage(props: {
slug: string slug: string
folds: Fold[] folds: Fold[]
}) { }) {
props = usePropz(props, getStaticPropz, true) ?? { props = usePropz(props, getStaticPropz) ?? {
contract: null, contract: null,
username: '', username: '',
comments: [], comments: [],

View File

@ -118,7 +118,7 @@ export default function FoldPage(props: {
creatorScores: { [userId: string]: number } creatorScores: { [userId: string]: number }
topCreators: User[] topCreators: User[]
}) { }) {
props = usePropz(props, getStaticPropz, true) ?? { props = usePropz(props, getStaticPropz) ?? {
fold: null, fold: null,
curator: null, curator: null,
contracts: [], contracts: [],