feat(fase-10): sidebar "+ New collective" entry + modal (10.6)
Adds a new "+ New collective" entry at the bottom of the sidebar collective-switcher dropdown (and the mobile drawer for parity). Clicking it opens a CreateCollectiveModal that reuses the same onboarding form — name + emoji grid — and calls the existing create_collective() RPC (migration 012). On success, the new collective is appended to $userCollectives, set active in $currentCollective, persisted to localStorage, and the user is sent to /lists. Side effects: - Switcher now opens even with a single collective (previously gated on >1) so the entry is always reachable; the chevron is always shown. - DesktopSidebar gets a data-testid on the switcher button so the Playwright suite can target it without text matching. O-04 (rescued from Fase 7): Eva creates her first collective via onboarding, then opens the switcher and creates a second one without leaving /lists; both collectives end up in the switcher and the DB. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
import { displayName } from '$lib/stores/auth';
|
||||
import { currentCollective, userCollectives } from '$lib/stores/collective';
|
||||
import Avatar from '$lib/components/Avatar.svelte';
|
||||
import CreateCollectiveModal from '$lib/components/CreateCollectiveModal.svelte';
|
||||
import * as m from '$lib/paraglide/messages';
|
||||
import { ShoppingCart, CheckSquare, FileText, Search, Settings } from 'lucide-svelte';
|
||||
import { ShoppingCart, CheckSquare, FileText, Search, Settings, Plus } from 'lucide-svelte';
|
||||
|
||||
const navItems = [
|
||||
{ href: '/lists', label: () => m.nav_lists(), icon: ShoppingCart },
|
||||
@@ -14,6 +15,7 @@
|
||||
];
|
||||
|
||||
let switcherOpen = $state(false);
|
||||
let showCreate = $state(false);
|
||||
|
||||
const activePath = $derived($page.url.pathname);
|
||||
|
||||
@@ -25,6 +27,11 @@
|
||||
switcherOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openCreateCollective() {
|
||||
switcherOpen = false;
|
||||
showCreate = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<aside
|
||||
@@ -33,6 +40,7 @@
|
||||
>
|
||||
<div class="relative">
|
||||
<button
|
||||
data-testid="sidebar-collective-switcher"
|
||||
class="flex h-14 w-full items-center gap-2 px-4 text-left hover:bg-black/5 dark:hover:bg-white/5"
|
||||
onclick={() => (switcherOpen = !switcherOpen)}
|
||||
aria-expanded={switcherOpen}
|
||||
@@ -41,11 +49,9 @@
|
||||
<span class="min-w-0 flex-1 truncate text-sm font-semibold text-slate-900 dark:text-slate-50">
|
||||
{$currentCollective?.name ?? m.app_name()}
|
||||
</span>
|
||||
{#if $userCollectives.length > 1}
|
||||
<span class="text-xs text-slate-400">⌄</span>
|
||||
{/if}
|
||||
<span class="text-xs text-slate-400">⌄</span>
|
||||
</button>
|
||||
{#if switcherOpen && $userCollectives.length > 1}
|
||||
{#if switcherOpen}
|
||||
<div class="absolute left-0 right-0 top-full z-50 bg-surface-raised shadow-[0px_20px_40px_rgba(15,23,42,0.06)]">
|
||||
{#each $userCollectives as c}
|
||||
<button
|
||||
@@ -56,6 +62,15 @@
|
||||
<span class="truncate">{c.name}</span>
|
||||
</button>
|
||||
{/each}
|
||||
<button
|
||||
data-testid="sidebar-create-collective"
|
||||
class="flex w-full items-center gap-2 border-t border-black/5 px-4 py-2.5 text-left text-sm font-medium text-slate-700
|
||||
hover:bg-black/5 dark:border-white/5 dark:text-slate-300 dark:hover:bg-white/5"
|
||||
onclick={openCreateCollective}
|
||||
>
|
||||
<Plus size={14} strokeWidth={1.5} />
|
||||
{m.sidebar_create_collective()}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -90,3 +105,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{#if showCreate}
|
||||
<CreateCollectiveModal onClose={() => (showCreate = false)} />
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user