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
-6
View File
@@ -194,12 +194,6 @@ Replace the single free-form instructions textarea with an ordered list of discr
- Keep `Instructions` as a migration fallback column, or do a single-step cutover migration? - Keep `Instructions` as a migration fallback column, or do a single-step cutover migration?
- Should steps support rich text (bold ingredient names, timers) or stay plain text for v1? - Should steps support rich text (bold ingredient names, timers) or stay plain text for v1?
## Lists
### Block create-list flow when no stores exist
- A shopping list requires a `Store` (see `ListSummary.store` and the `newStoreId` state in `lists/+page.svelte`), so the create-list flow shouldn't be available until at least one store exists.
- Behavior: if user tries to open the create-list UI (or hits the create-list page directly via URL) with zero stores, surface a `toast.warning()` (or modal) that says "You need to create a store first" with a CTA linking to `/stores`. Don't render the empty/broken create form.
## Stores ## Stores
### Store types / categorization ### Store types / categorization
+13 -1
View File
@@ -1,6 +1,8 @@
<script lang="ts"> <script lang="ts">
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { goto } from '$app/navigation';
import { api } from '$lib/api'; import { api } from '$lib/api';
import { toast } from '$lib/toast.svelte';
import { startConnection, stopConnection } from '$lib/signalr'; import { startConnection, stopConnection } from '$lib/signalr';
import type { HubConnection } from '@microsoft/signalr'; import type { HubConnection } from '@microsoft/signalr';
@@ -64,6 +66,16 @@
await stopConnection(); 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() { async function createList() {
if (!newName.trim() || !newStoreId) return; if (!newName.trim() || !newStoreId) return;
await api<{ id: number }>('/api/lists', { await api<{ id: number }>('/api/lists', {
@@ -79,7 +91,7 @@
<div class="mb-4 flex items-center justify-between"> <div class="mb-4 flex items-center justify-between">
<h2 class="text-2xl font-bold">Shopping Lists</h2> <h2 class="text-2xl font-bold">Shopping Lists</h2>
<button <button
onclick={() => (showCreate = !showCreate)} onclick={toggleCreate}
class="rounded-full bg-primary px-4 py-2 text-sm font-semibold text-white" class="rounded-full bg-primary px-4 py-2 text-sm font-semibold text-white"
> >
{showCreate ? 'Cancel' : '+ New list'} {showCreate ? 'Cancel' : '+ New list'}