aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ActivityHistory.svelte
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-25 12:42:34 -0700
committerFuwn <[email protected]>2023-09-25 12:42:34 -0700
commita6b49fa034324bca8054ea324f4fb8103fcd2c53 (patch)
treed571b56b599e62c7664229f028d5d288168c69f6 /src/lib/ActivityHistory.svelte
parentfix(settings): temporarily disable height limit (diff)
downloaddue.moe-a6b49fa034324bca8054ea324f4fb8103fcd2c53.tar.xz
due.moe-a6b49fa034324bca8054ea324f4fb8103fcd2c53.zip
refactor(history): move to tools
Diffstat (limited to 'src/lib/ActivityHistory.svelte')
-rw-r--r--src/lib/ActivityHistory.svelte90
1 files changed, 0 insertions, 90 deletions
diff --git a/src/lib/ActivityHistory.svelte b/src/lib/ActivityHistory.svelte
deleted file mode 100644
index 43dcb70d..00000000
--- a/src/lib/ActivityHistory.svelte
+++ /dev/null
@@ -1,90 +0,0 @@
-<script lang="ts">
- import { activityHistory, type ActivityHistoryEntry } from '$lib/AniList/activity.js';
- import { onMount } from 'svelte';
- import userIdentity from '../stores/userIdentity.js';
- import { userIdentity as getUserIdentity } from '$lib/AniList/identity';
-
- export let user;
-
- let activityHistoryData: Promise<ActivityHistoryEntry[]>;
- let currentUserIdentity = { name: '', id: -1 };
- const timezoneOffset = new Date().getTimezoneOffset() * 60 * 1000;
-
- 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);
- console.log(fillMissingDays(await activityHistory(currentUserIdentity)));
- }
- });
-
- const fillMissingDays = (inputActivities: ActivityHistoryEntry[]): ActivityHistoryEntry[] => {
- let activities = inputActivities;
- const firstDate = new Date(activities[0].date * 1000 + timezoneOffset);
- const lastDate = new Date(activities[activities.length - 1].date * 1000 + timezoneOffset);
- const currentDate = firstDate;
-
- while (currentDate <= lastDate) {
- const current_unix_timestamp = currentDate.getTime();
- let found = false;
-
- for (let i = 0; i < activities.length; i++) {
- if (activities[i].date * 1000 + timezoneOffset === current_unix_timestamp) {
- found = true;
-
- break;
- }
- }
-
- if (!found) {
- activities.push({
- date: current_unix_timestamp / 1000,
- amount: 0
- });
- }
-
- currentDate.setDate(currentDate.getDate() + 1);
- }
-
- // activities.sort((a: { date: number }, b: { date: number }) => a.date - b.date);
-
- return activities;
- };
-
- // 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 + timezoneOffset).toDateString()}
- </li>
- {/if}
- {/each}
- </ul>
- {/if}
- {/await}
-{/if}