mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
cc1b767264
Use the destination-complete predicate for the Ready chip and select-all operations so counts and filtered results remain consistent. Fixes #1215
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { ref } from 'vue'
|
|
import { api } from '@/lib/api'
|
|
import type { BookDockFinalizeResult, BookDockFinalizeOverride } from '@bookorbit/types'
|
|
|
|
export function useBookDockFinalize() {
|
|
const result = ref<BookDockFinalizeResult | null>(null)
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
|
|
async function finalize(payload: {
|
|
fileIds?: number[]
|
|
selectAll?: boolean
|
|
excludedIds?: number[]
|
|
status?: string
|
|
needsReview?: boolean
|
|
readyToFile?: boolean
|
|
search?: string
|
|
defaultLibraryId?: number
|
|
defaultFolderId?: number
|
|
overrides?: BookDockFinalizeOverride[]
|
|
}) {
|
|
loading.value = true
|
|
error.value = null
|
|
result.value = null
|
|
|
|
try {
|
|
const res = await api('/api/v1/book-dock/finalize', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
})
|
|
|
|
if (res.ok) {
|
|
result.value = await res.json()
|
|
} else {
|
|
const body = await res.json().catch(() => null)
|
|
error.value = (body as { message?: string } | null)?.message ?? `Error ${res.status}`
|
|
}
|
|
} catch (e) {
|
|
error.value = e instanceof Error ? e.message : 'Finalize failed'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function reset() {
|
|
result.value = null
|
|
error.value = null
|
|
}
|
|
|
|
return { result, loading, error, finalize, reset }
|
|
}
|