import clsx from 'clsx' import dayjs from 'dayjs' import { useState } from 'react' import Textarea from 'react-expanding-textarea' import { CATEGORY_LIST } from '../../../common/categories' import { Contract } from 'common/contract' import { parseTags } from 'common/util/parse' import { useAdmin } from 'web/hooks/use-admin' import { updateContract } from 'web/lib/firebase/contracts' import { Row } from '../layout/row' import { Linkify } from '../linkify' import { TagsList } from '../tags-list' export function ContractDescription(props: { contract: Contract isCreator: boolean className?: string }) { const { contract, isCreator, className } = props const descriptionTimestamp = () => `${dayjs().format('MMM D, h:mma')}: ` const isAdmin = useAdmin() // Append the new description (after a newline) async function saveDescription(newText: string) { const newDescription = `${contract.description}\n\n${newText}`.trim() const tags = parseTags( `${newDescription} ${contract.tags.map((tag) => `#${tag}`).join(' ')}` ) const lowercaseTags = tags.map((tag) => tag.toLowerCase()) await updateContract(contract.id, { description: newDescription, tags, lowercaseTags, }) } if (!isCreator && !contract.description.trim()) return null const { tags } = contract const categories = tags.filter((tag) => CATEGORY_LIST.includes(tag.toLowerCase()) ) return (