From 0617fedb178eb995be248938bfdb0e505943a5aa Mon Sep 17 00:00:00 2001 From: jahooma Date: Sat, 22 Jan 2022 11:39:31 -0600 Subject: [PATCH] Add /markets for fold --- web/components/fold-back.tsx | 14 +++++++ web/lib/firebase/folds.ts | 5 ++- web/pages/fold/[foldSlug]/index.tsx | 20 +++++---- web/pages/fold/[foldSlug]/markets.tsx | 59 +++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 web/components/fold-back.tsx create mode 100644 web/pages/fold/[foldSlug]/markets.tsx diff --git a/web/components/fold-back.tsx b/web/components/fold-back.tsx new file mode 100644 index 00000000..374e13e3 --- /dev/null +++ b/web/components/fold-back.tsx @@ -0,0 +1,14 @@ +import { ArrowCircleLeftIcon } from '@heroicons/react/outline' +import { Fold } from '../../common/fold' +import { foldPath } from '../lib/firebase/folds' +import { SiteLink } from './site-link' + +export function FoldBack(props: { fold: Fold }) { + const { fold } = props + return ( + + {' '} + {fold.name} + + ) +} diff --git a/web/lib/firebase/folds.ts b/web/lib/firebase/folds.ts index f1da0444..2e64b1d8 100644 --- a/web/lib/firebase/folds.ts +++ b/web/lib/firebase/folds.ts @@ -6,7 +6,10 @@ import { getValues } from './utils' const foldCollection = collection(db, 'folds') -export function foldPath(fold: Fold, subpath?: 'edit' | 'leaderboards') { +export function foldPath( + fold: Fold, + subpath?: 'edit' | 'markets' | 'leaderboards' +) { return `/fold/${fold.slug}${subpath ? `/${subpath}` : ''}` } diff --git a/web/pages/fold/[foldSlug]/index.tsx b/web/pages/fold/[foldSlug]/index.tsx index 07408fec..647000e8 100644 --- a/web/pages/fold/[foldSlug]/index.tsx +++ b/web/pages/fold/[foldSlug]/index.tsx @@ -90,14 +90,10 @@ export default function FoldPage(props: { <Row className="items-center gap-2 mb-2 flex-wrap"> - {isCurator && ( - <> - <SiteLink className="text-sm " href={foldPath(fold, 'edit')}> - Edit - </SiteLink> - <div className="text-gray-500">•</div> - </> - )} + <SiteLink className="text-sm" href={foldPath(fold, 'markets')}> + Markets + </SiteLink> + <div className="text-gray-500">•</div> <SiteLink className="text-sm" href={foldPath(fold, 'leaderboards')}> Leaderboards </SiteLink> @@ -110,6 +106,14 @@ export default function FoldPage(props: { username={curator.username} /> </Row> + {isCurator && ( + <> + <div className="text-gray-500">•</div> + <SiteLink className="text-sm " href={foldPath(fold, 'edit')}> + Edit + </SiteLink> + </> + )} </Row> <TagsList tags={tags.map((tag) => `#${tag}`)} /> diff --git a/web/pages/fold/[foldSlug]/markets.tsx b/web/pages/fold/[foldSlug]/markets.tsx new file mode 100644 index 00000000..667cb68a --- /dev/null +++ b/web/pages/fold/[foldSlug]/markets.tsx @@ -0,0 +1,59 @@ +import _ from 'lodash' +import { Contract } from '../../../../common/contract' +import { Fold } from '../../../../common/fold' +import { SearchableGrid } from '../../../components/contracts-list' +import { FoldBack } from '../../../components/fold-back' +import { Spacer } from '../../../components/layout/spacer' +import { Page } from '../../../components/page' +import { SEO } from '../../../components/SEO' +import { useQueryAndSortParams } from '../../../hooks/use-sort-and-query-params' +import { getFoldBySlug, getFoldContracts } from '../../../lib/firebase/folds' + +export async function getStaticProps(props: { params: { foldSlug: string } }) { + const { foldSlug } = props.params + + const fold = await getFoldBySlug(foldSlug) + const contracts = fold ? await getFoldContracts(fold) : [] + + return { + props: { + fold, + contracts, + }, + + revalidate: 60, // regenerate after a minute + } +} + +export async function getStaticPaths() { + return { paths: [], fallback: 'blocking' } +} + +export default function Markets(props: { fold: Fold; contracts: Contract[] }) { + const { fold, contracts } = props + const { query, setQuery, sort, setSort } = useQueryAndSortParams({ + defaultSort: 'most-traded', + }) + + return ( + <Page> + <SEO + title={`${fold.name}'s markets`} + description={`Explore or search all the markets of ${fold.name}`} + url="/markets" + /> + + <FoldBack fold={fold} /> + + <Spacer h={4} /> + + <SearchableGrid + contracts={contracts} + query={query} + setQuery={setQuery} + sort={sort} + setSort={setSort} + /> + </Page> + ) +}