From 600627907c0a993f7400cff30dc5c5c3c34564cd Mon Sep 17 00:00:00 2001 From: raffazizzi Date: Wed, 31 Jul 2024 13:26:32 -0400 Subject: [PATCH] filtered and sorted past people. Fix to CSS. Closes #29 --- src/pages/people-past.tsx | 51 ++++++++++++++++++++++++++++++++++++--- src/pages/people.css | 6 ++++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/pages/people-past.tsx b/src/pages/people-past.tsx index f86f4c8e6f..7d6ee077e5 100644 --- a/src/pages/people-past.tsx +++ b/src/pages/people-past.tsx @@ -13,6 +13,12 @@ type Person = NonNullable< Queries.PeoplePastQuery["people"]["group"][number]["nodes"][number]["data"] > +type LinkedIdentity = NonNullable[number] + +type MutablePerson = { + -readonly [P in keyof Person]: Person[P]; +}; + const PeoplePastPage = ({ data }: PeoplePastProps) => { function makePerson(person: Person) { let identities = (person.linked_identities || []).filter( @@ -55,6 +61,46 @@ const PeoplePastPage = ({ data }: PeoplePastProps) => { ) } + const handlePeople = (people: readonly { data: Person | null}[]): JSX.Element[] => { + + // dedupe identities + const filteredPeople: {data: MutablePerson}[] = people.map((p: {data: Person | null}) => { + const seen = new Set(); + const filteredIdentities = p.data?.linked_identities?.filter((identity: LinkedIdentity) => { + const data = identity!.data! + const identifier = `${data.title}-${data.start}-${data.end}`; + if (seen.has(identifier)) { + return false; + } else { + if (data.end && data.start) { + seen.add(identifier); + return true; + } + return false; + } + }) ?? []; + + // Sort them by end date + filteredIdentities.sort((a, b) => b!.data!.end! - a!.data!.end!) + + const mutablePerson: MutablePerson = { ...p.data! } as MutablePerson; + mutablePerson.linked_identities = filteredIdentities; + return { data: mutablePerson }; + }) + + // sort by end date + filteredPeople.sort((a, b) => { + const aMaxEnd = Math.max(...a!.data.linked_identities!.map(identity => identity!.data!.end || 0)); + const bMaxEnd = Math.max(...b!.data.linked_identities!.map(identity => identity!.data!.end || 0)); + return bMaxEnd - aMaxEnd; + }) + + console.log(filteredPeople) + return filteredPeople.map(p => { + return makePerson(p.data!) + }) + } + return ( @@ -83,11 +129,10 @@ const PeoplePastPage = ({ data }: PeoplePastProps) => {

{people.fieldValue}

- {people.nodes.map(p => { - return makePerson(p.data!) - })} + {handlePeople(people.nodes)}
) }) diff --git a/src/pages/people.css b/src/pages/people.css index 3eb08c80e7..054a6eaf04 100644 --- a/src/pages/people.css +++ b/src/pages/people.css @@ -8,9 +8,13 @@ letter-spacing: 1px; } @media screen and (min-width: 67em) { - #main-content section.pastpeople { + #main-content section.pastpeople, + #main-content > div section.people-group { margin-bottom: var(--content-spacing-xl); } + #main-content section.pastpeople { + margin-top: calc(var(--content-spacing-xl) * -1); + } } /* Current People */