import clsx from 'clsx' import _ from 'lodash' import { ArrowCircleLeftIcon } from '@heroicons/react/solid' import { useState } from 'react' import { Fold } from '../../../../common/fold' import { parseWordsAsTags } from '../../../../common/util/parse' import { Col } from '../../../components/layout/col' import { Spacer } from '../../../components/layout/spacer' import { Page } from '../../../components/page' import { TagsList } from '../../../components/tags-list' import { foldPath, getFoldBySlug, updateFold, } from '../../../lib/firebase/folds' import Custom404 from '../../404' import { SiteLink } from '../../../components/site-link' import { toCamelCase } from '../../../lib/util/format' export async function getStaticProps(props: { params: { foldSlug: string } }) { const { foldSlug } = props.params const fold = await getFoldBySlug(foldSlug) return { props: { fold }, revalidate: 60, // regenerate after a minute } } export async function getStaticPaths() { return { paths: [], fallback: 'blocking' } } export default function EditFoldPage(props: { fold: Fold | null }) { const { fold } = props const [name, setName] = useState(fold?.name ?? '') const initialOtherTags = fold?.tags.filter((tag) => tag !== toCamelCase(name)).join(', ') ?? '' const [otherTags, setOtherTags] = useState(initialOtherTags) const [isSubmitting, setIsSubmitting] = useState(false) if (!fold) return const tags = parseWordsAsTags(toCamelCase(name) + ' ' + otherTags) const saveDisabled = !name || (name === fold.name && _.isEqual(tags, fold.tags)) const onSubmit = async () => { setIsSubmitting(true) await updateFold(fold, { name, tags, }) setIsSubmitting(false) } return ( {' '} {fold.name} Fold name setName(e.target.value || '')} /> Tags setOtherTags(e.target.value || '')} /> `#${tag}`)} noLink /> Save ) }