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

feat: init pubs page #55

Merged
merged 30 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eab09dc
feat: add publication collection
hetd54 Jun 25, 2024
6f7aa50
feat: publication section with shown pubs
hetd54 Jun 25, 2024
355cb4a
chore: add react-select
hetd54 Jun 25, 2024
e8bad77
chore: add sample pub
hetd54 Jun 25, 2024
9356cb3
Merge branch 'main' into pubs-page
hetd54 Jun 25, 2024
5910c46
feat: iterate over classification options to display pubs
hetd54 Jun 25, 2024
5ab6776
chore: add optional image to pub
hetd54 Jun 25, 2024
b6511fe
styles: optional img, grid
hetd54 Jun 25, 2024
e251aaf
test: add more pubs for testing
hetd54 Jun 25, 2024
15c9464
style: grid vs flex
hetd54 Jun 25, 2024
660034e
styles: add placeholder image for pubs
hetd54 Jun 26, 2024
4fff0f7
Merge branch 'main' into pubs-page
hetd54 Jun 27, 2024
076bf6b
Merge branch 'main' into pubs-page
hetd54 Jul 1, 2024
ccdbe25
fix: images to public
hetd54 Jul 1, 2024
4a98725
refactor: publications in subfolder
hetd54 Jul 1, 2024
e720808
chore: add a bunch of pubs
hetd54 Jul 1, 2024
63c830f
refactor: remove useEffect
hetd54 Jul 1, 2024
5b7b76f
chore: npm audit fix
hetd54 Jul 1, 2024
c13dba8
Merge branch 'main' into pubs-page
hetd54 Jul 1, 2024
c49cbbd
chore: add back react select
hetd54 Jul 1, 2024
3edee5a
fix: set options interface for typing of onchange for filter
hetd54 Jul 1, 2024
a5ca881
chore: remove unused import
hetd54 Jul 1, 2024
c6a9e32
fix: shorten slugs for publications
hetd54 Jul 1, 2024
9842f94
chore: just ts things
hetd54 Jul 1, 2024
b9d4774
fix: select type
galenwinsor Jul 1, 2024
c09613c
fix: update pub object
hetd54 Jul 1, 2024
035d680
Merge branch 'pubs-page' of https://github.com/brown-ccv/mmp into pub…
hetd54 Jul 1, 2024
0efc83b
fix: type matching in zod
hetd54 Jul 1, 2024
1745f8f
refactor: remove logs
hetd54 Jul 1, 2024
464be96
refactor: image location of pubs in public
hetd54 Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"i": "^0.3.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-select": "^5.8.0",
"react-hook-form": "^7.51.3",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
Expand Down
24 changes: 21 additions & 3 deletions public/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,42 @@ collections:
date_format: yyyy
time_format: false
format: yyyy
- name: pubs
- name: publications
label: Publications
folder: src/content/pubs
folder: src/content/publications
create: true
slug: '{{year}}-{{month}}-{{day}}_{{title}}_{{slug}}'
identifier_field: citation
fields:
- name: classification
label: Classification
widget: select
options: [ 'Book', 'Chapter', 'Article', 'Dissertation' ]
- name: pubDate
i18n: duplicate
label: Publish Date
widget: datetime
date_format: MM.yyyy
time_format: false
- name: citation
i18n: duplicate
label: Citation
widget: text
- name: image
required: false
i18n: duplicate
label: Image
widget: image
- name: url
required: false
i18n: duplicate
label: Link to Publication
widget: string
- name: pdf
required: false
i18n: duplicate
label: PDF
widget: file
public_folder: public/publications
- name: data
label: Data
create: true
Expand Down
161 changes: 161 additions & 0 deletions src/components/Publications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import React, { useEffect, useState } from "react"
import Select from "react-select"
import PubPlaceholder from "./svg/PubPlaceholder.tsx"

interface PubProps {
publications: Array<PubObject>
}

interface PubObject {
data: {
classification: string
citation: string
image?: string
url?: string
pdf?: string
}
}

const PublicationSection: React.FC<PubProps> = ({ publications }) => {
const classificationOptions = [
{ value: "Book", label: "Books" },
{
value: "Article",
label: "Articles",
},
{ value: "Dissertation", label: "Dissertations" },
{ value: "Chapter", label: "Chapters" },
]

const [shownPubs, setShownPubs] = useState(publications)
const [searchInput, setSearchInput] = useState("")
const [classificationFilter, setClassificationFilter] = useState(classificationOptions)
const handleChange = (e: {
preventDefault: () => void
target: { value: React.SetStateAction<string> }
}) => {
hetd54 marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault()
setSearchInput(e.target.value)
}

useEffect(() => {
let currentPubs = publications
// filter based on classification
if (classificationFilter.length > 0) {
const filteredClassifications = classificationFilter.map(({ value }) => value)
currentPubs = currentPubs.filter((pub) =>
filteredClassifications.includes(pub.data.classification)
)
}

if (searchInput.length > 0) {
// do a search for Pubs
const foundPublications = currentPubs.filter(
(pub: { data: { citation: string | string[] } }) => {
if (pub.data && pub.data.citation.includes(searchInput)) {
return pub
}
}
)
if (foundPublications.length > 0) {
currentPubs = foundPublications
} else {
currentPubs = []
}
}

setShownPubs(currentPubs)
}, [searchInput, classificationFilter])
hetd54 marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<section className="flex flex-col lg:flex-row gap-4 py-14">
<div>
<label className="pl-1">Search for a Publication</label>
<input
type="text"
placeholder="🔍 Search here"
onChange={handleChange}
value={searchInput}
className="min-w-[460px]"
/>
galenwinsor marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div>
<label className="pl-1">Show</label>
<Select
options={classificationOptions}
isMulti={true}
isSearchable={false}
closeMenuOnSelect={false}
defaultValue={classificationOptions}
styles={{
control: (baseStyles) => ({
...baseStyles,
minWidth: "526px",
borderRadius: "9999px",
background: "#FAFAFA",
boxShadow:
"var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)",
paddingTop: ".75rem",
paddingBottom: ".75rem",
paddingLeft: "2rem",
paddingRight: "2rem",
}),
}}
onChange={(e) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
setClassificationFilter(e)
}}
/>
</div>
</section>

{shownPubs && (
<section className="flex flex-col gap-6">
{classificationOptions.map((option) => {
return (
<article key={option.value}>
<h2 className="py-2">{option.label}</h2>
<div className="flex flex-wrap lg:flex-nowrap gap-12">
{shownPubs.map((publication, i) => {
if (publication.data.classification === option.value) {
return (
<div key={i} className="grid grid-cols-1 md:grid-cols-2 gap-2">
<div className="hidden md:block drop-shadow-md">
{publication.data.image ? (
<img
className="drop-shadow-md object-cover w-48 h-72"
src={publication.data.image}
/>
) : (
<PubPlaceholder />
)}
</div>

<div className="flex flex-col gap-8 ">
<p>{publication.data.citation}</p>
{publication.data.pdf && (
<button
className="bg-neutral-500 text-neutral-50 rounded-full py-3 px-7 w-2/3"
onClick={() => console.log(publication.data.pdf)}
>
View PDF
</button>
)}
</div>
</div>
)
}
})}
</div>
</article>
)
})}
</section>
)}
</>
)
}

export default PublicationSection
81 changes: 81 additions & 0 deletions src/components/svg/PubPlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from "react"

const PubPlaceholder: React.FC = () => {
return (
<>
<svg
width="232"
height="342"
viewBox="0 0 232 342"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g filter="url(#filter0_dd_313_544)">
<rect width="200" height="310" transform="translate(12 12)" fill="#A7998B" />
<rect width="143" height="30" transform="translate(29 32)" fill="#D4CDC4" />
<rect width="143" height="12" transform="translate(29 72)" fill="#D4CDC4" />
<rect width="143" height="12" transform="translate(29 94)" fill="#D4CDC4" />
</g>
<defs>
<filter
id="filter0_dd_313_544"
x="0"
y="0"
width="232"
height="342"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB"
>
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feOffset dx="12" dy="12" />
<feGaussianBlur stdDeviation="2" />
<feComposite in2="hardAlpha" operator="out" />
<feColorMatrix
type="matrix"
values="0 0 0 0 0.654902 0 0 0 0 0.6 0 0 0 0 0.545098 0 0 0 0.35 0"
/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_313_544" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feMorphology
radius="4"
operator="dilate"
in="SourceAlpha"
result="effect2_dropShadow_313_544"
/>
<feOffset dx="4" dy="4" />
<feGaussianBlur stdDeviation="6" />
<feComposite in2="hardAlpha" operator="out" />
<feColorMatrix
type="matrix"
values="0 0 0 0 0.654902 0 0 0 0 0.6 0 0 0 0 0.545098 0 0 0 0.35 0"
/>
<feBlend
mode="normal"
in2="effect1_dropShadow_313_544"
result="effect2_dropShadow_313_544"
/>
<feBlend
mode="normal"
in="SourceGraphic"
in2="effect2_dropShadow_313_544"
result="shape"
/>
</filter>
</defs>
</svg>
</>
)
}

export default PubPlaceholder
14 changes: 13 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ const files = defineCollection({
}),
})

const publications = defineCollection({
type: "content",
schema: z.object({
classification: z.string(),
pubDate: z.coerce.date(),
citation: z.string(),
image: z.string().optional(),
pdf: z.string().optional(),
url: z.string().optional(),
}),
})

const people = defineCollection({
type: "content",
schema: z.object({
Expand All @@ -33,4 +45,4 @@ const people = defineCollection({
institution: z.string(),
}),
})
export const collections = { news: news, data: files, people: people }
export const collections = { news: news, data: files, people: people, publications: publications }
Binary file added src/content/data/files/historiaminimamexico.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
classification: Book
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.
image: /public/images/taylor-y-la-migracion-jaliscience.jpg
pdf: public/publications/codebook_life.pdf
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
classification: Chapter
pubDate: 2016-01-01
citation: 'Donato, Katharine M. and Gabriela León-Pérez. (2016). "Educación,
género, y migración de Colombia y México a Estados Unidos" in María Gertrudis
Roa Martínez (compiladora) Migración Internacional: patrones y determinantes.
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.'
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
classification: Book
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"
image: /public/images/historiaminimamexico.jpg
url: https://doi.org/10.2307/j.ctt1t89k3g
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
classification: Dissertation
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.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
classification: Article
pubDate: 2021-09-01
citation: 'Rodilitz, Scott and Edward H. Kaplan. "Snapshot Models of
Undocumented Immigration." Risk Analysis, (2021) DOI: 10.1111/risa.13658'
url: https://pubmed.ncbi.nlm.nih.gov/33373472/
---
11 changes: 11 additions & 0 deletions src/pages/publications.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Layout from "../layouts/Layout.astro"
import PublicationSection from "../components/Publications"
import { getCollection } from "astro:content"

const pubs = await getCollection("publications")
---

<Layout title="Publications" description="Publications associated with MMP">
<PublicationSection publications={pubs} client:only="react" />
</Layout>