import JobForm from './job-form' import Link from 'next/link' import Button from 'react-bootstrap/Button' import Alert from 'react-bootstrap/Alert' import AccordianItem from './accordian-item' import { useMe } from './me' import { useRouter } from 'next/router' import { DiscussionForm } from './discussion-form' import { LinkForm } from './link-form' import { PollForm } from './poll-form' import { BountyForm } from './bounty-form' import SubSelect from './sub-select' import { useCallback, useState } from 'react' import FeeButton, { FeeButtonProvider, postCommentBaseLineItems, postCommentUseRemoteLineItems } from './fee-button' import Delete from './delete' import CancelButton from './cancel-button' import { TerritoryInfo } from './territory-header' export function PostForm ({ type, sub, children }) { const me = useMe() const [errorMessage, setErrorMessage] = useState() const prefix = sub?.name ? `/~${sub.name}` : '' const checkSession = useCallback((e) => { if (!me) { e.preventDefault() setErrorMessage('you must be logged in') } }, [me, setErrorMessage]) if (!type) { let postButtons = [] let morePostButtons = [] if (sub) { if (sub?.postTypes?.includes('LINK')) { postButtons.push( ) } if (sub?.postTypes?.includes('DISCUSSION')) { postButtons.push( ) } if (sub?.postTypes?.includes('POLL')) { const array = postButtons.length < 2 ? postButtons : morePostButtons array.push( ) } if (sub?.postTypes?.includes('BOUNTY')) { const array = postButtons.length < 2 ? postButtons : morePostButtons array.push( ) } } else { postButtons = [ , ] morePostButtons = [ , ] } postButtons = postButtons.reduce((acc, cur) => { if (acc.length) acc.push(or) acc.push(cur) return acc }, []) morePostButtons = morePostButtons.reduce((acc, cur) => { if (acc.length) acc.push(or) acc.push(cur) return acc }, []) return (
{errorMessage && setErrorMessage(undefined)} dismissible> {errorMessage} } } hint={sub?.moderated && 'this territory is moderated'} />
{postButtons}
more types
} body={
{morePostButtons}
} />
) } let FormType = JobForm if (type === 'discussion') { FormType = DiscussionForm } else if (type === 'link') { FormType = LinkForm } else if (type === 'poll') { FormType = PollForm } else if (type === 'bounty') { FormType = BountyForm } return ( {children} ) } export default function Post ({ sub }) { const router = useRouter() let type = router.query.type if (sub?.postTypes?.length === 1) { type = sub.postTypes[0].toLowerCase() } return ( <> {sub?.name !== 'jobs' && s.postTypes?.includes(type.toUpperCase())} className='w-auto d-flex' large label='territory' info={sub && } hint={sub?.moderated && 'this territory is moderated'} />} ) } export function ItemButtonBar ({ itemId, canDelete = true, disable, className, children, onDelete, onCancel, hasCancel = true, createText = 'post', editText = 'save' }) { const router = useRouter() return (
{itemId && canDelete && router.push(`/items/${itemId}`))} > } {children}
{hasCancel && }
) }