mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
import books simplify
This commit is contained in:
parent
5b41cfaaec
commit
91c1eeb9c4
1 changed files with 28 additions and 31 deletions
|
|
@ -520,48 +520,51 @@ function fileNamePicked(name: string) {
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
function analyzeBook(book: BookImport) {
|
function analyzeBook(book: BookImport) {
|
||||||
const { refresh } = useQuery(transientBookAnalyze, () => ({
|
void useQuery(transientBookAnalyze, () => ({
|
||||||
transientBookId: book.transientBook.id,
|
transientBookId: book.transientBook.id,
|
||||||
}))
|
}))
|
||||||
void refresh().then(({ data }) => {
|
.refresh()
|
||||||
if (data) {
|
.then(({ data }) => {
|
||||||
book.transientBook = data
|
if (data) {
|
||||||
if (book.transientBook.seriesId && book.transientBook.seriesId !== book.series?.id)
|
book.transientBook = data
|
||||||
fetchSeries(book)
|
if (book.transientBook.seriesId && book.transientBook.seriesId !== book.series?.id)
|
||||||
}
|
fetchSeries(book)
|
||||||
})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchSeries(book: BookImport) {
|
function fetchSeries(book: BookImport) {
|
||||||
const { refresh } = useQuery(seriesDetailQuery, () => ({
|
void useQuery(seriesDetailQuery, () => ({
|
||||||
seriesId: book.transientBook.seriesId!,
|
seriesId: book.transientBook.seriesId!,
|
||||||
}))
|
}))
|
||||||
void refresh().then(({ data }) => {
|
.refresh()
|
||||||
if (data) {
|
.then(({ data }) => {
|
||||||
assignSeries(book, data)
|
if (data) assignSeries(book, data)
|
||||||
}
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchBooks(book: BookImport) {
|
function fetchBooks(book: BookImport) {
|
||||||
const { refresh } = useQuery(bookListQuery, () => ({
|
void useQuery(bookListQuery, () => ({
|
||||||
search: {
|
search: {
|
||||||
condition: {
|
condition: {
|
||||||
seriesId: { operator: 'Is', value: book.series!.id },
|
seriesId: { operator: 'Is', value: book.series!.id },
|
||||||
},
|
},
|
||||||
} as components['schemas']['BookSearch'],
|
} as components['schemas']['BookSearch'],
|
||||||
}))
|
}))
|
||||||
void refresh().then(({ data }) => {
|
.refresh()
|
||||||
if (data) {
|
.then(({ data }) => {
|
||||||
book.seriesBooks = data.content
|
if (data) {
|
||||||
if (book.transientBook.number) assignBookNumber(book, book.transientBook.number)
|
book.seriesBooks = data.content
|
||||||
}
|
if (book.series?.oneshot) book.upgradeBook = data.content?.at(0)
|
||||||
})
|
else if (book.transientBook.number) assignBookNumber(book, book.transientBook.number)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function assignSeries(book: BookImport, series: components['schemas']['SeriesDto']) {
|
function assignSeries(book: BookImport, series: components['schemas']['SeriesDto']) {
|
||||||
book.series = series
|
book.series = series
|
||||||
fetchBooks(book)
|
fetchBooks(book)
|
||||||
|
// auto-select importable books
|
||||||
if (book.importable && !selectedBookIds.value.includes(book.transientBook.id))
|
if (book.importable && !selectedBookIds.value.includes(book.transientBook.id))
|
||||||
selectedBookIds.value.push(book.transientBook.id)
|
selectedBookIds.value.push(book.transientBook.id)
|
||||||
}
|
}
|
||||||
|
|
@ -574,15 +577,12 @@ function unassignBook(book: BookImport) {
|
||||||
book.upgradeBook = undefined
|
book.upgradeBook = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const importing = ref<boolean>(false)
|
const { mutateAsync: postImportBooks, isLoading: importing } = useMutation({
|
||||||
|
mutation: () => komgaClient.POST('/api/v1/books/import', { body: importBatch.value }),
|
||||||
|
})
|
||||||
|
|
||||||
function doImportBooks() {
|
function doImportBooks() {
|
||||||
importing.value = true
|
postImportBooks()
|
||||||
const { mutateAsync } = useMutation({
|
|
||||||
mutation: () => komgaClient.POST('/api/v1/books/import', { body: importBatch.value }),
|
|
||||||
})
|
|
||||||
|
|
||||||
mutateAsync()
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
selectedImportableBooks.value.forEach((it) => {
|
selectedImportableBooks.value.forEach((it) => {
|
||||||
it.imported = true
|
it.imported = true
|
||||||
|
|
@ -597,9 +597,6 @@ function doImportBooks() {
|
||||||
(error?.cause as ErrorCause)?.message || intl.formatMessage(commonMessages.networkError),
|
(error?.cause as ErrorCause)?.message || intl.formatMessage(commonMessages.networkError),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.finally(() => {
|
|
||||||
importing.value = false
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue