47 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-10-26 15:49:37 -05:00
import { ITEM } from '../../../fragments/items'
import { getGetServerSideProps } from '../../../api/ssrApollo'
2021-08-11 15:13:10 -05:00
import { DiscussionForm } from '../../../components/discussion-form'
import { LinkForm } from '../../../components/link-form'
import { CenterLayout } from '../../../components/layout'
2022-02-17 11:23:43 -06:00
import JobForm from '../../../components/job-form'
2022-08-18 13:15:24 -05:00
import { PollForm } from '../../../components/poll-form'
2023-01-26 10:11:55 -06:00
import { BountyForm } from '../../../components/bounty-form'
2023-05-10 19:26:07 -05:00
import SubSelect from '../../../components/sub-select-form'
import { useState } from 'react'
import { useQuery } from '@apollo/client'
import { useRouter } from 'next/router'
import PageLoading from '../../../components/page-loading'
2021-08-11 15:13:10 -05:00
export const getServerSideProps = getGetServerSideProps(ITEM, null,
data => !data.item)
2021-08-11 15:13:10 -05:00
export default function PostEdit ({ ssrData }) {
const router = useRouter()
const { data } = useQuery(ITEM, { variables: { id: router.query.id } })
if (!data && !ssrData) return <PageLoading />
const { item } = data || ssrData
const [sub, setSub] = useState(item.subName)
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000
2023-05-10 19:26:07 -05:00
let FormType = DiscussionForm
if (item.isJob) {
FormType = JobForm
} else if (item.url) {
FormType = LinkForm
} else if (item.pollCost) {
FormType = PollForm
} else if (item.bounty) {
FormType = BountyForm
}
2021-08-11 15:13:10 -05:00
return (
<CenterLayout sub={sub}>
2023-05-10 19:26:07 -05:00
<FormType item={item} editThreshold={editThreshold}>
{!item.isJob && <SubSelect label='sub' item={item} setSub={setSub} sub={sub} />}
</FormType>
</CenterLayout>
2021-08-11 15:13:10 -05:00
)
}