feat: brain taxonomy — DB-backed folders/tags, sidebar, CRUD API
Backend: - New Folder/Tag/ItemTag models with proper relational tables - Taxonomy CRUD endpoints: list, create, rename, delete, merge tags - Sidebar endpoint with folder/tag counts - AI classification reads live folders/tags from DB, not hardcoded - Default folders/tags seeded on first request per user - folder_id FK on items for relational integrity Frontend: - Left sidebar with Folders/Tags tabs (like Karakeep) - Click folder/tag to filter items - "Manage" mode: add new folders/tags, delete existing - Counts next to each folder/tag - "All items" option to clear filter - Replaces the old signal-strip cards Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,17 +23,25 @@
|
||||
assets: { id: string; asset_type: string; filename: string; content_type: string | null }[];
|
||||
}
|
||||
|
||||
interface SidebarFolder { id: string; name: string; slug: string; is_active: boolean; item_count: number; }
|
||||
interface SidebarTag { id: string; name: string; slug: string; is_active: boolean; item_count: number; }
|
||||
|
||||
let loading = $state(true);
|
||||
let items = $state<BrainItem[]>([]);
|
||||
let total = $state(0);
|
||||
let activeFolder = $state<string | null>(null);
|
||||
let activeFolderId = $state<string | null>(null);
|
||||
let activeTag = $state<string | null>(null);
|
||||
let activeTagId = $state<string | null>(null);
|
||||
let searchQuery = $state('');
|
||||
let searching = $state(false);
|
||||
let folders = $state<string[]>([]);
|
||||
let tags = $state<string[]>([]);
|
||||
|
||||
// Filter
|
||||
let activeTag = $state<string | null>(null);
|
||||
// Sidebar
|
||||
let sidebarFolders = $state<SidebarFolder[]>([]);
|
||||
let sidebarTags = $state<SidebarTag[]>([]);
|
||||
let sidebarView = $state<'folders' | 'tags'>('folders');
|
||||
let showManage = $state(false);
|
||||
let newTaxName = $state('');
|
||||
|
||||
// Capture
|
||||
let captureInput = $state('');
|
||||
@@ -46,20 +54,18 @@
|
||||
let editingNote = $state(false);
|
||||
let editNoteContent = $state('');
|
||||
|
||||
// Folder counts
|
||||
let folderCounts = $state<Record<string, number>>({});
|
||||
|
||||
async function api(path: string, opts: RequestInit = {}) {
|
||||
const res = await fetch(`/api/brain${path}`, { credentials: 'include', ...opts });
|
||||
if (!res.ok) throw new Error(`${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
async function loadSidebar() {
|
||||
try {
|
||||
const data = await api('/config');
|
||||
folders = data.folders || [];
|
||||
tags = data.tags || [];
|
||||
const data = await api('/taxonomy/sidebar');
|
||||
sidebarFolders = data.folders || [];
|
||||
sidebarTags = data.tags || [];
|
||||
total = data.total_items || 0;
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
@@ -72,18 +78,59 @@
|
||||
const data = await api(`/items?${params}`);
|
||||
items = data.items || [];
|
||||
total = data.total || 0;
|
||||
|
||||
// Count items per folder
|
||||
const counts: Record<string, number> = {};
|
||||
for (const item of items) {
|
||||
const f = item.folder || 'Uncategorized';
|
||||
counts[f] = (counts[f] || 0) + 1;
|
||||
}
|
||||
folderCounts = counts;
|
||||
} catch { /* silent */ }
|
||||
loading = false;
|
||||
}
|
||||
|
||||
async function addTaxonomy() {
|
||||
if (!newTaxName.trim()) return;
|
||||
try {
|
||||
const endpoint = sidebarView === 'folders' ? '/taxonomy/folders' : '/taxonomy/tags';
|
||||
await api(endpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: newTaxName.trim() }),
|
||||
});
|
||||
newTaxName = '';
|
||||
await loadSidebar();
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
async function deleteTaxonomy(id: string) {
|
||||
try {
|
||||
const endpoint = sidebarView === 'folders' ? `/taxonomy/folders/${id}` : `/taxonomy/tags/${id}`;
|
||||
await api(endpoint, { method: 'DELETE' });
|
||||
await loadSidebar();
|
||||
await loadItems();
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
function selectFolder(folder: SidebarFolder | null) {
|
||||
if (folder) {
|
||||
activeFolder = folder.name;
|
||||
activeFolderId = folder.id;
|
||||
} else {
|
||||
activeFolder = null;
|
||||
activeFolderId = null;
|
||||
}
|
||||
activeTag = null;
|
||||
activeTagId = null;
|
||||
loadItems();
|
||||
}
|
||||
|
||||
function selectTag(tag: SidebarTag | null) {
|
||||
if (tag) {
|
||||
activeTag = tag.name;
|
||||
activeTagId = tag.id;
|
||||
} else {
|
||||
activeTag = null;
|
||||
activeTagId = null;
|
||||
}
|
||||
activeFolder = null;
|
||||
activeFolderId = null;
|
||||
loadItems();
|
||||
}
|
||||
|
||||
async function capture() {
|
||||
if (!captureInput.trim()) return;
|
||||
capturing = true;
|
||||
@@ -260,7 +307,7 @@
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
await loadConfig();
|
||||
await loadSidebar();
|
||||
await loadItems();
|
||||
});
|
||||
|
||||
@@ -309,58 +356,90 @@
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<!-- ═══ Folder signal strip ═══ -->
|
||||
<section class="signal-strip stagger">
|
||||
<button class="signal-card" class:active={activeFolder === null} onclick={() => { activeFolder = null; loadItems(); }}>
|
||||
<div class="signal-topline">
|
||||
<div class="signal-label">All</div>
|
||||
<div class="signal-value">{total}</div>
|
||||
<!-- ═══ Sidebar + Main layout ═══ -->
|
||||
<div class="brain-layout">
|
||||
|
||||
<!-- Sidebar -->
|
||||
<aside class="brain-sidebar">
|
||||
<div class="sidebar-tabs">
|
||||
<button class="sidebar-tab" class:active={sidebarView === 'folders'} onclick={() => sidebarView = 'folders'}>Folders</button>
|
||||
<button class="sidebar-tab" class:active={sidebarView === 'tags'} onclick={() => sidebarView = 'tags'}>Tags</button>
|
||||
</div>
|
||||
<div class="signal-note">Everything saved across all folders.</div>
|
||||
</button>
|
||||
{#each folders.slice(0, 5) as folder}
|
||||
<button class="signal-card" class:active={activeFolder === folder} onclick={() => { activeFolder = folder; loadItems(); }}>
|
||||
<div class="signal-topline">
|
||||
<div class="signal-label">{folder}</div>
|
||||
<div class="signal-value">{folderCounts[folder] || 0}</div>
|
||||
</div>
|
||||
<div class="signal-note">Items classified under {folder.toLowerCase()}.</div>
|
||||
</button>
|
||||
{/each}
|
||||
</section>
|
||||
|
||||
<!-- ═══ Active tag filter ═══ -->
|
||||
{#if activeTag}
|
||||
<div class="active-filter">
|
||||
<span class="filter-label">Filtered by tag:</span>
|
||||
<span class="filter-tag">{activeTag}</span>
|
||||
<button class="filter-clear" onclick={() => { activeTag = null; loadItems(); }}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
Clear
|
||||
<!-- All items -->
|
||||
<button class="sidebar-item" class:active={!activeFolder && !activeTag} onclick={() => { selectFolder(null); selectTag(null); }}>
|
||||
<span class="sidebar-item-name">All items</span>
|
||||
<span class="sidebar-item-count">{total}</span>
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- ═══ Search bar ═══ -->
|
||||
<section class="search-section">
|
||||
<div class="search-wrap">
|
||||
<svg class="search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="M21 21l-4.35-4.35"/></svg>
|
||||
<input
|
||||
type="text"
|
||||
class="search-input"
|
||||
placeholder="Search your brain..."
|
||||
bind:value={searchQuery}
|
||||
oninput={handleSearchInput}
|
||||
/>
|
||||
{#if searchQuery}
|
||||
<button class="search-clear" onclick={() => { searchQuery = ''; loadItems(); }}>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</button>
|
||||
{#if sidebarView === 'folders'}
|
||||
{#each sidebarFolders.filter(f => f.is_active) as folder}
|
||||
<button class="sidebar-item" class:active={activeFolderId === folder.id} onclick={() => selectFolder(folder)}>
|
||||
<span class="sidebar-item-name">{folder.name}</span>
|
||||
<span class="sidebar-item-count">{folder.item_count}</span>
|
||||
{#if showManage}
|
||||
<button class="sidebar-item-delete" onclick={(e) => { e.stopPropagation(); if (confirm(`Delete folder "${folder.name}"? Items will be moved.`)) deleteTaxonomy(folder.id); }}>
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</button>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
{:else}
|
||||
{#each sidebarTags.filter(t => t.is_active) as tag}
|
||||
<button class="sidebar-item" class:active={activeTagId === tag.id} onclick={() => selectTag(tag)}>
|
||||
<span class="sidebar-item-name">{tag.name}</span>
|
||||
<span class="sidebar-item-count">{tag.item_count}</span>
|
||||
{#if showManage}
|
||||
<button class="sidebar-item-delete" onclick={(e) => { e.stopPropagation(); if (confirm(`Delete tag "${tag.name}"?`)) deleteTaxonomy(tag.id); }}>
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</button>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ═══ Masonry card grid ═══ -->
|
||||
<!-- Add / Manage -->
|
||||
<div class="sidebar-actions">
|
||||
{#if showManage}
|
||||
<div class="sidebar-add">
|
||||
<input class="sidebar-add-input" placeholder="New {sidebarView === 'folders' ? 'folder' : 'tag'}..." bind:value={newTaxName} onkeydown={(e) => { if (e.key === 'Enter') addTaxonomy(); }} />
|
||||
<button class="sidebar-add-btn" onclick={addTaxonomy}>Add</button>
|
||||
</div>
|
||||
{/if}
|
||||
<button class="sidebar-manage-toggle" onclick={() => showManage = !showManage}>
|
||||
{showManage ? 'Done' : 'Manage'}
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- Main content -->
|
||||
<div class="brain-main">
|
||||
<!-- Active filter indicator -->
|
||||
{#if activeFolder || activeTag}
|
||||
<div class="active-filter">
|
||||
<span class="filter-label">Filtered by {activeFolder ? 'folder' : 'tag'}:</span>
|
||||
<span class="filter-tag">{activeFolder || activeTag}</span>
|
||||
<button class="filter-clear" onclick={() => { selectFolder(null); selectTag(null); }}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
Clear
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Search -->
|
||||
<div class="search-section">
|
||||
<div class="search-wrap">
|
||||
<svg class="search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="M21 21l-4.35-4.35"/></svg>
|
||||
<input type="text" class="search-input" placeholder="Search your brain..." bind:value={searchQuery} oninput={handleSearchInput} />
|
||||
{#if searchQuery}
|
||||
<button class="search-clear" onclick={() => { searchQuery = ''; loadItems(); }}>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Masonry card grid -->
|
||||
{#if loading}
|
||||
<div class="masonry">
|
||||
{#each [1, 2, 3, 4, 5, 6] as _}
|
||||
@@ -445,6 +524,9 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div><!-- .brain-main -->
|
||||
</div><!-- .brain-layout -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -667,23 +749,44 @@
|
||||
}
|
||||
.capture-btn:hover { opacity: 0.9; }
|
||||
|
||||
/* ═══ Signal strip ═══ */
|
||||
.signal-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
|
||||
.signal-card {
|
||||
border-radius: 28px; border: 1px solid rgba(35,26,17,0.08);
|
||||
background: rgba(255,252,248,0.68); backdrop-filter: blur(14px);
|
||||
padding: 18px; text-align: left;
|
||||
transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
|
||||
/* ═══ Layout: Sidebar + Main ═══ */
|
||||
.brain-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
|
||||
|
||||
.brain-sidebar {
|
||||
position: sticky; top: 68px;
|
||||
border-radius: 20px; border: 1px solid rgba(35,26,17,0.08);
|
||||
background: rgba(255,252,248,0.72); backdrop-filter: blur(14px);
|
||||
padding: 14px; max-height: calc(100vh - 80px); overflow-y: auto;
|
||||
}
|
||||
.signal-card:hover { transform: translateY(-2px); background: rgba(255,255,255,0.82); }
|
||||
.signal-card.active {
|
||||
border-color: rgba(179,92,50,0.2);
|
||||
background: linear-gradient(145deg, rgba(255,248,242,0.94), rgba(246,237,227,0.72));
|
||||
.sidebar-tabs { display: flex; gap: 2px; margin-bottom: 10px; background: rgba(35,26,17,0.04); border-radius: 10px; padding: 3px; }
|
||||
.sidebar-tab {
|
||||
flex: 1; padding: 6px 0; border-radius: 8px; font-size: 0.8rem; font-weight: 600;
|
||||
color: #7d6f61; background: none; border: none; font-family: var(--font); transition: all 160ms;
|
||||
}
|
||||
.signal-topline { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
|
||||
.signal-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: #7d6f61; }
|
||||
.signal-value { font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 0.95; letter-spacing: -0.05em; color: #1e1812; }
|
||||
.signal-note { color: #4f463d; line-height: 1.6; font-size: 0.85rem; }
|
||||
.sidebar-tab.active { background: rgba(255,255,255,0.9); color: #1e1812; box-shadow: 0 1px 3px rgba(35,26,17,0.06); }
|
||||
|
||||
.sidebar-item {
|
||||
display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px;
|
||||
border-radius: 10px; border: none; background: none; font-family: var(--font);
|
||||
font-size: 0.85rem; color: #3d342c; text-align: left; transition: all 160ms;
|
||||
}
|
||||
.sidebar-item:hover { background: rgba(255,255,255,0.6); }
|
||||
.sidebar-item.active { background: linear-gradient(135deg, rgba(255,248,242,0.94), rgba(246,237,227,0.72)); color: #1e1812; font-weight: 600; }
|
||||
.sidebar-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.sidebar-item-count { flex-shrink: 0; font-size: 0.72rem; font-family: var(--mono); color: #8c7b69; background: rgba(35,26,17,0.04); padding: 1px 6px; border-radius: 6px; }
|
||||
.sidebar-item-delete { flex-shrink: 0; width: 20px; height: 20px; border-radius: 6px; border: none; background: none; color: #8c7b69; display: flex; align-items: center; justify-content: center; }
|
||||
.sidebar-item-delete:hover { background: rgba(220,38,38,0.1); color: #DC2626; }
|
||||
|
||||
.sidebar-actions { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(35,26,17,0.06); display: flex; flex-direction: column; gap: 6px; }
|
||||
.sidebar-add { display: flex; gap: 4px; }
|
||||
.sidebar-add-input { flex: 1; padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(35,26,17,0.1); background: rgba(255,255,255,0.7); font-size: 0.8rem; font-family: var(--font); color: #1e1812; outline: none; }
|
||||
.sidebar-add-input:focus { border-color: rgba(179,92,50,0.4); }
|
||||
.sidebar-add-input::placeholder { color: #8c7b69; }
|
||||
.sidebar-add-btn { padding: 6px 10px; border-radius: 8px; border: none; background: #1e1812; color: white; font-size: 0.78rem; font-weight: 600; font-family: var(--font); }
|
||||
.sidebar-manage-toggle { padding: 6px 0; border: none; background: none; font-size: 0.78rem; color: #8c7b69; font-family: var(--font); text-align: center; }
|
||||
.sidebar-manage-toggle:hover { color: #1e1812; }
|
||||
|
||||
.brain-main { min-width: 0; }
|
||||
|
||||
/* ═══ Active filter ═══ */
|
||||
.active-filter {
|
||||
@@ -1113,11 +1216,13 @@
|
||||
/* ═══ Mobile ═══ */
|
||||
@media (max-width: 1100px) {
|
||||
.masonry { columns: 2; }
|
||||
.brain-layout { grid-template-columns: 200px 1fr; }
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.brain-command { display: grid; gap: 14px; }
|
||||
.command-actions { justify-items: start; }
|
||||
.signal-strip { grid-template-columns: 1fr 1fr; }
|
||||
.brain-layout { grid-template-columns: 1fr; }
|
||||
.brain-sidebar { position: static; max-height: none; }
|
||||
.masonry { columns: 1; }
|
||||
.detail-sheet { width: 100%; padding: 20px; }
|
||||
.viewer-overlay { padding: 12px; }
|
||||
|
||||
Reference in New Issue
Block a user