Skip to content

Commit

Permalink
udpates and adds demonyms to deaths pages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandersimoes committed Dec 11, 2024
1 parent ce52de7 commit 6fbfb16
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 157 deletions.
5 changes: 1 addition & 4 deletions app/[locale]/profile/deaths/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import DeathsByMonth from "/components/deaths/DeathsByMonth";
import {BASE_API, REVALIDATE_PERIODS} from "/app/constants";

async function getPeopleDiedThisYear(yearNum) {
console.log(
`${BASE_API}/person?alive=is.false&deathdate=gte.01-01-${yearNum}&deathdate=lte.12-31-${yearNum}&select=dplace_country(id,country,slug),dplace_geonameid(id,place,slug,lat,lon),occupation(*),occupation_id:occupation,name,slug,id,hpi,hpi_prev,gender,birthyear,birthdate,deathyear,deathdate,alive&order=deathdate.asc`
);
const res = await fetch(
`${BASE_API}/person?alive=is.false&deathdate=gte.01-01-${yearNum}&deathdate=lte.12-31-${yearNum}&select=dplace_country(id,country,slug),dplace_geonameid(id,place,slug,lat,lon),occupation(*),occupation_id:occupation,name,slug,id,hpi,hpi_prev,gender,birthyear,birthdate,deathyear,deathdate,alive&order=deathdate.asc`,
`${BASE_API}/person?alive=is.false&deathdate=gte.01-01-${yearNum}&deathdate=lte.12-31-${yearNum}&select=bplace_country(demonym),dplace_country(id,country,slug),dplace_geonameid(id,place,slug,lat,lon),occupation(*),occupation_id:occupation,name,slug,id,hpi,hpi_prev,gender,birthyear,birthdate,deathyear,deathdate,alive&order=deathdate.asc`,
{
next: {revalidate: REVALIDATE_PERIODS.DEFAULT},
}
Expand Down
10 changes: 6 additions & 4 deletions components/deaths/DeathsByMonth.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {plural} from "pluralize";
import PersonImage from "/components/utils/PersonImage";
import {toTitleCase} from "/components/utils/vizHelpers";
import {FORMATTERS} from "/components/utils/consts";
import PeopleGrid from "/components/deaths/PeopleGrid";
import "../common/Section.css";
import AnchorList from "../utils/AnchorList";
import dayjs from "dayjs";
Expand Down Expand Up @@ -47,6 +44,7 @@ export default async function DeathsByMonth({year, people}) {
}
return acc;
}, {});

return (
<section className="profile-section deaths-by-month">
<h2>Deaths by Month in {year}</h2>
Expand Down Expand Up @@ -100,7 +98,11 @@ export default async function DeathsByMonth({year, people}) {
{dayjs(person.deathdate).format("MMM D, YYYY")}
</p>
<p className="person-card__occupation">
{toTitleCase(person.occupation?.occupation)}
{person.bplace_country?.demonym
? `${person.bplace_country?.demonym} ${toTitleCase(
person.occupation?.occupation
)}`
: `${toTitleCase(person.occupation?.occupation)}`}
</p>
<p className="person-card__hpi">
HPI: {person.hpi?.toFixed(2)}
Expand Down
6 changes: 5 additions & 1 deletion components/deaths/PeopleGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const PeopleGrid = ({bios}) => (
<div className="person-card__info">
<h2 className="person-card__name">{profile.name}</h2>
<h3 className="person-card__occupation">
{toTitleCase(profile.occupation.occupation)}
{profile.bplace_country?.demonym
? `${profile.bplace_country?.demonym} ${toTitleCase(
profile.occupation?.occupation
)}`
: `${toTitleCase(profile.occupation?.occupation)}`}
</h3>
<p className="person-card__dates">
<span>
Expand Down
44 changes: 22 additions & 22 deletions components/person/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ import "../../styles/mouse.css";
// return res.json();
// }

async function getIsTrending(personId) {
const dateobj = new Date();
dateobj.setDate(dateobj.getDate() - 29);
const year1monthAgo = dateobj.getFullYear();
// need to add 1 since getMonth is zero based
const month1monthAgo = `${dateobj.getMonth() + 1}`.replace(
/(^|\D)(\d)(?!\d)/g,
"$10$2"
);
const day1monthAgo = `${dateobj.getDate()}`.replace(
/(^|\D)(\d)(?!\d)/g,
"$10$2"
);
const monthAgo = `${year1monthAgo}-${month1monthAgo}-${day1monthAgo}`;
const res = await fetch(
`https://api.pantheon.world/trend?date=gte.${monthAgo}&pid=eq.${personId}&rank_pantheon=lte.100`
);
return res.json();
}
// async function getIsTrending(personId) {
// const dateobj = new Date();
// dateobj.setDate(dateobj.getDate() - 29);
// const year1monthAgo = dateobj.getFullYear();
// // need to add 1 since getMonth is zero based
// const month1monthAgo = `${dateobj.getMonth() + 1}`.replace(
// /(^|\D)(\d)(?!\d)/g,
// "$10$2"
// );
// const day1monthAgo = `${dateobj.getDate()}`.replace(
// /(^|\D)(\d)(?!\d)/g,
// "$10$2"
// );
// const monthAgo = `${year1monthAgo}-${month1monthAgo}-${day1monthAgo}`;
// const res = await fetch(
// `https://api.pantheon.world/trend?date=gte.${monthAgo}&pid=eq.${personId}&rank_pantheon=lte.100`
// );
// return res.json();
// }

export default async function Header({person}) {
// const {items: wikiPageViews} = await getWikiPageViews(person.name);
const wikiPageViews = null;
const isTrendingData = await getIsTrending(person.id);
const isTrending = !!isTrendingData.length;
// const isTrendingData = await getIsTrending(person.id);
// const isTrending = !!isTrendingData.length;

let pageViewData = null;
if (wikiPageViews) {
Expand Down Expand Up @@ -93,7 +93,7 @@ export default async function Header({person}) {
</div>
</div>
<div className="info">
{isTrending ? <div className="trending-cont">Trending</div> : null}
{/* {isTrending ? <div className="trending-cont">Trending</div> : null} */}
<h2 className="profile-type">
{person.occupation ? person.occupation.occupation : ""}
</h2>
Expand Down
Loading

0 comments on commit 6fbfb16

Please sign in to comment.