From 973676e1777ce9c713a5cefe5edf17008f41c17f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 7 Sep 2023 16:37:30 -0700 Subject: feat(routes): profile page --- src/lib/AniList/activity.ts | 2 +- src/lib/AniList/user.ts | 46 +++++++++++++++++++++++++++++++++++++ src/routes/@[user]/+page.server.ts | 5 ++++ src/routes/@[user]/+page.svelte | 47 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/lib/AniList/user.ts create mode 100644 src/routes/@[user]/+page.server.ts create mode 100644 src/routes/@[user]/+page.svelte (limited to 'src') diff --git a/src/lib/AniList/activity.ts b/src/lib/AniList/activity.ts index 9d30d275..0d79bf72 100644 --- a/src/lib/AniList/activity.ts +++ b/src/lib/AniList/activity.ts @@ -17,7 +17,7 @@ export const lastActivityDate = async (userIdentity: UserIdentity): Promise => { + const userData = ( + await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `{ User(name: "${username}") { + name id statistics { + anime { + count meanScore minutesWatched episodesWatched + } + manga { + count meanScore chaptersRead volumesRead + } + } + } }` + }) + }) + ).json() + )['data']['User']; + + return userData; +}; diff --git a/src/routes/@[user]/+page.server.ts b/src/routes/@[user]/+page.server.ts new file mode 100644 index 00000000..76d2d889 --- /dev/null +++ b/src/routes/@[user]/+page.server.ts @@ -0,0 +1,5 @@ +export const load = ({ params }) => { + return { + username: params.user + }; +}; diff --git a/src/routes/@[user]/+page.svelte b/src/routes/@[user]/+page.svelte new file mode 100644 index 00000000..758b52e7 --- /dev/null +++ b/src/routes/@[user]/+page.svelte @@ -0,0 +1,47 @@ + + +{#await user(data.username)} + Loading ... +{:then profile} + {#if profile === null} + Could not load user profile for @{data.username}. + +

+ + Does this user exist? + {:else} + @{profile.name} + +

+ + This user has watched {(profile.statistics.anime.minutesWatched / 60 / 24).toFixed(1)} days of anime + and read + {((profile.statistics.manga.chaptersRead * 8.58) / 60 / 24).toFixed(1)} days of manga. + {/if} +{:catch} + Could not load user profile for @{data.username}. + +

+ + Does this user exist? +{/await} + +

+ +


+ +This page is under construction! -- cgit v1.2.3