import { Fragment, useState } from 'react' import { compute, Contract, deleteContract, setContract, } from '../lib/firebase/contracts' import { Col } from './layout/col' import { Spacer } from './layout/spacer' import { ContractProbGraph } from './contract-prob-graph' import { ContractDetails } from './contracts-list' import router from 'next/router' import { useUser } from '../hooks/use-user' import { Row } from './layout/row' import dayjs from 'dayjs' import Link from 'next/link' function ContractDescription(props: { contract: Contract isCreator: boolean }) { const { contract, isCreator } = props const [editing, setEditing] = useState(false) const editStatement = () => `${dayjs().format('MMM D, h:mma')}: ` const [description, setDescription] = useState(editStatement()) // Append the new description (after a newline) async function saveDescription(e: any) { e.preventDefault() setEditing(false) contract.description = `${contract.description}\n${description}`.trim() await setContract(contract) setDescription(editStatement()) } // Return a JSX span, linkifying @username, #hashtags, and https://... function Linkify(props: { text: string }) { const { text } = props const regex = /(?:^|\s)(?:[@#][a-z0-9_]+|https?:\/\/\S+)/gi const matches = text.match(regex) || [] const links = matches.map((match) => { // Matches are in the form: " @username" or "https://example.com" const whitespace = match.match(/^\s/) const symbol = match.trim().substring(0, 1) const tag = match.trim().substring(1) const href = { '@': `/${tag}`, '#': `/tag/${tag}`, }[symbol] ?? match return ( <> {whitespace} {symbol} {tag} ) }) return ( {text.split(regex).map((part, i) => ( {part} {links[i]} ))} ) } return (

{isCreator && !contract.resolution && (editing ? (