diff options
| author | Fuwn <[email protected]> | 2023-09-06 03:54:07 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-06 03:54:07 -0700 |
| commit | fe9a191a008b2f5e4d8fece1b36d6bd3b1f068f2 (patch) | |
| tree | 51f1c5c87bb3e77c83fed1d7cba76fe375877a6e /src | |
| parent | refactor(settings): rename setting (diff) | |
| download | due.moe-fe9a191a008b2f5e4d8fece1b36d6bd3b1f068f2.tar.xz due.moe-fe9a191a008b2f5e4d8fece1b36d6bd3b1f068f2.zip | |
fix(activity): last activity check
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/AniList/activity.ts | 28 | ||||
| -rw-r--r-- | src/routes/+layout.svelte | 30 |
2 files changed, 43 insertions, 15 deletions
diff --git a/src/lib/AniList/activity.ts b/src/lib/AniList/activity.ts index 995ff6eb..aa22a590 100644 --- a/src/lib/AniList/activity.ts +++ b/src/lib/AniList/activity.ts @@ -1,23 +1,25 @@ import type { UserIdentity } from './identity'; export const lastActivityDate = async (userIdentity: UserIdentity): Promise<Date> => { - const activityHistory = await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json' - }, - body: JSON.stringify({ - query: `{ Activity(userId: ${userIdentity.id}, type: MEDIA_LIST, sort: ID_DESC) { - __typename ... on ListActivity { createdAt } + const activityHistory = ( + await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `{ User(id: ${userIdentity.id}) { + stats { activityHistory { date } } } }` + }) }) - }) - ).json(); + ).json() + )['data']['User']['stats']['activityHistory']; const date = new Date(0); - date.setUTCSeconds(activityHistory['data']['Activity']['createdAt']); + date.setUTCSeconds(activityHistory[activityHistory.length - 1]['date']); return date; }; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index a11ea3ee..15073db3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -28,9 +28,32 @@ currentUserIdentity = JSON.parse($userIdentity); currentUserIdentity.name = currentUserIdentity.name; lastActivityWasToday = - (await lastActivityDate(currentUserIdentity)).toDateString() === new Date().toDateString(); + (await lastActivityDate(currentUserIdentity)).toDateString() >= new Date().toDateString(); } }); + + const timeLeftToday = () => { + const now = new Date(); + const currentHour = now.getHours(); + const currentMinute = now.getMinutes(); + const hoursLeft = 24 - currentHour; + let minutesLeft = 0; + let timeLeft = ''; + + if (hoursLeft > 0) { + minutesLeft = hoursLeft * 60 - currentMinute; + } else { + minutesLeft = 24 * 60 - (currentHour * 60 + currentMinute); + } + + if (minutesLeft > 60) { + timeLeft = `${Math.round(minutesLeft / 60)} hours`; + } else { + timeLeft = `${minutesLeft} minutes`; + } + + return timeLeft; + }; </script> <p /> @@ -49,7 +72,10 @@ {#if !lastActivityWasToday} <p /> - <p>You don't have any new activity statuses from the past day! Create one to keep your streak!</p> + <p> + You don't have any new activity statuses from the past day! Create one within {timeLeftToday()} + to keep your streak! + </p> {/if} <p /> |