aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/ActivityHistory.svelte
blob: a8f3c45bdca07455f528107ba54470f6bc493277 (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
<script lang="ts">
	import {
		activityHistory,
		fillMissingDays,
		type ActivityHistoryEntry
	} from '$lib/AniList/activity.js';
	import { onMount } from 'svelte';
	import userIdentity from '../../stores/userIdentity.js';
	import {
		userIdentity as getUserIdentity,
		type AniListAuthorisation
	} from '$lib/AniList/identity';

	export let user: AniListAuthorisation;

	let activityHistoryData: Promise<ActivityHistoryEntry[]>;
	let currentUserIdentity = { name: '', id: -1 };

	onMount(async () => {
		if (user !== undefined) {
			if ($userIdentity === '') {
				userIdentity.set(JSON.stringify(await getUserIdentity(user)));
			}

			currentUserIdentity = JSON.parse($userIdentity);
			currentUserIdentity.name = currentUserIdentity.name;
			activityHistoryData = activityHistory(currentUserIdentity);
		}
	});

	// const incrementDate = (date: Date): Date => {
	// 	date.setDate(date.getDate() + 1);

	// 	return date;
	// };
</script>

<blockquote>
	Days in risk of developing an activity history hole. (days with one activity)
</blockquote>

{#if user === undefined}
	Please log in to view this page.
{:else}
	{#await activityHistoryData}
		Loading ...
	{:then activities}
		{#if activities === undefined}
			Loading ...
		{:else}
			<ul>
				{#each fillMissingDays(activities) as activity}
					{#if activity.amount === 0}
						<li>
							{new Date(
								activity.date * 1000 + new Date().getTimezoneOffset() * 60 * 1000
							).toDateString()}
						</li>
					{/if}
				{/each}
			</ul>
		{/if}
	{/await}
{/if}