Conditionally use SSG depending on public vs private instance
This commit is contained in:
		
							parent
							
								
									ae63f70a30
								
							
						
					
					
						commit
						dc29ca531c
					
				|  | @ -1,6 +1,7 @@ | |||
| import _ from 'lodash' | ||||
| import { useRouter } from 'next/router' | ||||
| import { useState, useEffect } from 'react' | ||||
| import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' | ||||
| 
 | ||||
| type PropzProps = { | ||||
|   params: any | ||||
|  | @ -10,7 +11,7 @@ type PropzProps = { | |||
| // This allows us to client-side render the page for authenticated users.
 | ||||
| // TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/
 | ||||
| export function usePropz( | ||||
|   getStaticPropz: (props?: PropzProps) => Promise<any>, | ||||
|   getStaticPropz: (props: PropzProps) => Promise<any>, | ||||
|   // Dynamic routes will need the query params from the router
 | ||||
|   needParams?: boolean | ||||
| ) { | ||||
|  | @ -23,8 +24,11 @@ export function usePropz( | |||
|     if (needParams && _.isEmpty(params)) { | ||||
|       return | ||||
|     } | ||||
|     // @ts-ignore
 | ||||
|     getStaticPropz({ params }).then((result) => setPropz(result.props)) | ||||
|   }, [params]) | ||||
|   return propz | ||||
| } | ||||
| 
 | ||||
| export function fromPropz(getStaticPropz: (props: PropzProps) => Promise<any>) { | ||||
|   return IS_PRIVATE_MANIFOLD ? async () => {} : getStaticPropz | ||||
| } | ||||
|  |  | |||
|  | @ -29,8 +29,9 @@ import { useFoldsWithTags } from '../../hooks/use-fold' | |||
| import { listAllAnswers } from '../../lib/firebase/answers' | ||||
| import { Answer } from '../../../common/answer' | ||||
| import { AnswersPanel } from '../../components/answers/answers-panel' | ||||
| import { usePropz } from '../../hooks/use-propz' | ||||
| import { fromPropz, usePropz } from '../../hooks/use-propz' | ||||
| 
 | ||||
| export const getStaticProps = fromPropz(getStaticPropz) | ||||
| export async function getStaticPropz(props: { | ||||
|   params: { username: string; contractSlug: string } | ||||
| }) { | ||||
|  | @ -65,7 +66,7 @@ export async function getStaticPropz(props: { | |||
|   } | ||||
| } | ||||
| 
 | ||||
| export async function getStaticPathz() { | ||||
| export async function getStaticPaths() { | ||||
|   return { paths: [], fallback: 'blocking' } | ||||
| } | ||||
| 
 | ||||
|  | @ -78,16 +79,16 @@ export default function ContractPage(props: { | |||
|   slug: string | ||||
|   folds: Fold[] | ||||
| }) { | ||||
|   // @ts-ignore
 | ||||
|   props = usePropz(getStaticPropz, true) ?? { | ||||
|     contract: null, | ||||
|     username: '', | ||||
|     comments: [], | ||||
|     answers: [], | ||||
|     bets: [], | ||||
|     slug: '', | ||||
|     folds: [], | ||||
|   } | ||||
|   props = props ?? | ||||
|     usePropz(getStaticPropz, true) ?? { | ||||
|       contract: null, | ||||
|       username: '', | ||||
|       comments: [], | ||||
|       answers: [], | ||||
|       bets: [], | ||||
|       slug: '', | ||||
|       folds: [], | ||||
|     } | ||||
|   const user = useUser() | ||||
| 
 | ||||
|   const contract = useContractWithPreload(props.slug, props.contract) | ||||
|  |  | |||
|  | @ -22,12 +22,13 @@ import { | |||
|   useFilterYourContracts, | ||||
|   useFindActiveContracts, | ||||
| } from '../hooks/use-find-active-contracts' | ||||
| import { usePropz } from '../hooks/use-propz' | ||||
| import { fromPropz, usePropz } from '../hooks/use-propz' | ||||
| import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' | ||||
| import { useGetRecentBets, useRecentBets } from '../hooks/use-bets' | ||||
| import { useActiveContracts } from '../hooks/use-contracts' | ||||
| import { useRecentComments } from '../hooks/use-comments' | ||||
| 
 | ||||
| export const getStaticProps = fromPropz(getStaticPropz) | ||||
| export async function getStaticPropz() { | ||||
|   const contractInfo = await getAllContractInfo() | ||||
| 
 | ||||
|  | @ -42,11 +43,12 @@ const Home = (props: { | |||
|   folds: Fold[] | ||||
|   recentComments: Comment[] | ||||
| }) => { | ||||
|   props = usePropz(getStaticPropz) ?? { | ||||
|     contracts: [], | ||||
|     folds: [], | ||||
|     recentComments: [], | ||||
|   } | ||||
|   props = props ?? | ||||
|     usePropz(getStaticPropz) ?? { | ||||
|       contracts: [], | ||||
|       folds: [], | ||||
|       recentComments: [], | ||||
|     } | ||||
|   const { folds } = props | ||||
|   const user = useUser() | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user