feat: projekte und suche im frontend

Projektleiste mit Filter, Suchfeld, Projektauswahl beim Anlegen und
Bearbeiten, Etikett auf der Clip-Karte und eigene Seite zum Verwalten.
Filter und Suche stehen in der URL; Live-Ereignisse respektieren den
aktiven Filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dbildhauerandClaude Opus 5.5 committed 2026-10-25 13:33:03 +01:00
1 parent 9ba4655662
commit eba5621082
21 files changed
+1084 -37

No files matched your search

+98 -1
View File
@@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { Clip } from '@/api/types'
import { ClipConflictError, useClipsStore } from './clips'
import { ClipConflictError, matchesFilter, useClipsStore } from './clips'
function clip(overrides: Partial<Clip> = {}): Clip {
return {
@@ -13,6 +13,7 @@ function clip(overrides: Partial<Clip> = {}): Clip {
content: 'hello',
language: null,
pinned: false,
project_id: null,
version: 1,
created_at: '2026-10-25T10:00:00Z',
updated_at: '2026-10-25T10:00:00Z',
@@ -107,4 +108,100 @@ describe('clips store', () => {
expect(init.method).toBe('PATCH')
expect(JSON.parse(init.body as string)).toEqual({ pinned: true, version: 1 })
})
it('requests the filtered list', async () => {
const store = useClipsStore()
const fetchMock = vi.fn<typeof fetch>(async () => jsonResponse(200, { items: [], total: 0 }))
vi.stubGlobal('fetch', fetchMock)
await store.setFilter({ project: 3, query: ' a&b ' })
const url = new URL(String(fetchMock.mock.calls[0]![0]), 'https://x')
expect(url.searchParams.get('project')).toBe('3')
expect(url.searchParams.get('q')).toBe('a&b')
await store.setFilter({ project: 3, query: 'a&b' })
expect(fetchMock).toHaveBeenCalledOnce()
})
it('drops responses to superseded requests', async () => {
const store = useClipsStore()
const resolvers: ((r: Response) => void)[] = []
vi.stubGlobal(
'fetch',
vi.fn(() => new Promise<Response>((resolve) => resolvers.push(resolve))),
)
const first = store.setFilter({ project: null, query: 'a' })
const second = store.setFilter({ project: null, query: 'ab' })
resolvers[1]!(jsonResponse(200, { items: [clip({ id: 2, content: 'ab' })], total: 1 }))
await second
resolvers[0]!(jsonResponse(200, { items: [clip({ id: 1, content: 'a' })], total: 1 }))
await first
expect(store.items.map((c) => c.id)).toEqual([2])
expect(store.loading).toBe(false)
})
it('keeps live updates that do not match the filter out of the list', () => {
const store = useClipsStore()
store.filter = { project: 5, query: '' }
store.upsert(clip({ id: 1, project_id: 5 }))
store.upsert(clip({ id: 2, project_id: 6 }))
expect(store.items.map((c) => c.id)).toEqual([1])
// Moved to another project on a different device
store.upsert(clip({ id: 1, project_id: 6, version: 2 }))
expect(store.items).toEqual([])
expect(store.total).toBe(0)
})
it('tells subscribers about changes to filtered-out clips', () => {
const store = useClipsStore()
store.filter = { project: 'none', query: '' }
const listener = vi.fn()
const unsubscribe = store.subscribe(listener)
store.upsert(clip({ id: 1, project_id: 9 }))
store.removeLocal(1)
unsubscribe()
store.upsert(clip({ id: 2 }))
expect(listener.mock.calls).toEqual([
[{ clip: clip({ id: 1, project_id: 9 }) }],
[{ deleted: 1 }],
])
})
it('detaches clips from a deleted project like the backend', () => {
const store = useClipsStore()
store.upsert(clip({ id: 1, project_id: 4, version: 2 }))
store.upsert(clip({ id: 2, project_id: 5 }))
store.detachProject(4)
const byId = Object.fromEntries(store.items.map((c) => [c.id, c]))
expect(byId[1]).toMatchObject({ project_id: null, version: 3 })
expect(byId[2]).toMatchObject({ project_id: 5, version: 1 })
})
})
describe('matchesFilter', () => {
const all = { project: null, query: '' }
it('filters by project', () => {
expect(matchesFilter(clip({ project_id: 1 }), all)).toBe(true)
expect(matchesFilter(clip({ project_id: 1 }), { ...all, project: 1 })).toBe(true)
expect(matchesFilter(clip({ project_id: 2 }), { ...all, project: 1 })).toBe(false)
expect(matchesFilter(clip(), { ...all, project: 'none' })).toBe(true)
expect(matchesFilter(clip({ project_id: 1 }), { ...all, project: 'none' })).toBe(false)
})
it('searches title and content case-insensitively', () => {
const c = clip({ title: 'Server', content: 'cfg = getConfig()' })
expect(matchesFilter(c, { ...all, query: 'CONFIG' })).toBe(true)
expect(matchesFilter(c, { ...all, query: ' serv ' })).toBe(true)
expect(matchesFilter(c, { ...all, query: 'missing' })).toBe(false)
expect(matchesFilter(clip({ content: 'Straße' }), { ...all, query: 'STRASSE' })).toBe(true)
})
})