Remove unnecessary cruft from contract page props

This commit is contained in:
Marshall Polaris 2022-09-20 21:21:23 -07:00
parent 240c94a1d1
commit 68c2a73950
2 changed files with 4 additions and 20 deletions

View File

@ -54,7 +54,7 @@ export const getStaticProps = fromPropz(getStaticPropz)
export async function getStaticPropz(props: {
params: { username: string; contractSlug: string }
}) {
const { username, contractSlug } = props.params
const { contractSlug } = props.params
const contract = (await getContractFromSlug(contractSlug)) || null
const contractId = contract?.id
@ -66,8 +66,6 @@ export async function getStaticPropz(props: {
return {
props: {
contract,
username,
slug: contractSlug,
// Limit the data sent to the client. Client will still load all bets and comments directly.
bets: bets.slice(0, 5000),
comments: comments.slice(0, 1000),
@ -83,18 +81,14 @@ export async function getStaticPaths() {
export default function ContractPage(props: {
contract: Contract | null
username: string
bets: Bet[]
comments: ContractComment[]
slug: string
backToHome?: () => void
}) {
props = usePropz(props, getStaticPropz) ?? {
contract: null,
username: '',
comments: [],
bets: [],
slug: '',
}
const user = useUser()
@ -228,7 +222,7 @@ export function ContractPageContent(
<SEO
title={question}
description={ogCardProps.description}
url={`/${props.username}/${props.slug}`}
url={`/${contract.creatorUsername}/${contract.slug}`}
ogCardProps={ogCardProps}
/>
)}

View File

@ -34,20 +34,14 @@ export const getStaticProps = fromPropz(getStaticPropz)
export async function getStaticPropz(props: {
params: { username: string; contractSlug: string }
}) {
const { username, contractSlug } = props.params
const { contractSlug } = props.params
const contract = (await getContractFromSlug(contractSlug)) || null
const contractId = contract?.id
const bets = contractId ? await listAllBets(contractId) : []
return {
props: {
contract,
username,
slug: contractSlug,
bets,
},
props: { contract, bets },
revalidate: 60, // regenerate after a minute
}
}
@ -58,15 +52,11 @@ export async function getStaticPaths() {
export default function ContractEmbedPage(props: {
contract: Contract | null
username: string
bets: Bet[]
slug: string
}) {
props = usePropz(props, getStaticPropz) ?? {
contract: null,
username: '',
bets: [],
slug: '',
}
const contract = useContractWithPreload(props.contract)