diff options
| author | Fuwn <[email protected]> | 2023-12-17 22:32:25 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-17 22:32:25 -0800 |
| commit | 5fa05c2e19e537bf092f4f2dbd12049227c39a04 (patch) | |
| tree | c06f51596c3a715e1165b3650a11a291ff6d73aa /src/lib/Tools/ActivityHistoryGrid.svelte | |
| parent | fix(activities): fill missing dates (diff) | |
| download | due.moe-5fa05c2e19e537bf092f4f2dbd12049227c39a04.tar.xz due.moe-5fa05c2e19e537bf092f4f2dbd12049227c39a04.zip | |
feat(wrapped): activity history panel
Diffstat (limited to 'src/lib/Tools/ActivityHistoryGrid.svelte')
| -rw-r--r-- | src/lib/Tools/ActivityHistoryGrid.svelte | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/Tools/ActivityHistoryGrid.svelte b/src/lib/Tools/ActivityHistoryGrid.svelte new file mode 100644 index 00000000..289afc01 --- /dev/null +++ b/src/lib/Tools/ActivityHistoryGrid.svelte @@ -0,0 +1,96 @@ +<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'; + import { clearAllParameters } from './tool.js'; + + export let user: AniListAuthorisation; + + let activityHistoryData: Promise<ActivityHistoryEntry[]>; + let currentUserIdentity = { name: '', id: -1 }; + let baseHue = Math.floor(Math.random() * 360); + + onMount(async () => { + clearAllParameters(); + + 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; + // }; + + const gradientColour = (amount: number, maxAmount: number, baseHue: number) => { + const lightness = 100 - Math.round((amount / maxAmount) * 50); + + return `hsl(${baseHue}, 100%, ${lightness}%)`; + }; +</script> + +{#if user === undefined} + Please log in to view this page. +{:else} + {#await activityHistoryData} + Loading ... + {:then activities} + {#if activities === undefined} + Loading ... + {:else} + {@const filledActivities = fillMissingDays(activities)} + {@const highestActivity = Math.max(...filledActivities.map((activity) => activity.amount))} + + <div class="grid"> + {#each filledActivities as activity} + <div + class="grid-item" + style="background-color: {gradientColour(activity.amount, highestActivity, baseHue)}" + on:click={() => (baseHue = Math.floor(Math.random() * 360))} + on:keydown={() => { + return; + }} + role="button" + tabindex="0" + title={`Date: ${new Date(activity.date * 1000).toLocaleDateString()}\nAmount: ${ + activity.amount + }`} + /> + {/each} + </div> + {/if} + {/await} +{/if} + +<style> + .grid { + display: grid; + grid-template-columns: repeat(52, 1fr); + grid-template-rows: repeat(7, 1fr); + /* gap: 2px; */ + grid-auto-flow: column; + width: min-content; + background-color: white; + } + .grid-item { + width: 20px; + height: 20px; + /* width: 3.25vw; */ + /* height: 3.25vw; */ + /* border: 1px solid #ccc; */ + } +</style> |