Skip to content

Commit

Permalink
Use de-duplicated species data methods
Browse files Browse the repository at this point in the history
Re alveusgg/data#87

Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Dec 25, 2024
1 parent 58b8876 commit bd34de6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
10 changes: 5 additions & 5 deletions apps/website/src/components/content/AnimalQuest.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { type ComponentProps } from "react";
import Image from "next/image";
import {
type AnimalQuestWithEpisode,
type AnimalQuestWithRelation,
} from "@alveusgg/data/src/animal-quest";
import { type Ambassador } from "@alveusgg/data/src/ambassadors/core";

import { sentenceToKebab } from "@/utils/string-case";
import { classes } from "@/utils/classes";
Expand All @@ -15,6 +10,11 @@ import Heading from "@/components/content/Heading";
import Link from "@/components/content/Link";

import animalQuestImage from "@/assets/animal-quest/full.png";
import { type Ambassador } from "../../../../../../data/src/ambassadors/core";
import {
type AnimalQuestWithEpisode,
type AnimalQuestWithRelation,
} from "../../../../../../data/src/animal-quest";

type AnimalQuestProps = {
episode: AnimalQuestWithEpisode;
Expand Down
63 changes: 34 additions & 29 deletions apps/website/src/pages/ambassadors/[ambassadorName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@ import Image from "next/image";
import PhotoSwipeLightbox from "photoswipe/lightbox";
import { useEffect, useId, useMemo, Fragment } from "react";

import ambassadors, {
type Ambassador,
} from "@alveusgg/data/src/ambassadors/core";
import { isActiveAmbassadorKey } from "@alveusgg/data/src/ambassadors/filters";
import {
getAmbassadorImages,
getAmbassadorMerchImage,
getAmbassadorIconImage,
type AmbassadorImage,
type AmbassadorImages,
} from "@alveusgg/data/src/ambassadors/images";
import {
getAmbassadorEpisodes,
type AnimalQuestWithRelation,
} from "@alveusgg/data/src/animal-quest";
import enclosures, { type Enclosure } from "@alveusgg/data/src/enclosures";
import { getIUCNStatus } from "@alveusgg/data/src/iucn";
import { getClassification } from "@alveusgg/data/src/ambassadors/classification";

import Section from "@/components/content/Section";
import Heading from "@/components/content/Heading";
Expand All @@ -35,6 +17,27 @@ import { getDefaultPhotoswipeLightboxOptions } from "@/utils/photoswipe";
import { typeSafeObjectKeys } from "@/utils/helpers";
import { convertToSlug } from "@/utils/slugs";
import { formatPartialDateString } from "@/utils/datetime";
import { getClassification } from "../../../../../../data/src/ambassadors/classification";
import { getIUCNStatus } from "../../../../../../data/src/iucn";
import enclosures, {
type Enclosure,
} from "../../../../../../data/src/enclosures";
import {
getAmbassadorEpisodes,
type AnimalQuestWithRelation,
} from "../../../../../../data/src/animal-quest";
import {
getAmbassadorImages,
getAmbassadorMerchImage,
getAmbassadorIconImage,
type AmbassadorImage,
type AmbassadorImages,
} from "../../../../../../data/src/ambassadors/images";
import { isActiveAmbassadorKey } from "../../../../../../data/src/ambassadors/filters";
import ambassadors, {
type Ambassador,
} from "../../../../../../data/src/ambassadors/core";
import { getSpecies } from "../../../../../../data/src/ambassadors/species";

type AmbassadorPageProps = {
ambassador: Ambassador;
Expand Down Expand Up @@ -90,15 +93,17 @@ const AmbassadorPage: NextPage<AmbassadorPageProps> = ({
iconImage,
animalQuest,
}) => {
const species = getSpecies(ambassador.species);

const stats = useMemo(
() => [
{
title: "Species",
value: (
<>
<p>{ambassador.species}</p>
<p>{species.name}</p>
<p className="italic text-alveus-green-700">
{ambassador.scientific} (
{species.scientificName} (
<Link
href={`/ambassadors#classification:${convertToSlug(
getClassification(ambassador.class),
Expand All @@ -115,37 +120,37 @@ const AmbassadorPage: NextPage<AmbassadorPageProps> = ({
title: "Conservation Status",
value: (
<p>
{ambassador.iucn.id ? (
{species.iucn.id ? (
<Link
href={`https://apiv3.iucnredlist.org/api/v3/taxonredirect/${ambassador.iucn.id}`}
href={`https://apiv3.iucnredlist.org/api/v3/taxonredirect/${species.iucn.id}`}
external
>
IUCN: {getIUCNStatus(ambassador.iucn.status)}
IUCN: {getIUCNStatus(species.iucn.status)}
</Link>
) : (
<>IUCN: {getIUCNStatus(ambassador.iucn.status)}</>
<>IUCN: {getIUCNStatus(species.iucn.status)}</>
)}
</p>
),
},
{
title: "Native To",
value: <p>{ambassador.native.text}</p>,
value: <p>{species.native.text}</p>,
},
{
title: "Species Lifespan",
value: (
<>
<p>
Wild:{" "}
{ambassador.lifespan.wild
? `${stringifyLifespan(ambassador.lifespan.wild)} years`
{species.lifespan.wild
? `${stringifyLifespan(species.lifespan.wild)} years`
: "Unknown"}
</p>
<p>
Captivity:{" "}
{ambassador.lifespan.captivity
? `${stringifyLifespan(ambassador.lifespan.captivity)} years`
{species.lifespan.captivity
? `${stringifyLifespan(species.lifespan.captivity)} years`
: "Unknown"}
</p>
</>
Expand Down
20 changes: 11 additions & 9 deletions apps/website/src/pages/ambassadors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import Image from "next/image";
import Link from "next/link";
import { useMemo, type ComponentProps } from "react";

import ambassadors from "@alveusgg/data/src/ambassadors/core";
import { isActiveAmbassadorEntry } from "@alveusgg/data/src/ambassadors/filters";
import { getAmbassadorImages } from "@alveusgg/data/src/ambassadors/images";
import enclosures from "@alveusgg/data/src/enclosures";
import {
getClassification,
sortAmbassadorClassification,
} from "@alveusgg/data/src/ambassadors/classification";

import useGrouped, { type GroupedItems, type Options } from "@/hooks/grouped";

Expand All @@ -34,6 +26,15 @@ import leafRightImage1 from "@/assets/floral/leaf-right-1.png";
import leafLeftImage1 from "@/assets/floral/leaf-left-1.png";
import leafRightImage2 from "@/assets/floral/leaf-right-2.png";
import leafLeftImage2 from "@/assets/floral/leaf-left-2.png";
import {
getClassification,
sortAmbassadorClassification,
} from "../../../../../../data/src/ambassadors/classification";
import enclosures from "../../../../../../data/src/enclosures";
import { getAmbassadorImages } from "../../../../../../data/src/ambassadors/images";
import { isActiveAmbassadorEntry } from "../../../../../../data/src/ambassadors/filters";
import ambassadors from "../../../../../../data/src/ambassadors/core";
import { getSpecies } from "../../../../../../data/src/ambassadors/species";

// We don't want to show retired ambassadors on the page
const activeAmbassadors = typeSafeObjectEntries(ambassadors).filter(
Expand Down Expand Up @@ -114,6 +115,7 @@ const AmbassadorItem = ({
level?: ComponentProps<typeof Heading>["level"];
}) => {
const [key, data] = ambassador;
const species = getSpecies(data.species);
const images = useMemo(() => getAmbassadorImages(key), [key]);

return (
Expand All @@ -134,7 +136,7 @@ const AmbassadorItem = ({
{data.name}
</Heading>
<p className="text-center text-xl text-alveus-green-700 transition-colors group-hover:text-alveus-green-400">
{data.species}
{species.name}
</p>
</Link>
</div>
Expand Down

0 comments on commit bd34de6

Please sign in to comment.