working on loading items for location

This commit is contained in:
2025-10-13 21:57:50 +02:00
parent 26d2f7c1f4
commit 6e9a2b6aca
10 changed files with 152 additions and 9 deletions

View File

@@ -10,6 +10,21 @@
let top_level = $state(null);
let selected = $state(null);
let items = $derived(loadItems(selected));
async function loadItems(loc){
if (!loc) return null;
const url = api(`stock/items_at/${loc.id}`)
const res = await fetch(url,{credentials:'include'});
if (res.ok){
yikes();
return loc.name;
} else {
error(res);
return null;
}
}
async function load(){
const url = api('stock/locations/of_user')
@@ -32,12 +47,18 @@
{#each top_level as realm,idx}
<h3>{realm.name}</h3>
{#if realm.locations}
<Locations locations={realm.locations} />
<Locations locations={realm.locations} bind:selected />
{/if}
{/each}
{/if}
</td>
<td class="items">
{#if selected}
<h3>{selected.name}</h3>
{/if}
{#if items}
<pre>{JSON.stringify(items)}</pre>
{/if}
<ItemList />
</td>
<td class="properties">

View File

@@ -3,11 +3,12 @@
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
let { locations } = $props();
let { locations, selected = $bindable(null) } = $props();
async function toggleChildren(ev, location){
ev.preventDefault();
ev.stopPropagation();
selected = location;
if (location.locations) {
delete location.locations;
} else {
@@ -32,7 +33,7 @@
<li onclick={e => toggleChildren(e, location)} class={location.locations?'expanded':'collapsed'}>
{location.name}
{#if location.locations}
<svelte:self locations={location.locations} />
<svelte:self locations={location.locations} bind:selected />
{/if}
</li>
{/each}