stacker.news/pages/post.js

62 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-04-14 00:57:32 +00:00
import Button from 'react-bootstrap/Button'
2021-04-12 18:05:09 +00:00
import { useRouter } from 'next/router'
import Link from 'next/link'
2021-05-06 21:15:22 +00:00
import LayoutCenter from '../components/layout-center'
2021-05-25 00:08:56 +00:00
import { useMe } from '../components/me'
2021-08-11 20:13:10 +00:00
import { DiscussionForm } from '../components/discussion-form'
import { LinkForm } from '../components/link-form'
2022-04-21 22:50:02 +00:00
import { getGetServerSideProps } from '../api/ssrApollo'
2022-07-30 13:25:46 +00:00
import AccordianItem from '../components/accordian-item'
import { PollForm } from '../components/poll-form'
2022-04-21 22:50:02 +00:00
export const getServerSideProps = getGetServerSideProps()
2021-04-12 18:05:09 +00:00
export function PostForm () {
const router = useRouter()
2021-05-25 00:08:56 +00:00
const me = useMe()
2021-04-12 18:05:09 +00:00
if (!router.query.type) {
return (
<div className='align-items-center'>
2022-07-30 13:25:46 +00:00
{me?.freePosts
? <div className='text-center font-weight-bold mb-3 text-success'>{me.freePosts} free posts left</div>
: null}
2021-04-12 18:05:09 +00:00
<Link href='/post?type=link'>
2021-04-14 00:57:32 +00:00
<Button variant='secondary'>link</Button>
2021-04-12 18:05:09 +00:00
</Link>
<span className='mx-3 font-weight-bold text-muted'>or</span>
<Link href='/post?type=discussion'>
2021-05-06 21:15:22 +00:00
<Button variant='secondary'>discussion</Button>
2021-04-12 18:05:09 +00:00
</Link>
2022-07-30 13:25:46 +00:00
<div className='d-flex justify-content-center mt-3'>
<AccordianItem
headerColor='#6c757d'
header={<div className='font-weight-bold text-muted'>more</div>}
body={
<Link href='/post?type=poll'>
<Button variant='info'>poll</Button>
</Link>
}
/>
</div>
2021-04-12 18:05:09 +00:00
</div>
)
}
if (router.query.type === 'discussion') {
return <DiscussionForm adv />
2022-07-30 13:25:46 +00:00
} else if (router.query.type === 'link') {
2021-04-12 18:05:09 +00:00
return <LinkForm />
2022-07-30 13:25:46 +00:00
} else {
return <PollForm />
2021-04-12 18:05:09 +00:00
}
}
export default function Post () {
return (
2021-05-06 21:15:22 +00:00
<LayoutCenter>
<PostForm />
</LayoutCenter>
2021-04-12 18:05:09 +00:00
)
}