feat: clip-liste mit schnell-eingabe und kopieren

- Startseite zeigt Clips, angeheftete zuerst, mit 'Weitere laden'
- Schnell-Eingabe mit Text/Code, Spracherkennung und Einfügen aus der Zwischenablage
- Kopieren-Button mit Clipboard API und Ausweichlösung
- Syntax-Highlighting mit highlight.js (nur die 24 unterstützten Sprachen)
- Pinia-Store für Clips als Grundlage für den Live-Sync

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dbildhauerandClaude Opus 5.5 committed 2026-10-25 11:04:33 +01:00
1 parent 4caab7e657
commit 7b16940b96
13 files changed
+673 -42

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { ApiError, api } from '@/api/client'
import type { Clip, ClipInput, ClipList } from '@/api/types'
const PAGE_SIZE = 50
export class ClipConflictError extends Error {
constructor(public readonly current: Clip) {
super('Der Clip wurde inzwischen auf einem anderen Gerät geändert.')
}
}
/** Pinned first, then most recently edited – same order as the backend. */
function compareClips(a: Clip, b: Clip): number {
if (a.pinned !== b.pinned) return a.pinned ? -1 : 1
if (a.updated_at !== b.updated_at) return a.updated_at < b.updated_at ? 1 : -1
return b.id - a.id
}
export const useClipsStore = defineStore('clips', () => {
const items = ref<Clip[]>([])
const total = ref(0)
const loading = ref(false)
const error = ref<string | null>(null)
/** Insert or replace a clip locally (also the entry point for live sync later). */
function upsert(clip: Clip): void {
const index = items.value.findIndex((c) => c.id === clip.id)
if (index === -1) {
items.value.push(clip)
total.value += 1
} else {
items.value[index] = clip
}
items.value.sort(compareClips)
}
function removeLocal(id: number): void {
const before = items.value.length
items.value = items.value.filter((c) => c.id !== id)
total.value -= before - items.value.length
}
async function load(): Promise<void> {
loading.value = true
error.value = null
try {
const page = await api.get<ClipList>(`/clips?limit=${PAGE_SIZE}&offset=0`)
items.value = page.items
total.value = page.total
} catch (e) {
error.value = e instanceof Error ? e.message : String(e)
} finally {
loading.value = false
}
}
async function loadMore(): Promise<void> {
const page = await api.get<ClipList>(`/clips?limit=${PAGE_SIZE}&offset=${items.value.length}`)
for (const clip of page.items) upsert(clip)
total.value = page.total
}
async function fetchOne(id: number): Promise<Clip> {
const clip = await api.get<Clip>(`/clips/${id}`)
upsert(clip)
return clip
}
async function create(input: ClipInput): Promise<Clip> {
const clip = await api.post<Clip>('/clips', input)
upsert(clip)
return clip
}
/** Pass the version the edit is based on to detect concurrent changes. */
async function update(id: number, changes: ClipInput, version?: number): Promise<Clip> {
try {
const clip = await api.patch<Clip>(`/clips/${id}`, { ...changes, version })
upsert(clip)
return clip
} catch (e) {
if (e instanceof ApiError && e.status === 409) {
const current = (e.data as { current: Clip }).current
upsert(current)
throw new ClipConflictError(current)
}
throw e
}
}
async function remove(id: number): Promise<void> {
await api.delete(`/clips/${id}`)
removeLocal(id)
}
return {
items,
total,
loading,
error,
upsert,
removeLocal,
load,
loadMore,
fetchOne,
create,
update,
remove,
}
})