Block create-list flow when no stores exist

Tapping "+ New list" with zero stores now shows a warning toast with an
"Add a store" action linking to /stores, instead of opening a form whose
required store dropdown would be empty.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Josh Rogers
2026-05-15 19:53:51 -05:00
parent b7e4ebc15a
commit 7c30c7db27
2 changed files with 13 additions and 7 deletions
+13 -1
View File
@@ -1,6 +1,8 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { goto } from '$app/navigation';
import { api } from '$lib/api';
import { toast } from '$lib/toast.svelte';
import { startConnection, stopConnection } from '$lib/signalr';
import type { HubConnection } from '@microsoft/signalr';
@@ -64,6 +66,16 @@
await stopConnection();
});
function toggleCreate() {
if (!showCreate && stores.length === 0) {
toast.warning('You need to create a store first', {
action: { label: 'Add a store', onClick: () => goto('/stores') }
});
return;
}
showCreate = !showCreate;
}
async function createList() {
if (!newName.trim() || !newStoreId) return;
await api<{ id: number }>('/api/lists', {
@@ -79,7 +91,7 @@
<div class="mb-4 flex items-center justify-between">
<h2 class="text-2xl font-bold">Shopping Lists</h2>
<button
onclick={() => (showCreate = !showCreate)}
onclick={toggleCreate}
class="rounded-full bg-primary px-4 py-2 text-sm font-semibold text-white"
>
{showCreate ? 'Cancel' : '+ New list'}