stacker.news/components/recent-header.js

27 lines
752 B
JavaScript
Raw Normal View History

import { ITEM_TYPES } from '../lib/constants'
import { Select } from './form'
2022-12-01 22:22:13 +00:00
import { useRouter } from 'next/router'
2023-05-01 20:58:30 +00:00
export default function RecentHeader ({ type, sub }) {
2022-12-01 22:22:13 +00:00
const router = useRouter()
const prefix = sub ? `/~${sub}` : ''
2023-05-01 20:58:30 +00:00
const items = ITEM_TYPES(sub)
2022-08-23 22:34:51 +00:00
type ||= router.query.type || type || 'posts'
2022-08-23 22:34:51 +00:00
return (
<div className='text-muted fw-bold mt-0 mb-3 d-flex justify-content-end align-items-center'>
<Select
groupClassName='mb-0 ms-2'
className='w-auto'
name='type'
size='sm'
value={type}
items={items}
noForm
onChange={(_, e) => router.push(prefix + (e.target.value === 'posts' ? '/recent' : `/recent/${e.target.value}`))}
/>
</div>
2022-08-23 22:34:51 +00:00
)
}