feat(frontend): tagDirectory rename and merge store actions

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-16 13:41:20 -04:00
parent 305687dc33
commit 1d1574e586
2 changed files with 109 additions and 1 deletions
+33 -1
View File
@@ -45,6 +45,38 @@ export const useTagDirectoryStore = defineStore('tagDirectory', () => {
function setKind(k) { kind.value = k; reset() }
function setQuery(text) { q.value = text; reset() }
async function rename(id, name) {
try {
const body = await api.patch(`/api/tags/${id}`, { body: { name } })
const card = cards.value.find((c) => c.id === id)
if (card) card.name = body.name
return { tag: body }
} catch (e) {
if (e.status === 409 && e.body && e.body.target) {
const card = cards.value.find((c) => c.id === id)
return {
collision: {
sourceId: id,
sourceName: card ? card.name : '',
target: e.body.target,
sourceImageCount: e.body.source_image_count,
willAlias: e.body.will_alias
}
}
}
throw e
}
}
async function merge(sourceId, targetId) {
const result = await api.post(`/api/tags/${sourceId}/merge`, {
body: { target_id: targetId }
})
const idx = cards.value.findIndex((c) => c.id === sourceId)
if (idx !== -1) cards.value.splice(idx, 1)
return result
}
const hasMore = computed(() => !started || nextCursor.value !== null)
const isEmpty = computed(
() => !loading.value && cards.value.length === 0 && error.value === null
@@ -52,6 +84,6 @@ export const useTagDirectoryStore = defineStore('tagDirectory', () => {
return {
cards, loading, error, kind, q, hasMore, isEmpty,
loadMore, reset, setKind, setQuery
loadMore, reset, setKind, setQuery, rename, merge
}
})