Accept usernames from URL query
This commit is contained in:
parent
7846a0a895
commit
c1e1718899
@ -4,18 +4,29 @@
|
|||||||
import RowHeader from "./lib/components/table/RowHeader.svelte";
|
import RowHeader from "./lib/components/table/RowHeader.svelte";
|
||||||
import { AniList } from "./lib/services/anilist";
|
import { AniList } from "./lib/services/anilist";
|
||||||
import { formatProgress } from "./lib/utils/formatting";
|
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 searchTerm = "";
|
||||||
let onlyShowCommon = true;
|
let onlyShowCommon = true;
|
||||||
|
|
||||||
let inputUser = "";
|
let inputUser = "";
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const urlParams = new URL(window.location.href).searchParams;
|
||||||
|
const users = urlParams.getAll("users[]");
|
||||||
|
users.forEach(loadUser);
|
||||||
|
});
|
||||||
|
|
||||||
function hotEncode(index, data) {
|
function hotEncode(index, data) {
|
||||||
return index.map((idx) => data[idx] ?? null);
|
return index.map((idx) => data[idx] ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processUser(userName: string, mediaList: MediaListCollection) {
|
function processUser(username: string, mediaList: MediaListCollection) {
|
||||||
tableIndex.update((old) => [...old, userName]);
|
tableIndex.update((old) => [...old, username]);
|
||||||
|
|
||||||
for (const list of mediaList.lists) {
|
for (const list of mediaList.lists) {
|
||||||
for (const listEntry of list.entries) {
|
for (const listEntry of list.entries) {
|
||||||
@ -26,20 +37,22 @@
|
|||||||
progress: {},
|
progress: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
row.progress[userName] = listEntry.progress;
|
row.progress[username] = listEntry.progress;
|
||||||
|
|
||||||
table.update((map) => map.set(rowId, row));
|
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() {
|
async function handleAddUser() {
|
||||||
if (inputUser.length === 0) return;
|
if (inputUser.length === 0) return;
|
||||||
const { error, data } = await AniList.fetchMediaList(inputUser);
|
loadUser(inputUser);
|
||||||
|
|
||||||
const resp = await data.json();
|
|
||||||
processUser(inputUser, resp.data.MediaListCollection);
|
|
||||||
|
|
||||||
inputUser = "";
|
inputUser = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +60,6 @@
|
|||||||
term: searchTerm.toLowerCase(),
|
term: searchTerm.toLowerCase(),
|
||||||
onlyCommon: onlyShowCommon,
|
onlyCommon: onlyShowCommon,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const styleClasses = {
|
|
||||||
tableHeader: "text-sm font-medium text-gray-900 px-6 py-4 text-left",
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main class="w-screen min-h-screen bg-slate-50">
|
<main class="w-screen min-h-screen bg-slate-50">
|
||||||
@ -75,9 +84,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
{#each $tableIndex as userName}
|
{#each $tableIndex as username}
|
||||||
<th scope="col" class="{styleClasses.tableHeader}">
|
<th scope="col" class="{styleClasses.tableHeader}">
|
||||||
{userName}
|
{username}
|
||||||
</th>
|
</th>
|
||||||
{/each}
|
{/each}
|
||||||
<th scope="col" class="{styleClasses.tableHeader}">
|
<th scope="col" class="{styleClasses.tableHeader}">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user