diff options
| author | Fuwn <[email protected]> | 2023-09-22 23:48:39 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-22 23:48:39 -0700 |
| commit | 2caef2c1723801e6145331003e7b430e9772b65a (patch) | |
| tree | dfaa9a361c503bbb5a6de8a18ecb3d083d3d8d37 /src/lib | |
| parent | feat(layout): tools in navbar (diff) | |
| download | due.moe-2caef2c1723801e6145331003e7b430e9772b65a.tar.xz due.moe-2caef2c1723801e6145331003e7b430e9772b65a.zip | |
feat(tools): move activity history
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ActivityHistory.svelte | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/lib/ActivityHistory.svelte b/src/lib/ActivityHistory.svelte new file mode 100644 index 00000000..43dcb70d --- /dev/null +++ b/src/lib/ActivityHistory.svelte @@ -0,0 +1,90 @@ +<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} |