Skip to content

Commit

Permalink
filtered and sorted past people. Fix to CSS. Closes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
raffazizzi committed Jul 31, 2024
1 parent 8642e5c commit 6006279
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
51 changes: 48 additions & 3 deletions src/pages/people-past.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type Person = NonNullable<
Queries.PeoplePastQuery["people"]["group"][number]["nodes"][number]["data"]
>

type LinkedIdentity = NonNullable<Person["linked_identities"]>[number]

type MutablePerson = {
-readonly [P in keyof Person]: Person[P];
};

const PeoplePastPage = ({ data }: PeoplePastProps) => {
function makePerson(person: Person) {
let identities = (person.linked_identities || []).filter(
Expand Down Expand Up @@ -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 (
<Layout>
<SEO title="Past People" />
Expand Down Expand Up @@ -83,11 +129,10 @@ const PeoplePastPage = ({ data }: PeoplePastProps) => {
<section
id={people.fieldValue?.toLowerCase().replace(" ", "_")}
className="people-group"
key={people.fieldValue}
>
<h2>{people.fieldValue}</h2>
{people.nodes.map(p => {
return makePerson(p.data!)
})}
{handlePeople(people.nodes)}
</section>
)
})
Expand Down
6 changes: 5 additions & 1 deletion src/pages/people.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 6006279

Please sign in to comment.