From c1e17188995c393869c8c18f50731256075375c0 Mon Sep 17 00:00:00 2001 From: strNophix Date: Sat, 28 Jan 2023 17:18:10 +0100 Subject: [PATCH] Accept usernames from URL query --- src/App.svelte | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index e8926b9..6525203 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4,18 +4,29 @@ import RowHeader from "./lib/components/table/RowHeader.svelte"; import { AniList } from "./lib/services/anilist"; import { formatProgress } from "./lib/utils/formatting"; + import { onMount } from "svelte"; + + const styleClasses = { + tableHeader: "text-sm font-medium text-gray-900 px-6 py-4 text-left", + }; let searchTerm = ""; let onlyShowCommon = true; let inputUser = ""; + onMount(async () => { + const urlParams = new URL(window.location.href).searchParams; + const users = urlParams.getAll("users[]"); + users.forEach(loadUser); + }); + function hotEncode(index, data) { return index.map((idx) => data[idx] ?? null); } - function processUser(userName: string, mediaList: MediaListCollection) { - tableIndex.update((old) => [...old, userName]); + function processUser(username: string, mediaList: MediaListCollection) { + tableIndex.update((old) => [...old, username]); for (const list of mediaList.lists) { for (const listEntry of list.entries) { @@ -26,20 +37,22 @@ progress: {}, }; - row.progress[userName] = listEntry.progress; + row.progress[username] = listEntry.progress; table.update((map) => map.set(rowId, row)); } } } + async function loadUser(username: string) { + const { error, data } = await AniList.fetchMediaList(username); + const resp = await data.json(); + processUser(username, resp.data.MediaListCollection); + } + async function handleAddUser() { if (inputUser.length === 0) return; - const { error, data } = await AniList.fetchMediaList(inputUser); - - const resp = await data.json(); - processUser(inputUser, resp.data.MediaListCollection); - + loadUser(inputUser); inputUser = ""; } @@ -47,10 +60,6 @@ term: searchTerm.toLowerCase(), onlyCommon: onlyShowCommon, })); - - const styleClasses = { - tableHeader: "text-sm font-medium text-gray-900 px-6 py-4 text-left", - };
@@ -75,9 +84,9 @@ - {#each $tableIndex as userName} + {#each $tableIndex as username} - {userName} + {username} {/each}