From 8f6e0b759cbdbb94b152f1af0637bc2206abe315 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 29 Sep 2023 17:14:21 -0700
Subject: refactor(list): move to respective modules

---
 src/lib/List/Completed/WatchingAnimeList.svelte | 53 +++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 src/lib/List/Completed/WatchingAnimeList.svelte

(limited to 'src/lib/List/Completed/WatchingAnimeList.svelte')

diff --git a/src/lib/List/Completed/WatchingAnimeList.svelte b/src/lib/List/Completed/WatchingAnimeList.svelte
new file mode 100644
index 00000000..da48c32d
--- /dev/null
+++ b/src/lib/List/Completed/WatchingAnimeList.svelte
@@ -0,0 +1,53 @@
+<script lang="ts">
+	import { mediaListCollection, Type, type Media } from '$lib/AniList/media';
+	import type { UserIdentity, AniListAuthorisation } from '$lib/AniList/identity';
+	import { onMount } from 'svelte';
+	import anime from '../../../stores/anime';
+	import lastPruneTimes from '../../../stores/lastPruneTimes';
+	import settings from '../../../stores/settings';
+	import AnimeList from '../Template/AnimeListTemplate.svelte';
+
+	export let user: AniListAuthorisation;
+	export let identity: UserIdentity;
+
+	let animeLists: Promise<Media[]>;
+	let startTime: number;
+	let endTime: number;
+
+	onMount(async () => {
+		startTime = performance.now();
+		animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $lastPruneTimes.anime);
+	});
+
+	const cleanMedia = (media: Media[]) => {
+		if (media === undefined) {
+			return [];
+		}
+
+		const releasingMedia = media.filter(
+			(media: Media) =>
+				media.status === 'FINISHED' &&
+				(media.mediaListEntry || { status: 'DROPPED' }).status != 'DROPPED' &&
+				(media.mediaListEntry || { status: 'DROPPED' }).status !=
+					($settings.displayPausedMedia ? '' : 'PAUSED') &&
+				(media.mediaListEntry || { progress: 0 }).progress >= ($settings.displayNotStarted ? 0 : 1)
+		);
+		let finalMedia = releasingMedia;
+
+		finalMedia.sort((a: Media, b: Media) => {
+			const difference = (anime: Media) => {
+				return anime.episodes - (anime.mediaListEntry || { progress: 0 }).progress;
+			};
+
+			return difference(a) - difference(b);
+		});
+
+		if (!endTime) {
+			endTime = performance.now() - startTime;
+		}
+
+		return finalMedia;
+	};
+</script>
+
+<AnimeList {endTime} {cleanMedia} {animeLists} {user} {identity} title="Completed Anime" />
-- 
cgit v1.2.3

