2021-10-26 20:49:37 +00:00
|
|
|
import { ITEM } from '../../../fragments/items'
|
|
|
|
import { getGetServerSideProps } from '../../../api/ssrApollo'
|
2021-08-11 20:13:10 +00:00
|
|
|
import { DiscussionForm } from '../../../components/discussion-form'
|
|
|
|
import { LinkForm } from '../../../components/link-form'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { CenterLayout } from '../../../components/layout'
|
2022-02-17 17:23:43 +00:00
|
|
|
import JobForm from '../../../components/job-form'
|
2022-08-18 18:15:24 +00:00
|
|
|
import { PollForm } from '../../../components/poll-form'
|
2023-01-26 16:11:55 +00:00
|
|
|
import { BountyForm } from '../../../components/bounty-form'
|
2023-05-11 00:26:07 +00:00
|
|
|
import SubSelect from '../../../components/sub-select-form'
|
|
|
|
import { useState } from 'react'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import PageLoading from '../../../components/page-loading'
|
2023-11-11 00:18:10 +00:00
|
|
|
import { FeeButtonProvider } from '../../../components/fee-button'
|
2021-08-11 20:13:10 +00:00
|
|
|
|
2023-08-28 17:52:15 +00:00
|
|
|
export const getServerSideProps = getGetServerSideProps({
|
|
|
|
query: ITEM,
|
|
|
|
notFound: data => !data.item,
|
|
|
|
authRequired: true
|
|
|
|
})
|
2021-08-11 20:13:10 +00:00
|
|
|
|
2023-07-23 15:08:43 +00: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
|
2023-07-23 14:16:12 +00:00
|
|
|
const [sub, setSub] = useState(item.subName)
|
2023-07-21 22:33:11 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000
|
|
|
|
|
2023-05-11 00:26:07 +00: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 20:13:10 +00:00
|
|
|
|
2023-11-11 00:18:10 +00:00
|
|
|
const existingBoostLineItem = item.boost
|
|
|
|
? {
|
|
|
|
existingBoost: {
|
|
|
|
label: 'old boost',
|
|
|
|
term: `- ${item.boost}`,
|
|
|
|
modifier: cost => cost - item.boost
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: undefined
|
|
|
|
|
2021-08-11 20:13:10 +00:00
|
|
|
return (
|
2023-07-23 15:08:43 +00:00
|
|
|
<CenterLayout sub={sub}>
|
2023-11-11 00:18:10 +00:00
|
|
|
<FeeButtonProvider baseLineItems={existingBoostLineItem}>
|
|
|
|
<FormType item={item} editThreshold={editThreshold}>
|
|
|
|
{!item.isJob && <SubSelect label='sub' item={item} setSub={setSub} sub={sub} />}
|
|
|
|
</FormType>
|
|
|
|
</FeeButtonProvider>
|
2023-07-23 15:08:43 +00:00
|
|
|
</CenterLayout>
|
2021-08-11 20:13:10 +00:00
|
|
|
)
|
|
|
|
}
|