preparing to move items to new location

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-20 09:26:47 +02:00
parent d179a33b41
commit b1517edc31
4 changed files with 45 additions and 12 deletions

View File

@@ -10,10 +10,10 @@
import Notes from '../notes/RelatedNotes.svelte';
import Tags from '../tags/TagList.svelte';
let loc_data = $derived.by(loadLocation);
let item = $state(null);
let location = $state(null);
let draggedItem = $state(null)
$effect(() => {
// This effect runs whenever `location` changes
@@ -22,6 +22,19 @@
let properties = $state(null);
let top_level = $state(null);
async function move_dragged_to(new_loc){
const data = { item : draggedItem, target: new_loc };
const url = api('stock/move_item');
const res = await fetch(url,{
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
if (res.ok){
yikes();
} else error(res);
}
async function loadLocation(){
if (!location) return null;
const url = api(`stock/location/${location.id}`)
@@ -76,7 +89,7 @@
{#each top_level as realm,idx}
<h3>{realm.name}</h3>
{#if realm.locations}
<Locations locations={realm.locations} parent={realm} bind:selected={location} />
<Locations locations={realm.locations} bind:selected={location} {move_dragged_to} />
{/if}
{/each}
{/if}
@@ -88,7 +101,7 @@
{#if location}
<h3>{location.name}</h3>
{/if}
<ItemList items={data?.items.sort((a,b) => a.code.localeCompare(b.code))} bind:selected={item} />
<ItemList items={data?.items.sort((a,b) => a.code.localeCompare(b.code))} bind:selected={item} drag_start={item => draggedItem = item} />
</div>
<div class="properties">
<ItemProps {item} {properties} />