stacker.news/components/recent-header.js
keyan 18910fa2ed Revert "shield your eyes; massive, squashed refactor; nextjs/react/react-dom/apollo upgrades"
This reverts commit d0314ab73c42ebf85fe2f418dddd681af45dbc55.
2023-07-23 09:16:12 -05:00

32 lines
876 B
JavaScript

import { Form, Select } from './form'
import { useRouter } from 'next/router'
export default function RecentHeader ({ type, sub }) {
const router = useRouter()
const prefix = sub?.name ? `/~${sub.name}` : ''
const items = ['posts', 'bounties', 'comments', 'links', 'discussions', 'polls']
if (!sub?.name) {
items.push('bios')
}
return (
<Form
initial={{
type: router.query.type || type || 'posts'
}}
>
<div className='text-muted font-weight-bold mt-0 mb-3 d-flex justify-content-end align-items-center'>
<Select
groupClassName='mb-0 ml-2'
className='w-auto'
name='type'
size='sm'
items={items}
onChange={(formik, e) => router.push(prefix + (e.target.value === 'posts' ? '/recent' : `/recent/${e.target.value}`))}
/>
</div>
</Form>
)
}