Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Issue 4, Button to random episode (#12)
Browse files Browse the repository at this point in the history
* Issue 4, Button to random episode

* Changed to button

* Removed ?randomEpisode query param

* Changed getRandomEpisode to use randomElement

Co-authored-by: David Quezada <davidquezada@David-Quezadas-MacBook-Pro.local>
Co-authored-by: Kalle Jillheden <kalle.jillheden@gmail.com>
  • Loading branch information
3 people authored Nov 9, 2021
1 parent a4204d4 commit be4408e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/libs/episodes-repo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { LinkOrHref } from "./link";
import { randomElement } from "./util";

export interface EpisodeRawData {
readonly id: string;
Expand Down Expand Up @@ -42,6 +43,10 @@ export function getEpisodeByNumber(episodeNumber: string): EpisodeData {
return episodeMapByNumber.get(episodeNumber);
}

export function getRandomEpisode(): EpisodeData {
return randomElement(episodeDatas);
}

export function getAllEpisodeData(): EpisodeData[] {
return episodeDatas;
}
Expand Down
13 changes: 12 additions & 1 deletion src/sections/EpisodeListSection.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<script lang="ts">
import Section from "./base/Section.svelte";
import { getAllEpisodeData } from "../libs/episodes-repo";
import { getAllEpisodeData, getRandomEpisode } from "../libs/episodes-repo";
import Link from "../Link.svelte";
import { navigate } from "../libs/util";
export let currentEpisodeId: string = null;
function onClickRandomEpisode() {
const epi = getRandomEpisode();
navigate(`?episode=${epi.number}`);
}
</script>

<Section title="Episodes">
Expand All @@ -17,6 +23,11 @@
{/if}
</li>
{/each}
<li>
<button class="link" on:click={onClickRandomEpisode}
>??: Random episode</button
>
</li>
</ol>
</Section>

Expand Down

0 comments on commit be4408e

Please sign in to comment.