Skip to content

Commit 74d5822

Browse files
Moved the now playing api to the layout
1 parent f9cfc1c commit 74d5822

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/lib/shared/components/now-playing/NowPlaying.svelte

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,8 @@
5353
</style>
5454

5555
<script lang="ts">
56-
import { onDestroy, onMount } from 'svelte';
5756
import { nowPlayingSong } from '$stores';
58-
import ExternalLink from '$lib/shared/ui/components/external-link/ExternalLink.svelte';
59-
60-
let clearSetTimeout: NodeJS.Timeout;
61-
const getCurrentlyPlayingSong = (): void => {
62-
fetch(`/api/now-playing.json`)
63-
.then((res) => res.json())
64-
.then((response) => nowPlayingSong.set(response));
65-
66-
clearSetTimeout = setTimeout(getCurrentlyPlayingSong, 120000);
67-
};
68-
onMount(async () => {
69-
getCurrentlyPlayingSong();
70-
});
71-
72-
onDestroy(() => {
73-
clearTimeout(clearSetTimeout);
74-
});
57+
import ExternalLink from '$ui/components/external-link/ExternalLink.svelte';
7558
</script>
7659

7760
<div class="flex flex-row-reverse sm:flex-row mb-8 space-x-0 sm:space-x-2 w-full">

src/routes/__layout.svelte

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script lang="ts">
22
// Start: Local Imports
33
4+
import { onDestroy, onMount } from 'svelte';
5+
import { nowPlayingSong } from '$stores';
46
// Start: External Imports
5-
7+
import '../styles/tailwind.postcss';
68
79
// End: External Imports
810
@@ -58,6 +60,22 @@
5860
htmlTag.className = event.detail.dark ? 'dark' : 'light';
5961
};
6062
63+
let clearSetTimeout: NodeJS.Timeout;
64+
const getCurrentlyPlayingSong = (): void => {
65+
fetch(`/api/now-playing.json`)
66+
.then((res) => res.json())
67+
.then((response) => nowPlayingSong.set(response));
68+
69+
clearSetTimeout = setTimeout(getCurrentlyPlayingSong, 120000);
70+
};
71+
onMount(async () => {
72+
getCurrentlyPlayingSong();
73+
});
74+
75+
onDestroy(() => {
76+
clearTimeout(clearSetTimeout);
77+
});
78+
6179
// End: Local component methods
6280
</script>
6381

0 commit comments

Comments
 (0)