|
| 1 | +import { MacroTheme, SectionHeader } from "@/utils/interfaces"; |
| 2 | +import { Icon } from "@/components/Icon/Icon"; |
| 3 | +import { LinkButton } from "@/components/LinkButton/LinkButton"; |
| 4 | +import CategoryCard from "../CategoryCard/CategoryCard"; |
| 5 | + |
| 6 | +const DataSection = ({ |
| 7 | + header, |
| 8 | + categories, |
| 9 | +}: { |
| 10 | + header?: { fields: SectionHeader }; |
| 11 | + categories?: { fields: MacroTheme }[]; |
| 12 | +}) => { |
| 13 | + const { title, subtitle } = header?.fields || { |
| 14 | + title: "", |
| 15 | + subtitle: "", |
| 16 | + }; |
| 17 | + |
| 18 | + const filteredData = categories?.sort((a, b) => { |
| 19 | + if (a.fields.id < b.fields.id) { |
| 20 | + return -1; |
| 21 | + } |
| 22 | + if (a.fields.id > b.fields.id) { |
| 23 | + return 1; |
| 24 | + } |
| 25 | + |
| 26 | + return 0; |
| 27 | + }); |
| 28 | + |
| 29 | + return ( |
| 30 | + <section |
| 31 | + className="w-full max-w-[1440px] px-4 py-6 content-center flex flex-col gap-6 box-border" |
| 32 | + id={title} |
| 33 | + > |
| 34 | + <div className="flex flex-col gap-3"> |
| 35 | + <div className="flex justify-between w-full"> |
| 36 | + <h2 className="text-3xl font-semibold">{title}</h2> |
| 37 | + <LinkButton |
| 38 | + href="/posts" |
| 39 | + variant="secondary" |
| 40 | + className="w-fit hidden md:flex" |
| 41 | + > |
| 42 | + <p>Ver Todos</p> |
| 43 | + <Icon className="rotate-270 size-2" id="expand" /> |
| 44 | + </LinkButton> |
| 45 | + </div> |
| 46 | + <p className="text-sm">{subtitle}</p> |
| 47 | + </div> |
| 48 | + <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6"> |
| 49 | + {filteredData?.map((category: { fields: MacroTheme }) => ( |
| 50 | + <CategoryCard key={category.fields.id} category={category} /> |
| 51 | + ))} |
| 52 | + </div> |
| 53 | + <LinkButton href="/posts" variant="secondary" className="md:hidden"> |
| 54 | + <p>Ver Todos</p> |
| 55 | + <Icon className="rotate-270 size-2" id="expand" /> |
| 56 | + </LinkButton> |
| 57 | + </section> |
| 58 | + ); |
| 59 | +}; |
| 60 | + |
| 61 | +export default DataSection; |
0 commit comments