Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #74 from brown-ccv/feat-featured-pubs
Browse files Browse the repository at this point in the history
feat: featured publications
  • Loading branch information
hetd54 authored Jul 15, 2024
2 parents ee53cc0 + 4709313 commit 610722d
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 45 deletions.
3 changes: 3 additions & 0 deletions public/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ collections:
i18n: duplicate
label: Citation
widget: text
- name: feature
label: Featured Publication
widget: boolean
- name: image
required: false
i18n: duplicate
Expand Down
142 changes: 98 additions & 44 deletions src/components/Publications.tsx
Original file line number Diff line number Diff line change
@@ -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">[]
Expand All @@ -23,22 +23,62 @@ const PublicationSection: React.FC<PubProps> = ({ publications }) => {
] as const

const [searchInput, setSearchInput] = useState("")
const [classificationFilter, setClassificationFilter] =
useState<Readonly<{ value: Classification; label: string }[]>>(classificationOptions)
const [classificationFilter, setClassificationFilter] = useState<
SingleValue<Readonly<{ value: Classification; label: string }>>
>({ value: "Book", label: "Books" })

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
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<string, InferEntrySchema<"publications">[]> = shownPubs.reduce(
(pub, i) => {
const key = i.pubDate.toISOString().substring(0, 4)
pub[key] = pub[key] ?? []
pub[key].push(i)
return pub
},
{} as Record<string, InferEntrySchema<"publications">[]>
)
const pubsByYear = Object.entries(categoryByYear).sort(
(a, b) => new Date(b[0]).getTime() - new Date(a[0]).getTime()
)

return (
<>
<Form className="flex flex-col lg:flex-row gap-4 justify-center mb-24">
<section className="flex flex-col gap-6">
<h2>Featured Publications</h2>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
{featuredPubs.map((publication, i) => {
return (
<div key={i} className="">
<div className="flex flex-col gap-8">
<p>{publication.citation}</p>
{publication.pdf && (
<a
className="no-underline bg-neutral-500 text-neutral-50 rounded-full py-3 px-7 w-max"
href={publication.pdf}
>
View PDF
</a>
)}
</div>
</div>
)
})}
</div>
</section>
<Form className="flex flex-col lg:flex-row gap-4 justify-center my-24">
<div>
<Input
label="Search for a publication"
Expand All @@ -47,7 +87,7 @@ const PublicationSection: React.FC<PubProps> = ({ publications }) => {
placeholder="Durand, Jorge..."
value={searchInput}
onChange={handleChange}
className="min-w-96"
className="md:min-w-96"
/>
</div>
<div className="space-y-2">
Expand All @@ -57,10 +97,8 @@ const PublicationSection: React.FC<PubProps> = ({ publications }) => {
<Select
id="classification"
options={classificationOptions}
isMulti
isSearchable={false}
closeMenuOnSelect={false}
defaultValue={classificationOptions}
defaultValue={classificationFilter}
unstyled
className="cursor-pointer"
classNames={{
Expand All @@ -85,46 +123,62 @@ const PublicationSection: React.FC<PubProps> = ({ publications }) => {
</div>
</Form>

{shownPubs && (
{pubsByYear && (
<section className="flex flex-col gap-6">
{classificationOptions.map((option) => {
return (
<article key={option.value}>
<h2 className="mb-10">{option.label}</h2>
<div className="grid grid-cols-1 md:grid-cols-2 gap-12">
{shownPubs.map((publication, i) => {
if (publication.classification === option.value) {
if (classificationFilter && classificationFilter.label === option.label) {
return (
<article key={option.value}>
<h2 className="mb-10">{option.label}</h2>
<div className="">
{pubsByYear.map((cat, i) => {
return (
<div key={i} className="flex gap-8 content-start">
<div className="flex-none hidden md:block shadow-book-shadow w-40 h-72">
{publication.image ? (
<img
className="flex-none object-cover h-full w-full"
src={publication.image}
/>
) : (
<PubPlaceholder />
)}
</div>

<div className="flex flex-col gap-8">
<p className="font-bold">{publication.citation}</p>
{publication.pdf && (
<a
className="no-underline bg-neutral-500 text-neutral-50 rounded-full py-3 px-7 w-max"
href={publication.pdf}
<div key={i} className="flex flex-col gap-6 py-6">
<h3 className="font-bold">{cat[0]}</h3>
{cat[1].map((pub) => {
return (
<div
key={pub.citation}
className={
option.label === "Books" ? "flex gap-8 content-start" : "gap-8"
}
>
View PDF
</a>
)}
</div>
{option.label === "Books" && (
<div className="flex-none hidden md:block shadow-book-shadow w-40 h-72">
{pub.image ? (
<img
className="flex-none object-cover h-full w-full"
src={pub.image}
/>
) : (
<PubPlaceholder />
)}
</div>
)}

<div className="flex flex-col gap-4">
<p>{pub.citation}</p>
{pub.pdf && (
<div className={option.label === "Books" ? "" : "ml-2"}>
<a
className="no-underline bg-neutral-500 text-neutral-50 rounded-full py-3 px-7 w-max"
href={pub.pdf}
>
View PDF
</a>
</div>
)}
</div>
</div>
)
})}
</div>
)
}
})}
</div>
</article>
)
})}
</div>
</article>
)
}
})}
</section>
)}
Expand Down
1 change: 1 addition & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const publications = defineCollection({
author: z.string(),
pubDate: z.coerce.date(),
citation: z.string(),
feature: z.boolean(),
image: z.string().optional(),
pdf: z.string().optional(),
url: z.string().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ author: Rodilitz, Scott and Edward H. Kaplan
pubDate: 2021-09-01
citation: 'Rodilitz, Scott and Edward H. Kaplan. "Snapshot Models of
Undocumented Immigration." Risk Analysis, (2021) DOI: 10.1111/risa.13658'
feature: true
url: https://pubmed.ncbi.nlm.nih.gov/33373472/
---
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pubDate: 2010-01-01
citation: Donato, Katharine M., Jonathan Hiskey, Jorge Durand, and Douglas
S. Massey. 2010. Salvando fronteras. Migración internacional en
América Latina y el Caribe. Miguel Angel Porrúa.
feature: false
image: /pubs/salvando_fronteras.jpg
pdf: /pubs/donato_hiskey_durand_massey_2010-salvando-fronteras.pdf
---
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pubDate: 2013-01-01
citation: Arias, Patricia and Jorge Durand. 2013. Paul S. Taylor y la migración
jalisciense a Estados Unidos. Universidad de Guadalajara, Centro Universitario
de los Altos.
feature: false
image: /pubs/taylor-y-la-migracion-jaliscience.jpg
pdf: /pubs/2013_arias_durand_paul_taylor.pdf
---
1 change: 1 addition & 0 deletions src/content/publications/book-2016-01-01_durand-jorge.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: Durand, Jorge
pubDate: 2016-01-01
citation: "Durand, Jorge . 2016. Historia mínima de la migración México-Estados
Unidos . 1a. edición. Ciudad de México: El Colegio de México"
feature: true
image: /pubs/historiaminimamexico.jpg
url: https://doi.org/10.2307/j.ctt1t89k3g
---
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ citation: >
In Lois Ann Lorentzen (Ed.), Hidden Lives and Human Rights in the United
States: Undestanding the Constroversies and Tragedies of Undocumented
Immigration (pp. 53-70). Santa Barbara, California: Praeger, 2014.
feature: false
image: /pubs/hidden-lives.jpg
---
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ citation: >
tesis sobre el trabajo migrante temporal." In S. M. Lara Flores, J. Pantaleón,
y M. J. Sánchez Gómez (coordinadores) 1a ed. Hacia el otro norte. Mexicanos en
Canadá (pp. 175-205). Ciudad Autónoma de Buenos Aires: CLACSO, 2015.
feature: false
pdf: /pubs/haciaelotronorte.pdf
---
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ citation: >
Challenge to the Migration and Development Nexus." In A. Coles, L. Gray, and
J. Momsen (Eds.), The Routledge Handbook of Gender and Development. Chapter 37
(pp. 365-373).
feature: false
image: /pubs/handbook-gender-dev.jpeg
---
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ citation: >
Acosta Arcarazo and Anja Wiesbrock, editors. Global Migration. Old
Assumptions, New Dynamics Vol. 2, Chapter 1 (pp. 3-22). Santa Barbara,
California: Praeger, 2015.
feature: false
image: /pubs/global-migration.jpg
---
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ citation: >
Massey, Douglas S. (2015). "Uninformed Policies and Reactionary Politics." In
Christian Dustmann, editor. Migration: Economic Change, Social Challenge,
Chapter 6 (pp. 118-137). Oxford University Press, 2015.
feature: false
url: https://global.oup.com/academic/product/migration-9780198729624?cc=us&lang=en&
---
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ citation: 'Donato, Katharine M. and Gabriela León-Pérez. (2016). "Educación,
Estudios comparados Colombia-América Latina - Proyecto LAMP, 1a edición,
Capítulo 7, pp. 179-202. Colección: Ciencias Sociales - Sociología. Cali:
Programa Editorial Universidad del Valle, 2016.'
feature: false
image: /pubs/migration-international.jpg
---
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ citation: >
Internacional: patrones y determinantes. Estudios comparados Colombia-América
Latina - Proyecto LAMP, 1a edición, Capítulo 1, pp. 17-38. Colección: Ciencias
Sociales - Sociología. Cali: Programa Editorial Universidad del Valle, 2016.
feature: false
---
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ citation: >
comparados Colombia-América Latina - Proyecto LAMP, 1a edición, Capítulo 10,
pp. 263-289. Colección: Ciencias Sociales - Sociología. Cali: Programa
Editorial Universidad del Valle, 2016."
feature: false
---
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ citation: >
Related to Climate Stressors: The Case of Mexico." In R. McLeman, J. Schade,
and T. Faist (eds.) Environmental Migration and Social Inequality, part II,
chapter 8 (pp. 117-128). Springer International Publishing, 2016
feature: false
---
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ citation: >
determinantes. Estudios comparados Colombia-América Latina - Proyecto LAMP, 1a
edición, Capítulo 8, pp. 203-236. Colección: Ciencias Sociales - Sociología.
Cali: Programa Editorial Universidad del Valle, 2016.
feature: false
---
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ classification: Dissertation
author: Department of Economics, Georgetown University.
pubDate: 1995-01-01
citation: >-
"Mexican Labor Migration to the United States: Determinants, Labor Market Outcomes, and Dynamics." PhD. Dissertation, Department of Economics, Georgetown University.
feature: false
---

0 comments on commit 610722d

Please sign in to comment.