aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/SequelSpy.svelte
blob: 2aaa5f60dbf1710659f2400693af4217b242898a (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
<script lang="ts">
	import type { AniListAuthorisation } from '$lib/Data/AniList/identity';
	import { prequels, type MediaPrequel } from '$lib/Data/AniList/prequels';
	import MediaTitle from '$lib/List/MediaTitleDisplay.svelte';
	import { onMount } from 'svelte';
	import { clearAllParameters, parseOrDefault } from '../Utility/parameters';
	import { airingTime } from '$lib/Media/Anime/Airing/time';
	import type { Media } from '$lib/Data/AniList/media';
	import { page } from '$app/stores';
	import { browser } from '$app/environment';
	import { season as getSeason } from '$lib/Media/Anime/season';
	import Skeleton from '$lib/Loading/Skeleton.svelte';
	import identity from '$stores/identity';
	import LogInRestricted from '$lib/Error/LogInRestricted.svelte';
	import tooltip from '$lib/Tooltip/tooltip';

	export let user: AniListAuthorisation;

	let currentPrequels: Promise<MediaPrequel[]> = Promise.resolve([]) as Promise<MediaPrequel[]>;
	const urlParameters = browser ? new URLSearchParams(window.location.search) : null;
	let year = parseOrDefault(urlParameters, 'year', new Date().getFullYear());
	let season = parseOrDefault(urlParameters, 'season', getSeason());

	$: {
		if (year.toString().length === 4 && $identity.id !== -2 && user)
			currentPrequels = prequels(user, year, season);
	}
	$: {
		if (browser) {
			$page.url.searchParams.set('year', year.toString());
			$page.url.searchParams.set('season', season.toString());
			clearAllParameters(['year', 'season']);
			history.replaceState(null, '', `?${$page.url.searchParams.toString()}`);
		}
	}

	onMount(() => clearAllParameters(['year', 'season']));

	const prequelAiringTime = (prequel: MediaPrequel) =>
		airingTime(prequel as unknown as Media, null, false, true);
</script>

{#if user === undefined || $identity.id === -2}
	<LogInRestricted />
{:else}
	<div class="card">
		<p>
			<select bind:value={season}>
				<option value="WINTER">Winter</option>
				<option value="SPRING">Spring</option>
				<option value="SUMMER">Summer</option>
				<option value="FALL">Fall</option>
			</select>
			<input type="number" bind:value={year} />
		</p>

		{#await currentPrequels}
			<Skeleton card={false} count={5} height="0.9rem" list />
		{:then currentPrequels}
			<ul>
				{#each currentPrequels.sort((a, b) => new Date(a.startDate.year, a.startDate.month - 1, a.startDate.day).getTime() - new Date(b.startDate.year, b.startDate.month - 1, b.startDate.day).getTime()) as prequel}
					<li>
						<a
							href={`https://anilist.co/anime/${prequel.id}`}
							target="_blank"
							title={`<img src="${prequel.coverImage.extraLarge}" style="width: 250px; object-fit: cover; border-radius: 8px;" />`}
							use:tooltip
						>
							<MediaTitle title={prequel.title} />
						</a>
						<span class="opaque">|</span>
						{prequel.seen}<span class="opaque">/{prequel.episodes}</span>
						{@html prequelAiringTime(prequel)}
					</li>
				{/each}
			</ul>
		{/await}

		<p />

		The count ratio is the number of episodes you've seen of any direct prequels, and the total
		number of episodes of all direct prequels.
	</div>
{/if}