da4ce99755
* Add dev target for TheoremOne * Restrict signups to theoremone.co emails * Add new indices * Forbid reads from unauthenticated users * Client-side render pages that need auth These pages are now client-side rendered: - /home - /leaderboards - /market/... - /fold/... * Hide 404 for private Manifolds * Brand instance for TheoremOne * Hide "Add Funds" and "Personalize your feed" * "M$" => "T$" * Hide Discord & About Page too * Update placeholders for teams * Update firestore.indexes.json * Switch /analytics to propz * Migrate per-env code into common/ * More migrations to PROJECT_ID * Conditionally use SSG depending on public vs private instance * Fix props to be empty object * Move more logic into access * Spin out config files for each environment * Generify most of the customizable brand stuff * Move IS_PRIVATE_MANIFOLD to access.ts * Rename access.ts to envs/constants.ts * Add "dev:dev" alias * Rever firestore rules to existing settings * Fixes according to James's review
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import _ from 'lodash'
|
|
import { useRouter } from 'next/router'
|
|
import { useState, useEffect } from 'react'
|
|
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
|
|
|
|
type PropzProps = {
|
|
// Params from the router query
|
|
params: any
|
|
}
|
|
|
|
// getStaticPropz should exactly match getStaticProps
|
|
// 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(
|
|
initialProps: Object,
|
|
getStaticPropz: (props: PropzProps) => Promise<any>
|
|
) {
|
|
// If props were successfully server-side generated, just use those
|
|
if (!_.isEmpty(initialProps)) {
|
|
return initialProps
|
|
}
|
|
|
|
// Otherwise, get params from router
|
|
const router = useRouter()
|
|
const params = router.query
|
|
|
|
const [propz, setPropz] = useState<any>(undefined)
|
|
useEffect(() => {
|
|
if (router.isReady) {
|
|
getStaticPropz({ params }).then((result) => setPropz(result.props))
|
|
}
|
|
}, [params])
|
|
return propz
|
|
}
|
|
|
|
// Conditionally disable SSG for private Manifold instances
|
|
export function fromPropz(getStaticPropz: (props: PropzProps) => Promise<any>) {
|
|
return IS_PRIVATE_MANIFOLD ? async () => ({ props: {} }) : getStaticPropz
|
|
}
|