2023-05-11 00:26:07 +00:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { Select } from './form'
|
|
|
|
import Info from './info'
|
2023-06-20 16:26:23 +00:00
|
|
|
import { SUBS, SUBS_NO_JOBS } from '../lib/constants'
|
2023-05-11 00:26:07 +00:00
|
|
|
|
|
|
|
export function SubSelectInitial ({ sub }) {
|
|
|
|
const router = useRouter()
|
|
|
|
sub = sub || router.query.sub || 'pick sub'
|
|
|
|
|
|
|
|
return {
|
|
|
|
sub
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function SubSelect ({ label, sub, setSub, item, ...props }) {
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const SubInfo = () => (
|
|
|
|
<Info>
|
|
|
|
<div>
|
2023-07-24 18:35:05 +00:00
|
|
|
<div className='fw-bold'>The sub your post will go in ...</div>
|
2023-05-11 00:26:07 +00:00
|
|
|
<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>
|
2023-06-12 17:41:22 +00:00
|
|
|
<li>If it's tech related, put it in the tech sub.</li>
|
2023-06-20 16:26:23 +00:00
|
|
|
<li>If it's stacker news related, put it in the meta sub.</li>
|
2023-05-11 00:26:07 +00:00
|
|
|
<li>If it's a job, put it in the jobs sub.</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</Info>
|
|
|
|
)
|
|
|
|
|
2023-07-25 20:41:46 +00:00
|
|
|
sub ||= router.query.sub || 'pick sub'
|
|
|
|
const extraProps = props.noForm
|
|
|
|
? {
|
|
|
|
value: sub,
|
|
|
|
items: ['pick sub', ...SUBS]
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
overrideValue: sub,
|
|
|
|
items: item ? SUBS_NO_JOBS : ['pick sub', ...SUBS_NO_JOBS]
|
|
|
|
}
|
2023-07-25 20:29:45 +00:00
|
|
|
|
2023-05-11 00:26:07 +00:00
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
className='w-auto d-flex'
|
|
|
|
onChange={(formik, e) => {
|
|
|
|
if (!item) {
|
|
|
|
router.push({
|
|
|
|
pathname: e.target.value === 'pick sub' ? '/post' : `/~${e.target.value}/post`,
|
|
|
|
query: router.query?.type ? { type: router.query.type } : undefined
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setSub(e.target.value)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
name='sub'
|
|
|
|
size='sm'
|
2023-07-25 20:29:45 +00:00
|
|
|
{...extraProps}
|
2023-05-11 00:26:07 +00:00
|
|
|
label={label &&
|
|
|
|
<>
|
|
|
|
{label}
|
|
|
|
<SubInfo />
|
|
|
|
</>}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|