diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/lib/Tools/ActivityHistory | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/lib/Tools/ActivityHistory')
| -rw-r--r-- | src/lib/Tools/ActivityHistory/Grid.svelte | 130 | ||||
| -rw-r--r-- | src/lib/Tools/ActivityHistory/Tool.svelte | 220 |
2 files changed, 175 insertions, 175 deletions
diff --git a/src/lib/Tools/ActivityHistory/Grid.svelte b/src/lib/Tools/ActivityHistory/Grid.svelte index 22d90d33..db9f3839 100644 --- a/src/lib/Tools/ActivityHistory/Grid.svelte +++ b/src/lib/Tools/ActivityHistory/Grid.svelte @@ -1,82 +1,82 @@ <script lang="ts"> - import { - fillMissingDays, - type ActivityHistoryEntry, - activityHistory - } from '$lib/Data/AniList/activity'; - import { onMount } from 'svelte'; - import userIdentity from '$stores/identity'; - import type { AniListAuthorisation } from '$lib/Data/AniList/identity'; - import { clearAllParameters } from '../../Utility/parameters'; - import Skeleton from '$lib/Loading/Skeleton.svelte'; - import tooltip from '$lib/Tooltip/tooltip'; - import LogInRestricted from '$lib/Error/LogInRestricted.svelte'; + import { + fillMissingDays, + type ActivityHistoryEntry, + activityHistory + } from '$lib/Data/AniList/activity'; + import { onMount } from 'svelte'; + import userIdentity from '$stores/identity'; + import type { AniListAuthorisation } from '$lib/Data/AniList/identity'; + import { clearAllParameters } from '../../Utility/parameters'; + import Skeleton from '$lib/Loading/Skeleton.svelte'; + import tooltip from '$lib/Tooltip/tooltip'; + import LogInRestricted from '$lib/Error/LogInRestricted.svelte'; - export let user: AniListAuthorisation; - export let activityData: ActivityHistoryEntry[] | null = null; - export let currentYear = new Date().getFullYear(); + export let user: AniListAuthorisation; + export let activityData: ActivityHistoryEntry[] | null = null; + export let currentYear = new Date().getFullYear(); - let activityHistoryData: ActivityHistoryEntry[]; - let baseHue = Math.floor(Math.random() * 360); + let activityHistoryData: ActivityHistoryEntry[]; + let baseHue = Math.floor(Math.random() * 360); - onMount(async () => { - clearAllParameters(); + onMount(async () => { + clearAllParameters(); - activityHistoryData = activityData || (await activityHistory($userIdentity)); - }); + activityHistoryData = activityData || (await activityHistory($userIdentity)); + }); - const gradientColour = (amount: number, maxAmount: number, baseHue: number) => { - const lightness = 100 - Math.round((amount / maxAmount) * 50); + const gradientColour = (amount: number, maxAmount: number, baseHue: number) => { + const lightness = 100 - Math.round((amount / maxAmount) * 50); - return `hsl(${baseHue}, 100%, ${lightness}%)`; - }; + return `hsl(${baseHue}, 100%, ${lightness}%)`; + }; </script> {#if user === undefined} - <LogInRestricted /> + <LogInRestricted /> {:else if activityHistoryData === undefined} - <Skeleton card={false} count={1} height="150px" /> + <Skeleton card={false} count={1} height="150px" /> {:else} - {@const filledActivities = fillMissingDays(activityHistoryData, false, currentYear)} - {@const highestActivity = Math.max(...filledActivities.map((activity) => activity.amount))} + {@const filledActivities = fillMissingDays(activityHistoryData, false, currentYear)} + {@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" - use:tooltip - title={`Date: ${new Date(activity.date * 1000).toLocaleDateString()}\nAmount: ${ - activity.amount - }`} - /> - {/each} - </div> + <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" + use:tooltip + title={`Date: ${new Date(activity.date * 1000).toLocaleDateString()}\nAmount: ${ + activity.amount + }`} + /> + {/each} + </div> {/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; - border-radius: 3px; - overflow: hidden; - } - .grid-item { - width: 20px; - height: 20px; - /* width: 3.25vw; */ - /* height: 3.25vw; */ - /* border: 1px solid #ccc; */ - } + .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; + border-radius: 3px; + overflow: hidden; + } + .grid-item { + width: 20px; + height: 20px; + /* width: 3.25vw; */ + /* height: 3.25vw; */ + /* border: 1px solid #ccc; */ + } </style> diff --git a/src/lib/Tools/ActivityHistory/Tool.svelte b/src/lib/Tools/ActivityHistory/Tool.svelte index aafac40d..b6e66a5e 100644 --- a/src/lib/Tools/ActivityHistory/Tool.svelte +++ b/src/lib/Tools/ActivityHistory/Tool.svelte @@ -1,116 +1,116 @@ <script lang="ts"> - import { - activityHistory, - fillMissingDays, - type ActivityHistoryEntry - } from '$lib/Data/AniList/activity'; - import { onMount } from 'svelte'; - import userIdentity from '$stores/identity'; - import type { AniListAuthorisation } from '$lib/Data/AniList/identity'; - import { clearAllParameters } from '../../Utility/parameters'; - import { domToBlob } from 'modern-screenshot'; - import ActivityHistoryGrid from './Grid.svelte'; - import SettingHint from '$lib/Settings/SettingHint.svelte'; - import Skeleton from '$lib/Loading/Skeleton.svelte'; - import LogInRestricted from '$lib/Error/LogInRestricted.svelte'; - - export let user: AniListAuthorisation; - - let activityHistoryData: Promise<ActivityHistoryEntry[]>; - let generated = false; - - onMount(async () => { - clearAllParameters(); - - if (user !== undefined) activityHistoryData = activityHistory($userIdentity); - }); - - // const incrementDate = (date: Date): Date => { - // date.setDate(date.getDate() + 1); - - // return date; - // }; - - const screenshot = async () => { - let element = document.querySelector('.grid') as HTMLElement; - - if (element !== null) { - domToBlob(element, { - quality: 1, - scale: 2 - }).then((blob) => { - const downloadWrapper = document.createElement('a'); - const image = document.createElement('img'); - const object = (window.URL || window.webkitURL || window || {}).createObjectURL(blob); - - downloadWrapper.href = object; - downloadWrapper.target = '_blank'; - image.src = object; - - downloadWrapper.appendChild(image); - - const gridFinal = document.getElementById('grid-final'); - - if (gridFinal !== null) { - gridFinal.innerHTML = ''; - - gridFinal.appendChild(downloadWrapper); - - generated = true; - } - - downloadWrapper.click(); - }); - } - }; + import { + activityHistory, + fillMissingDays, + type ActivityHistoryEntry + } from '$lib/Data/AniList/activity'; + import { onMount } from 'svelte'; + import userIdentity from '$stores/identity'; + import type { AniListAuthorisation } from '$lib/Data/AniList/identity'; + import { clearAllParameters } from '../../Utility/parameters'; + import { domToBlob } from 'modern-screenshot'; + import ActivityHistoryGrid from './Grid.svelte'; + import SettingHint from '$lib/Settings/SettingHint.svelte'; + import Skeleton from '$lib/Loading/Skeleton.svelte'; + import LogInRestricted from '$lib/Error/LogInRestricted.svelte'; + + export let user: AniListAuthorisation; + + let activityHistoryData: Promise<ActivityHistoryEntry[]>; + let generated = false; + + onMount(async () => { + clearAllParameters(); + + if (user !== undefined) activityHistoryData = activityHistory($userIdentity); + }); + + // const incrementDate = (date: Date): Date => { + // date.setDate(date.getDate() + 1); + + // return date; + // }; + + const screenshot = async () => { + let element = document.querySelector('.grid') as HTMLElement; + + if (element !== null) { + domToBlob(element, { + quality: 1, + scale: 2 + }).then((blob) => { + const downloadWrapper = document.createElement('a'); + const image = document.createElement('img'); + const object = (window.URL || window.webkitURL || window || {}).createObjectURL(blob); + + downloadWrapper.href = object; + downloadWrapper.target = '_blank'; + image.src = object; + + downloadWrapper.appendChild(image); + + const gridFinal = document.getElementById('grid-final'); + + if (gridFinal !== null) { + gridFinal.innerHTML = ''; + + gridFinal.appendChild(downloadWrapper); + + generated = true; + } + + downloadWrapper.click(); + }); + } + }; </script> {#if user === undefined} - <LogInRestricted /> + <LogInRestricted /> {:else} - {#await activityHistoryData} - <Skeleton card={false} count={5} height="0.9rem" list /> - {:then activities} - {#if activities === undefined} - <Skeleton card={false} count={5} height="0.9rem" list /> - {:else} - {@const filledActivities = fillMissingDays(activities)} - - <div class="card"> - <ActivityHistoryGrid {user} /> - - <p /> - - <div id="grid-final" /> - - {#if generated} - <p /> - {/if} - - <button on:click={screenshot}>Generate grid image</button> - </div> - - <p /> - - <details open> - <summary>Days in risk of developing an activity history hole</summary> - - <SettingHint> - Days in which you did not log any activity or only have one activity logged. - </SettingHint> - - <ul> - {#each filledActivities as activity} - {#if activity.amount === 0} - <li> - {new Date( - activity.date * 1000 + new Date().getTimezoneOffset() * 60 * 1000 - ).toDateString()} - </li> - {/if} - {/each} - </ul> - </details> - {/if} - {/await} + {#await activityHistoryData} + <Skeleton card={false} count={5} height="0.9rem" list /> + {:then activities} + {#if activities === undefined} + <Skeleton card={false} count={5} height="0.9rem" list /> + {:else} + {@const filledActivities = fillMissingDays(activities)} + + <div class="card"> + <ActivityHistoryGrid {user} /> + + <p /> + + <div id="grid-final" /> + + {#if generated} + <p /> + {/if} + + <button on:click={screenshot}>Generate grid image</button> + </div> + + <p /> + + <details open> + <summary>Days in risk of developing an activity history hole</summary> + + <SettingHint> + Days in which you did not log any activity or only have one activity logged. + </SettingHint> + + <ul> + {#each filledActivities as activity} + {#if activity.amount === 0} + <li> + {new Date( + activity.date * 1000 + new Date().getTimezoneOffset() * 60 * 1000 + ).toDateString()} + </li> + {/if} + {/each} + </ul> + </details> + {/if} + {/await} {/if} |