From 154f92fc9f984726771d5a5b41b2e1067c8d50e4 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 29 Sep 2023 17:20:25 -0700
Subject: refactor(anime): move anime to modules

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

(limited to 'src/lib/List/Anime/CompletedAnimeList.svelte')

diff --git a/src/lib/List/Anime/CompletedAnimeList.svelte b/src/lib/List/Anime/CompletedAnimeList.svelte
new file mode 100644
index 00000000..da48c32d
--- /dev/null
+++ b/src/lib/List/Anime/CompletedAnimeList.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

