import clsx from 'clsx' import _ from 'lodash' import { useRouter } from 'next/router' import { useState } from 'react' import { Fold } from '../../common/fold' import { parseWordsAsTags } from '../../common/util/parse' import { ConfirmationButton } from '../components/confirmation-button' import { Col } from '../components/layout/col' import { Row } from '../components/layout/row' import { Spacer } from '../components/layout/spacer' import { Page } from '../components/page' import { SiteLink } from '../components/site-link' import { TagsList } from '../components/tags-list' import { Title } from '../components/title' import { UserLink } from '../components/user-page' import { useUser } from '../hooks/use-user' import { createFold } from '../lib/firebase/api-call' import { foldPath, listAllFolds } from '../lib/firebase/folds' import { getUser, User } from '../lib/firebase/users' export async function getStaticProps() { const folds = await listAllFolds().catch((_) => []) const curators = await Promise.all( folds.map((fold) => getUser(fold.curatorId)) ) return { props: { folds, curators, }, revalidate: 60, // regenerate after a minute } } export default function Folds(props: { folds: Fold[]; curators: User[] }) { const { folds, curators } = props const user = useUser() return ( {user && } {folds.map((fold, index) => ( {fold.name} 12 followers • Curated by ))} ) } function CreateFoldButton() { const [name, setName] = useState('') const [tags, setTags] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) const router = useRouter() const onSubmit = async () => { setIsSubmitting(true) const result = await createFold({ name, tags: parseWordsAsTags(tags), }).then((r) => r.data || {}) if (result.fold) await router.push(foldPath(result.fold)) else console.log(result.status, result.message) setIsSubmitting(false) } return ( A fold is a view of markets that match selected tags. You can further include or exclude individual markets. Fold name setName(e.target.value || '')} /> Tags setTags(e.target.value || '')} /> ) }