porridger/front/src/components/CategoryPreview.tsx
2023-08-15 23:33:58 +03:00

30 lines
999 B
TypeScript

import StoriesPreview from './StoriesPreview'
import { UserCategoriesNames, UserCategory, composeUserCategoriesFilters } from '../assets/userCategories'
import { useAnnouncements } from '../hooks/api'
import { gotError, gotResponse } from '../hooks/useFetch'
type CategoryPreviewProps = {
category: UserCategory,
}
function CategoryPreview({ category }: CategoryPreviewProps) {
const announcements = useAnnouncements(composeUserCategoriesFilters[category]())
return (
<section>
<h4 className='fw-bold'>{UserCategoriesNames[category]}</h4>
{gotError(announcements) ? (
<p className='text-danger'>{announcements.error}</p>
) : (
gotResponse(announcements) ? (
<StoriesPreview announcements={announcements.data} category={category} />
) : (
'Загрузка...'
)
)}
</section>
)
}
export default CategoryPreview