diff --git a/src/routes/(app)/locations/+page.server.ts b/src/routes/(app)/locations/+page.server.ts index ee4de90..86ca66e 100644 --- a/src/routes/(app)/locations/+page.server.ts +++ b/src/routes/(app)/locations/+page.server.ts @@ -68,6 +68,20 @@ export const actions: Actions = { return { created: true }; }, + rename: async ({ request }) => { + const formData = await request.formData(); + const id = formData.get('id') as string; + const name = (formData.get('name') as string)?.trim(); + const description = (formData.get('description') as string)?.trim(); + if (!name) return fail(400, { error: 'Name is required' }); + + await db + .update(locations) + .set({ name, description: description || null, updatedAt: new Date() }) + .where(eq(locations.id, id)); + return { renamed: true }; + }, + delete: async ({ request }) => { const formData = await request.formData(); const id = formData.get('id') as string; diff --git a/src/routes/(app)/locations/+page.svelte b/src/routes/(app)/locations/+page.svelte index c6785c2..8f3aa62 100644 --- a/src/routes/(app)/locations/+page.svelte +++ b/src/routes/(app)/locations/+page.svelte @@ -3,6 +3,7 @@ let { data, form } = $props(); let showForm = $state(false); + let editingId = $state(null); type Loc = (typeof data.locations)[number] & { depth: number }; @@ -81,37 +82,67 @@ {:else}
{#each sortedLocations as loc} -
-
-

- {#if loc.depth > 0} - └  - {/if} - {loc.name} -

- {#if loc.description} -

{loc.description}

- {/if} -
-
-
- {#if loc.deviceCount > 0} - {loc.deviceCount} device{loc.deviceCount !== 1 ? 's' : ''} - {/if} - {#if loc.componentCount > 0} - {loc.componentCount} component{loc.componentCount !== 1 ? 's' : ''} - {/if} -
-
+ {#if editingId === loc.id} + { + return async ({ update, result }) => { + await update(); + if (result.type === 'success') editingId = null; + }; + }} class="flex flex-wrap items-end gap-2"> - +
+ + +
+
+ + +
+ +
-
+ {:else} +
+
+

+ {#if loc.depth > 0} + └  + {/if} + {loc.name} +

+ {#if loc.description} +

{loc.description}

+ {/if} +
+
+
+ {#if loc.deviceCount > 0} + {loc.deviceCount} device{loc.deviceCount !== 1 ? 's' : ''} + {/if} + {#if loc.componentCount > 0} + {loc.componentCount} component{loc.componentCount !== 1 ? 's' : ''} + {/if} +
+ +
+ + +
+
+
+ {/if}
{/each}