[F] Fix userbox

This commit is contained in:
Azalea
2024-12-17 20:36:01 -05:00
parent 637191836a
commit d854d8ae0b
2 changed files with 129 additions and 169 deletions

View File

@@ -8,7 +8,6 @@
import { USER, USERBOX } from "../libs/sdk"; import { USER, USERBOX } from "../libs/sdk";
import { t, ts } from "../libs/i18n"; import { t, ts } from "../libs/i18n";
import { DATA_HOST, HAS_USERBOX_ASSETS } from "../libs/config"; import { DATA_HOST, HAS_USERBOX_ASSETS } from "../libs/config";
import { FADE_IN, FADE_OUT } from "../libs/config";
import { fade, slide } from "svelte/transition"; import { fade, slide } from "svelte/transition";
import StatusOverlays from "./StatusOverlays.svelte"; import StatusOverlays from "./StatusOverlays.svelte";
import Icon from "@iconify/svelte"; import Icon from "@iconify/svelte";
@@ -19,9 +18,6 @@
let submitting = ""; let submitting = "";
let changed: string[] = []; let changed: string[] = [];
let tab = 0;
const tabs = ["chusan", "ongeki", "maimai"];
// Things that can be changed in the userbox // Things that can be changed in the userbox
const userBoxFields = [ const userBoxFields = [
{ {
@@ -149,9 +145,9 @@
const currentValues = await USERBOX.getProfile().catch((e) => { const currentValues = await USERBOX.getProfile().catch((e) => {
loading = false; loading = false;
error = t("userbox.error.noprofile") error = t("userbox.error.noprofile")
}); })
if(!currentValues) return; if (!currentValues) return
values = { values = {
nameplate: currentValues.nameplateId, nameplate: currentValues.nameplateId,
@@ -174,7 +170,7 @@
return return
}); });
if(!itemLabels) return; if (!itemLabels) return;
await Promise.all( await Promise.all(
userBoxItems.map(async (kind) => { userBoxItems.map(async (kind) => {
@@ -300,45 +296,14 @@
</script> </script>
{#if !loading && !error} {#if !loading && !error}
<div class="outer-container">
<nav>
{#each tabs as tabName, i}
<div
transition:slide={{ axis: "x" }}
class:active={tab === i}
on:click={() => {
tab = i;
// Set url params
window.history.pushState({}, "", `/settings?tab=${tab}`);
}}
on:keydown={(e) => e.key === "Enter" && (tab = i)}
role="button"
tabindex="0"
>
{ts(`userbox.tabs.${tabName}`)}
</div>
{/each}
</nav>
{#if tab === 0}
<div class="container" out:fade={FADE_OUT} in:fade={FADE_IN}>
<div class="fields"> <div class="fields">
{#each userBoxFields as { key, label, kind }, i (key)} {#each userBoxFields as { key, label, kind }, i (key)}
<div class="field"> <div class="field">
<label for={key}>{label}</label> <label for={key}>{label}</label>
<div> <div>
<select <select bind:value={values[key]} id={key} on:change={() => changed = [...changed, key]}>
bind:value={values[key]} {#each availableOptions[key] as option}
id={key} <option value={option.id}>{option.label || `${key} ${option.id.toString()}`}</option>
on:change={() => {
changed = [...changed, key];
}}
>
{#each availableOptions[key] as option (option)}
<option value={option.id}
>{option.label ||
`${key} ${option.id.toString()}`}</option
>
{/each} {/each}
</select> </select>
{#if changed.includes(key)} {#if changed.includes(key)}
@@ -463,13 +428,6 @@
</div> </div>
</div> </div>
{/if} {/if}
</div>
{:else}
<div>
<p>WIP</p>
</div>
{/if}
</div>
{/if} {/if}
<StatusOverlays {error} {loading} /> <StatusOverlays {error} {loading} />

View File

@@ -266,7 +266,9 @@ export const USERBOX = {
get('/api/v2/game/chu3/user-box', {}), get('/api/v2/game/chu3/user-box', {}),
getUnlockedItems: (itemId: UserBoxItemKind): Promise<{ itemKind: number, itemId: number, stock: number, isValid: boolean }[]> => getUnlockedItems: (itemId: UserBoxItemKind): Promise<{ itemKind: number, itemId: number, stock: number, isValid: boolean }[]> =>
get(`/api/v2/game/chu3/user-box-item-by-kind`,{ itemId }), get(`/api/v2/game/chu3/user-box-item-by-kind`,{ itemId }),
getItemLabels: () => get(`/api/v2/game/chu3/user-box-all-items`, {}), getItemLabels: () => get(`/api/v2/game/chu3/user-box-all-items`, {}).then(it =>
Object.fromEntries(Object.entries(it).map(([key, value]) =>
[key, Object.fromEntries((value as any[]).map(it => [it.id, it.name]))]))),
setUserBox: (d: { field: string, value: number | string }) => setUserBox: (d: { field: string, value: number | string }) =>
post(`/api/v2/game/chu3/user-detail-set`, d), post(`/api/v2/game/chu3/user-detail-set`, d),
} }