aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-10 02:15:56 -0700
committerFuwn <[email protected]>2023-09-10 02:15:56 -0700
commitc81e430c62459255fe02a75d3794860acd02c3b8 (patch)
tree46e2af1d8ba95b61d59b5b76eeac187582a2d764 /src/lib
parentrefactor(anime): generalise clean cache (diff)
downloaddue.moe-c81e430c62459255fe02a75d3794860acd02c3b8.tar.xz
due.moe-c81e430c62459255fe02a75d3794860acd02c3b8.zip
refactor(anime): generalise update media
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/List/Due/AnimeList.svelte18
-rw-r--r--src/lib/List/WatchingAnimeList.svelte18
-rw-r--r--src/lib/anime.ts4
3 files changed, 24 insertions, 16 deletions
diff --git a/src/lib/List/Due/AnimeList.svelte b/src/lib/List/Due/AnimeList.svelte
index 66a26712..b6d6f9ef 100644
--- a/src/lib/List/Due/AnimeList.svelte
+++ b/src/lib/List/Due/AnimeList.svelte
@@ -7,7 +7,7 @@
import anime from '../../../stores/anime';
import settings from '../../../stores/settings';
import lastPruneTimes from '../../../stores/lastPruneTimes';
- import { airingTime, cleanCache, totalEpisodes } from '$lib/anime';
+ import { airingTime, cleanCache, totalEpisodes, updateMedia } from '$lib/anime';
export let user: AniListAuthorisation;
export let identity: UserIdentity;
@@ -104,12 +104,6 @@
return finalMedia;
};
-
- const updateMedia = async (id: number, progress: number | undefined) => {
- fetch(`/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
- animeLists = cleanCache(user, identity);
- });
- };
</script>
{#await animeLists}
@@ -150,7 +144,15 @@
</a>
<span style="opacity: 50%;">|</span>
{(anime.mediaListEntry || { progress: 0 }).progress}{@html totalEpisodes(anime)}
- <a href={'#'} on:click={() => updateMedia(anime.id, anime.mediaListEntry?.progress)}>+</a>
+ <a
+ href={'#'}
+ on:click={() =>
+ updateMedia(
+ anime.id,
+ anime.mediaListEntry?.progress,
+ () => (animeLists = cleanCache(user, identity))
+ )}>+</a
+ >
[{anime.nextAiringEpisode?.episode === -1
? '?'
: (anime.nextAiringEpisode?.episode || 1) - 1}]
diff --git a/src/lib/List/WatchingAnimeList.svelte b/src/lib/List/WatchingAnimeList.svelte
index e76b1ef0..2c298488 100644
--- a/src/lib/List/WatchingAnimeList.svelte
+++ b/src/lib/List/WatchingAnimeList.svelte
@@ -7,7 +7,7 @@
import anime from '../../stores/anime';
import lastPruneTimes from '../../stores/lastPruneTimes';
import settings from '../../stores/settings';
- import { cleanCache, totalEpisodes } from '$lib/anime';
+ import { cleanCache, totalEpisodes, updateMedia } from '$lib/anime';
export let user: AniListAuthorisation;
export let identity: UserIdentity;
@@ -59,12 +59,6 @@
return finalMedia;
};
-
- const updateMedia = async (id: number, progress: number | undefined) => {
- fetch(`/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(() => {
- animeLists = cleanCache(user, identity);
- });
- };
</script>
{#await animeLists}
@@ -105,7 +99,15 @@
</a>
<span style="opacity: 50%;">|</span>
{anime.mediaListEntry?.progress || 0}{@html totalEpisodes(anime)}
- <a href={'#'} on:click={() => updateMedia(anime.id, anime.mediaListEntry?.progress)}>+</a>
+ <a
+ href={'#'}
+ on:click={() =>
+ updateMedia(
+ anime.id,
+ anime.mediaListEntry?.progress,
+ () => (animeLists = cleanCache(user, identity))
+ )}>+</a
+ >
</li>
{/each}
</ul>
diff --git a/src/lib/anime.ts b/src/lib/anime.ts
index 2ebdf25e..c9bba378 100644
--- a/src/lib/anime.ts
+++ b/src/lib/anime.ts
@@ -15,6 +15,10 @@ export const cleanCache = (user: AniListAuthorisation, identity: UserIdentity) =
);
};
+export const updateMedia = (id: number, progress: number | undefined, callback: () => void) => {
+ fetch(`/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(callback);
+};
+
export const totalEpisodes = (anime: Media) => {
return anime.episodes === null ? '' : `<span style="opacity: 50%">/${anime.episodes}</span>`;
};