1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
<script lang="ts">
import { mediaListCollection, Type, type Media } from '$lib/Data/AniList/media';
import type { AniListAuthorisation } from '$lib/Data/AniList/identity';
import { onMount } from 'svelte';
import anime from '$stores/anime';
import lastPruneTimes from '$stores/lastPruneTimes';
import settings from '$stores/settings';
import AnimeList from './AnimeListTemplate.svelte';
import { getNotificationsContext } from 'svelte-notifications';
import locale from '$stores/locale';
import identity from '$stores/identity';
import sampleAnime from '$lib/Data/Static/SampleMedia/anime.json';
export let user: AniListAuthorisation = {
accessToken: '',
refreshToken: '',
expiresIn: 0,
tokenType: ''
};
export let dummy = false;
const { addNotification } = getNotificationsContext();
let animeLists: Promise<Media[]>;
let startTime: number;
let endTime: number;
onMount(async () => {
startTime = performance.now();
if (dummy) {
animeLists = Promise.resolve(
sampleAnime
.filter(
(anime) =>
anime.episodes &&
!anime.tags.some((tag) => tag.name === 'Nudity') &&
!anime.tags.some((tag) => tag.name === 'Rape') &&
!anime.tags.some((tag) => tag.name === 'Tragedy') &&
!anime.tags.some((tag) => tag.name === 'Bondage') &&
!anime.genres.some((genre) => genre === 'Hentai') &&
anime.genres.some((genre) => genre === 'Comedy') &&
anime.status !== 'NOT_YET_RELEASED' &&
anime.episodes > 1
)
.sort(() => 0.5 - Math.random())
.map((anime) => {
anime.mediaListEntry.progress = Math.floor(Math.random() * (anime.episodes || 0)) + 1;
anime.status = 'FINISHED';
return anime;
})
.slice(0, 7) as unknown as Media[]
);
} else {
animeLists = mediaListCollection(user, $identity, Type.Anime, $anime, $lastPruneTimes.anime, {
addNotification
});
}
});
const cleanMedia = (anime: Media[]) => {
if (anime && dummy) return anime;
if (anime === undefined) return [];
const outdatedCompletedAnime = anime.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)
);
outdatedCompletedAnime.sort((a: Media, b: Media) => {
const difference = (anime: Media) =>
anime.episodes - (anime.mediaListEntry || { progress: 0 }).progress;
return difference(a) - difference(b);
});
if (!endTime) endTime = performance.now() - startTime;
return outdatedCompletedAnime;
};
</script>
<AnimeList
{endTime}
{cleanMedia}
bind:animeLists
{user}
title={$locale().lists.completed.anime}
completed
{dummy}
/>
|