stacker.news/pages/post.js

119 lines
3.7 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'
2023-01-26 16:11:55 +00:00
import { BountyForm } from '../components/bounty-form'
2023-05-01 20:58:30 +00:00
import { Form, Select } from '../components/form'
import { useEffect, useState } from 'react'
2023-05-02 16:55:10 +00:00
import Info from '../components/info'
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'>
{me?.freePosts && me?.sats < 1
2022-07-30 13:25:46 +00:00
? <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>
2023-01-26 16:11:55 +00:00
<div className='d-flex mt-3'>
2022-07-30 13:25:46 +00:00
<AccordianItem
headerColor='#6c757d'
header={<div className='font-weight-bold text-muted'>more</div>}
body={
2023-01-26 16:11:55 +00:00
<div className='align-items-center'>
<Link href='/post?type=poll'>
<Button variant='info'>poll</Button>
</Link>
<span className='mx-3 font-weight-bold text-muted'>or</span>
<Link href='/post?type=bounty'>
<Button variant='info'>bounty</Button>
</Link>
</div>
}
2022-07-30 13:25:46 +00:00
/>
</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 />
2023-01-26 16:11:55 +00:00
} else if (router.query.type === 'poll') {
2022-07-30 13:25:46 +00:00
return <PollForm />
2023-01-26 16:11:55 +00:00
} else {
return <BountyForm adv />
2021-04-12 18:05:09 +00:00
}
}
2023-05-01 20:58:30 +00:00
export function SubSelect ({ children }) {
const router = useRouter()
const [sub, setSub] = useState(router.query.sub || 'bitcoin')
useEffect(() => {
setSub(router.query.sub || 'bitcoin')
}, [router.query?.sub])
return (
<div className='mb-3 d-flex justify-content-start'>
<Form
2023-05-02 16:55:10 +00:00
className='w-auto d-flex align-items-center'
2023-05-01 20:58:30 +00:00
initial={{
sub
}}
>
<Select
groupClassName='mb-0'
onChange={(formik, e) =>
// todo move the form values to the other sub's post form
router.push({
pathname: `/~${e.target.value}/post`,
query: router.query?.type ? { type: router.query.type } : undefined
})}
name='sub'
size='sm'
items={router.query?.type ? ['bitcoin', 'nostr'] : ['bitcoin', 'nostr', 'jobs']}
/>
2023-05-02 16:55:10 +00:00
<Info>
<div>
<div className='font-weight-bold'>The sub your post will go in ...</div>
<ul>
<li>If it's bitcoin related, put it in the bitcoin sub.</li>
<li>If it's nostr related, put it in the nostr sub.</li>
<li>If it's a job, put it in the jobs sub.</li>
</ul>
</div>
</Info>
2023-05-01 20:58:30 +00:00
</Form>
{children}
</div>
)
}
2021-04-12 18:05:09 +00:00
export default function Post () {
return (
2021-05-06 21:15:22 +00:00
<LayoutCenter>
2023-05-01 20:58:30 +00:00
<SubSelect />
2021-05-06 21:15:22 +00:00
<PostForm />
</LayoutCenter>
2021-04-12 18:05:09 +00:00
)
}