diff --git a/frontend/src/routes/stock/Index.svelte b/frontend/src/routes/stock/Index.svelte index 24eabab..d8c17e7 100644 --- a/frontend/src/routes/stock/Index.svelte +++ b/frontend/src/routes/stock/Index.svelte @@ -18,17 +18,22 @@ let draggedItem = $state(null) let draggedLocation = $state(null) let { item_id, location_id, owner, owner_id } = $props(); + let skip_location = false; // disable effect on setting location within loadItem() $effect(() => { // This effect runs whenever `location` changes - if (location !== null) { + if (!skip_location && location !== null) { item = null; setLocationUrl(); } }); $effect(() => { - if (item !== null) setItemUrl(); + // This effect runs whenever `item` changes + if (item !== null) { + setItemUrl(); + skip_location = false; + } }); let properties = $state(null); let top_level = $state(null); @@ -96,6 +101,27 @@ if (!item_id) return; const url = api(`stock/${owner}/${owner_id}/item/${item_id}`); const res = await get(url); + if (res.ok){ + yikes(); + const json = await res.json(); + const path = json.path; + for (let owner of top_level){ + for (let loc of owner.locations){ + if (loc.id == path.id) { + loc.locations = path.locations; + skip_location = true; + location = json.location; + break; + } + } + } + for (let i of json.items){ + if (i.owner_number == +item_id) item = i; + } + } else { + error(res); + return null; + } } async function loadPath(){ @@ -146,9 +172,9 @@ async function load(){ await loadUserLocations(); - loadItem(); - loadPath(); - loadProperties(); + await loadPath(); + await loadProperties(); + await loadItem(); } function moveToTop(loc){ @@ -240,7 +266,7 @@