Get challenge on server
This commit is contained in:
parent
cf653bd567
commit
8db67ad6a4
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
collectionGroup,
|
collectionGroup,
|
||||||
doc,
|
doc,
|
||||||
|
getDoc,
|
||||||
orderBy,
|
orderBy,
|
||||||
query,
|
query,
|
||||||
setDoc,
|
setDoc,
|
||||||
|
@ -130,3 +131,8 @@ export const useUserChallenges = (fromId: string) => {
|
||||||
|
|
||||||
return links
|
return links
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getChallenge = async (slug: string, contractId: string) => {
|
||||||
|
const challenge = await getDoc(doc(challenges(contractId), slug))
|
||||||
|
return challenge.data() as Challenge
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,11 @@ import { Spacer } from 'web/components/layout/spacer'
|
||||||
import { Row } from 'web/components/layout/row'
|
import { Row } from 'web/components/layout/row'
|
||||||
|
|
||||||
import { Challenge } from 'common/challenge'
|
import { Challenge } from 'common/challenge'
|
||||||
import { getChallengeUrl, useChallenge } from 'web/lib/firebase/challenges'
|
import {
|
||||||
|
getChallenge,
|
||||||
|
getChallengeUrl,
|
||||||
|
useChallenge,
|
||||||
|
} from 'web/lib/firebase/challenges'
|
||||||
import { getPortfolioHistory, getUserByUsername } from 'web/lib/firebase/users'
|
import { getPortfolioHistory, getUserByUsername } from 'web/lib/firebase/users'
|
||||||
import { PortfolioMetrics, User } from 'common/user'
|
import { PortfolioMetrics, User } from 'common/user'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
|
@ -45,6 +49,9 @@ export async function getStaticPropz(props: {
|
||||||
const contract = (await getContractFromSlug(contractSlug)) || null
|
const contract = (await getContractFromSlug(contractSlug)) || null
|
||||||
const user = (await getUserByUsername(username)) || null
|
const user = (await getUserByUsername(username)) || null
|
||||||
const bets = contract?.id ? await listAllBets(contract.id) : []
|
const bets = contract?.id ? await listAllBets(contract.id) : []
|
||||||
|
const challenge = contract?.id
|
||||||
|
? await getChallenge(challengeSlug, contract.id)
|
||||||
|
: null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
@ -53,6 +60,7 @@ export async function getStaticPropz(props: {
|
||||||
slug: contractSlug,
|
slug: contractSlug,
|
||||||
challengeSlug,
|
challengeSlug,
|
||||||
bets,
|
bets,
|
||||||
|
challenge,
|
||||||
},
|
},
|
||||||
|
|
||||||
revalidate: 60, // regenerate after a minute
|
revalidate: 60, // regenerate after a minute
|
||||||
|
@ -68,7 +76,7 @@ export default function ChallengePage(props: {
|
||||||
user: User
|
user: User
|
||||||
slug: string
|
slug: string
|
||||||
bets: Bet[]
|
bets: Bet[]
|
||||||
|
challenge: Challenge | null
|
||||||
challengeSlug: string
|
challengeSlug: string
|
||||||
}) {
|
}) {
|
||||||
props = usePropz(props, getStaticPropz) ?? {
|
props = usePropz(props, getStaticPropz) ?? {
|
||||||
|
@ -76,31 +84,17 @@ export default function ChallengePage(props: {
|
||||||
user: null,
|
user: null,
|
||||||
challengeSlug: '',
|
challengeSlug: '',
|
||||||
bets: [],
|
bets: [],
|
||||||
|
challenge: null,
|
||||||
slug: '',
|
slug: '',
|
||||||
}
|
}
|
||||||
const contract = useContractWithPreload(props.contract) ?? props.contract
|
const contract = useContractWithPreload(props.contract) ?? props.contract
|
||||||
const challenge = useChallenge(props.challengeSlug, contract?.id)
|
const challenge =
|
||||||
|
useChallenge(props.challengeSlug, contract?.id) ?? props.challenge
|
||||||
const { user, bets } = props
|
const { user, bets } = props
|
||||||
const currentUser = useUser()
|
const currentUser = useUser()
|
||||||
|
|
||||||
if (!contract) return <Custom404 />
|
if (!contract || !challenge) return <Custom404 />
|
||||||
const ogCardProps = getOpenGraphProps(contract)
|
const ogCardProps = getOpenGraphProps(contract)
|
||||||
if (!challenge) {
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<SEO
|
|
||||||
title={ogCardProps.question}
|
|
||||||
description={ogCardProps.description}
|
|
||||||
// url={getChallengeUrl(challenge)}
|
|
||||||
ogCardProps={ogCardProps}
|
|
||||||
/>
|
|
||||||
<Col className={'min-h-screen items-center justify-center'}>
|
|
||||||
<LoadingIndicator />
|
|
||||||
</Col>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ogCardProps.question =
|
ogCardProps.question =
|
||||||
challenge.creatorName.split(' ')[0] +
|
challenge.creatorName.split(' ')[0] +
|
||||||
|
|
Loading…
Reference in New Issue
Block a user