diff --git a/src/components/Publications.tsx b/src/components/Publications.tsx index 8ac5d13..b3349df 100644 --- a/src/components/Publications.tsx +++ b/src/components/Publications.tsx @@ -1,11 +1,11 @@ import React, { useState } from "react" -import Select from "react-select" +import Select, { type SingleValue } from "react-select" import type { InferEntrySchema } from "astro:content" import { Form } from "@radix-ui/react-form" +import { MagnifyingGlassIcon } from "@radix-ui/react-icons" import type { Classification } from "../content/config.ts" import PubPlaceholder from "./svg/PubPlaceholder.tsx" import { Input } from "./Input.tsx" -import { MagnifyingGlassIcon } from "@radix-ui/react-icons" interface PubProps { publications: InferEntrySchema<"publications">[] @@ -23,22 +23,62 @@ const PublicationSection: React.FC = ({ publications }) => { ] as const const [searchInput, setSearchInput] = useState("") - const [classificationFilter, setClassificationFilter] = - useState>(classificationOptions) + const [classificationFilter, setClassificationFilter] = useState< + SingleValue> + >({ value: "Book", label: "Books" }) + const handleChange = (e: React.ChangeEvent) => { e.preventDefault() setSearchInput(e.target.value) } + const featuredPubs = publications.filter((pub) => pub.feature) + const shownPubs = publications.filter( (pub) => - classificationFilter.map((item) => item.value).includes(pub.classification) && + classificationFilter && + classificationFilter.value.includes(pub.classification) && pub.citation.toLowerCase().includes(searchInput.toLowerCase()) ) + const categoryByYear: Record[]> = shownPubs.reduce( + (pub, i) => { + const key = i.pubDate.toISOString().substring(0, 4) + pub[key] = pub[key] ?? [] + pub[key].push(i) + return pub + }, + {} as Record[]> + ) + const pubsByYear = Object.entries(categoryByYear).sort( + (a, b) => new Date(b[0]).getTime() - new Date(a[0]).getTime() + ) + return ( <> -
+
+

Featured Publications

+
+ {featuredPubs.map((publication, i) => { + return ( +
+
+

{publication.citation}

+ {publication.pdf && ( + + View PDF + + )} +
+
+ ) + })} +
+
+
= ({ publications }) => { placeholder="Durand, Jorge..." value={searchInput} onChange={handleChange} - className="min-w-96" + className="md:min-w-96" />
@@ -57,10 +97,8 @@ const PublicationSection: React.FC = ({ publications }) => {