diff --git a/frontend/src/api/snippets.ts b/frontend/src/api/snippets.ts index ea5b5a0..40796f3 100644 --- a/frontend/src/api/snippets.ts +++ b/frontend/src/api/snippets.ts @@ -1,7 +1,16 @@ import { apiGet, apiPost, apiPatch, apiDelete } from "@/api/client"; +/** One canonical location of a reusable thing. A snippet that unifies several + * one-offs carries several — one per call site. */ +export interface SnippetLocation { + repo: string; + path: string; + symbol: string; +} + /** Structured fields parsed out of a snippet note (mirrors the backend - * `parse_snippet_fields` — see services/snippets.py). */ + * `parse_snippet_fields` — see services/snippets.py). `repo`/`path`/`symbol` + * mirror the first location for back-compat; `locations` is the full list. */ export interface SnippetFields { name: string; when_to_use: string; @@ -10,6 +19,7 @@ export interface SnippetFields { repo: string; path: string; symbol: string; + locations: SnippetLocation[]; code: string; } @@ -50,9 +60,7 @@ export interface SnippetInput { language?: string; signature?: string; when_to_use?: string; - repo?: string; - path?: string; - symbol?: string; + locations?: SnippetLocation[]; tags?: string[]; project_id?: number | null; } @@ -85,3 +93,12 @@ export async function updateSnippet( export async function deleteSnippet(id: number): Promise { return apiDelete(`/api/snippets/${id}`); } + +/** Unify `sourceIds` into the canonical snippet `targetId`. Returns the merged + * survivor plus `merged_ids` — the sources actually folded in and trashed. */ +export async function mergeSnippets( + targetId: number, + sourceIds: number[], +): Promise { + return apiPost(`/api/snippets/${targetId}/merge`, { source_ids: sourceIds }); +} diff --git a/frontend/src/views/SnippetDetailView.vue b/frontend/src/views/SnippetDetailView.vue index 9dca0dd..63ca1f2 100644 --- a/frontend/src/views/SnippetDetailView.vue +++ b/frontend/src/views/SnippetDetailView.vue @@ -21,11 +21,11 @@ const canWrite = computed(() => { return p === undefined || p === "owner" || p === "edit" || p === "admin"; }); -const locationParts = computed(() => { - const s = snippet.value?.snippet; - if (!s) return []; - return [s.repo, s.path, s.symbol].filter((p) => p && p.trim()); -}); +const locations = computed(() => snippet.value?.snippet.locations ?? []); + +function locParts(loc: { repo: string; path: string; symbol: string }): string[] { + return [loc.repo, loc.path, loc.symbol].filter((p) => p && p.trim()); +} async function load() { loading.value = true; @@ -92,10 +92,12 @@ async function confirmDelete() {
Signature
{{ snippet.snippet.signature }}
-