Skip to content

Commit

Permalink
Add Winnie's dairy animal quest episode (#49)
Browse files Browse the repository at this point in the history
* Add Winnie's dairy animal quest episode

* Allow for an ambassador to have multiple episodes

* New version

* Add actual video + length

* New version
  • Loading branch information
MattIPv4 authored Nov 30, 2023
1 parent 02dbb3d commit 229db29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alveusgg/data",
"version": "0.25.1",
"version": "0.26.0",
"private": true,
"license": "SEE LICENSE IN LICENSE.md",
"repository": {
Expand Down
57 changes: 33 additions & 24 deletions src/animal-quest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@ const animalQuest: Readonly<AnimalQuest[]> = [
related: [],
},
},
{
video: {
id: 1991494103,
start: "00h00m00s",
},
edition: "Dairy Edition",
description:
"Get to know Winnie, Alveus' Red Angus Beef Cow. Learn about the dairy industry and how they operate, from the life of a dairy cow to the production of dairy products. We'll also explore the impact the dairy industry has on our planet, and what we can do to help.",
broadcast: new Date("2023-11-30"),
host: "maya",
length: 2 * 60 * 60 + 10 * 60 + 30, // 00:00:00 - 02:10:30
prezi: "AM31kV6Mv82syKsoQhud",
ambassadors: {
featured: ["winnieTheMoo"],
related: [],
},
},
] as const;

export type AnimalQuestWithEpisode = AnimalQuest & {
Expand All @@ -400,37 +417,29 @@ export type AnimalQuestWithRelation = AnimalQuestWithEpisode & {
relation: "featured" | "related";
};

export const getAmbassadorEpisode = (
export const getAmbassadorEpisodes = (
ambassador: AmbassadorKey | string,
type?: "featured" | "related",
): AnimalQuestWithRelation | undefined => {
): [AnimalQuestWithRelation, ...AnimalQuestWithRelation[]] | undefined => {
if (!isAmbassadorKey(ambassador)) return undefined;

let related: AnimalQuestWithRelation | undefined;
// Find all the episodes that have the ambassador featured or related
const featured: AnimalQuestWithRelation[] = [];
const related: AnimalQuestWithRelation[] = [];
for (const [index, quest] of animalQuest.entries()) {
// If we're looking for the featured type, or any type, and find a featured, return it
if (
(!type || type === "featured") &&
quest.ambassadors.featured.includes(ambassador)
) {
return { ...quest, episode: index + 1, relation: "featured" };
}

// If we're looking for the related type, and find a related, return it
// If we're looking for any type, and find a related, store it for if we find no featured
if (
(!type || type === "related") &&
quest.ambassadors.related.includes(ambassador)
) {
if (type === "related")
return { ...quest, episode: index + 1, relation: "related" };
if (!related)
related = { ...quest, episode: index + 1, relation: "related" };
}
if (quest.ambassadors.featured.includes(ambassador))
featured.push({ ...quest, episode: index + 1, relation: "featured" });
if (quest.ambassadors.related.includes(ambassador))
related.push({ ...quest, episode: index + 1, relation: "related" });
}

// If we were looking for any type, but didn't find a featured, return the related if there is one
if (!type && related) return related;
// If we're looking for a specific type, and we found it, return it
// or, if we weren't looking for a type, return the first type we found
// [arr[0], ...arr.slice(1)] is a hack to ensure the array is not empty for TS
if ((!type || type === "featured") && featured[0])
return [featured[0], ...featured.slice(1)];
if ((!type || type === "related") && related[0])
return [related[0], ...related.slice(1)];
};

export default animalQuest;

0 comments on commit 229db29

Please sign in to comment.