aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/SequelCatcher.svelte
blob: 5d7cf81a61b435069456f426e9516405502e8b26 (plain) (blame)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<script lang="ts">
	import type { AniListAuthorisation } from '$lib/Data/AniList/identity';
	import userIdentity from '$stores/identity';
	import { filterRelations, type Media, mediaListCollection, Type } from '$lib/Data/AniList/media';
	import LogInRestricted from '$lib/Error/LogInRestricted.svelte';
	import anime from '$stores/anime';
	import identity from '$stores/identity';
	import { onMount } from 'svelte';
	import lastPruneTimes from '$stores/lastPruneTimes';
	import MediaTitleDisplay from '$lib/List/MediaTitleDisplay.svelte';
	import { outboundLink } from '$lib/Media/links';
	import settings from '$stores/settings';
	import Message from '$lib/Loading/Message.svelte';
	import Skeleton from '$lib/Loading/Skeleton.svelte';
	import Username from '$lib/Layout/Username.svelte';

	export let user: AniListAuthorisation;

	let mediaList: Promise<Media[]>;

	onMount(async () => {
		if (user === undefined || $identity.id === -2) return;

		mediaList = mediaListCollection(
			user,
			$userIdentity,
			Type.Anime,
			$anime,
			$lastPruneTimes.anime,
			{
				forcePrune: true,
				includeCompleted: true,
				all: true,
				includeRelations: true
			}
		);
	});
</script>

{#if user === undefined || $identity.id === -2}
	<LogInRestricted />
{:else}
	<div class="card">
		{#await mediaList}
			<Message message="Cross-checking media ..." />

			<Skeleton
				card={false}
				count={8}
				pad={false}
				height={'0.9rem'}
				width={'100%'}
				list
				grid={false}
			/>
		{:then mediaListUnchecked}
			{#if mediaListUnchecked}
				{@const mediaList = mediaListUnchecked.filter(
					(media) => media.mediaListEntry?.status === 'COMPLETED'
				)}

				<ol class="media-list">
					{#each filterRelations(mediaList) as { media, unwatchedRelations }}
						<a
							href={outboundLink(media, 'anime', $settings.displayOutboundLinksTo)}
							target="_blank"
						>
							<MediaTitleDisplay title={media.title} />
						</a>
						<span class="opaque">
							({media.startDate.year})
						</span>

						<ol class="unwatched-relations-list">
							{#each unwatchedRelations as relation}
								<li>
									<a
										href={outboundLink(relation.node, 'anime', $settings.displayOutboundLinksTo)}
										target="_blank"
									>
										<MediaTitleDisplay title={relation.node.title} />
									</a>
									<span class="opaque">
										({relation.node.startDate.year})
									</span>
								</li>
							{/each}
						</ol>
					{/each}
				</ol>
			{:else}
				<Message message="Cross-checking media ..." />

				<Skeleton
					card={false}
					count={8}
					pad={false}
					height={'0.9rem'}
					width={'100%'}
					list
					grid={false}
				/>
			{/if}
		{:catch}
			<Message message="" loader="ripple" slot withReload fullscreen>Error fetching media.</Message>
		{/await}

		<p />

		<blockquote style="margin: 0 0 0 1.5rem;">
			Thanks to <Username username="sevengirl" /> and <Username username="esthereae" /> for the idea!
		</blockquote>
	</div>
{/if}

<style>
	.media-list li {
		margin-bottom: 1rem;
	}

	.unwatched-relations-list li:not(:last-child) {
		margin-bottom: 0 !important;
	}
</style>