fix(webreader): progress not marked correctly

closes #518
This commit is contained in:
Gauthier Roebroeck 2021-04-29 18:27:32 +08:00
parent f304aaf2f6
commit f3c541cd14

View file

@ -288,6 +288,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import {debounce} from 'lodash'
import SettingsSelect from '@/components/SettingsSelect.vue' import SettingsSelect from '@/components/SettingsSelect.vue'
import SettingsSwitch from '@/components/SettingsSwitch.vue' import SettingsSwitch from '@/components/SettingsSwitch.vue'
import ThumbnailExplorerDialog from '@/components/dialogs/ThumbnailExplorerDialog.vue' import ThumbnailExplorerDialog from '@/components/dialogs/ThumbnailExplorerDialog.vue'
@ -342,7 +343,7 @@ export default Vue.extend({
fromMetadata: false, fromMetadata: false,
}, },
pages: [] as PageDtoWithUrl[], pages: [] as PageDtoWithUrl[],
page: 1, page: undefined as unknown as number,
supportedMediaTypes: ['image/jpeg', 'image/png', 'image/gif'], supportedMediaTypes: ['image/jpeg', 'image/png', 'image/gif'],
convertTo: 'jpeg', convertTo: 'jpeg',
showExplorer: false, showExplorer: false,
@ -427,15 +428,20 @@ export default Vue.extend({
async beforeRouteUpdate(to, from, next) { async beforeRouteUpdate(to, from, next) {
if (to.params.bookId !== from.params.bookId) { if (to.params.bookId !== from.params.bookId) {
// route update means going to previous/next book, in this case we start from first page // route update means going to previous/next book, in this case we start from first page
this.setup(to.params.bookId, 1) this.setup(to.params.bookId)
} }
next() next()
}, },
watch: { watch: {
page(val) { page: {
this.updateRoute() handler(val, old) {
this.goToPage = val if (val) {
// this.markProgress(val) this.markProgress(val)
this.goToPage = val
this.updateRoute()
}
},
immediate: true,
}, },
}, },
computed: { computed: {
@ -577,7 +583,7 @@ export default Vue.extend({
keyPressed(e: KeyboardEvent) { keyPressed(e: KeyboardEvent) {
this.shortcuts[e.key]?.execute(this) this.shortcuts[e.key]?.execute(this)
}, },
async setup(bookId: string, page: number) { async setup(bookId: string, page?: number) {
this.book = await this.$komgaBooks.getBook(bookId) this.book = await this.$komgaBooks.getBook(bookId)
this.series = await this.$komgaSeries.getOneSeries(this.book.seriesId) this.series = await this.$komgaSeries.getOneSeries(this.book.seriesId)
@ -602,7 +608,7 @@ export default Vue.extend({
pageDtos.forEach((p: any) => p['url'] = this.getPageUrl(p)) pageDtos.forEach((p: any) => p['url'] = this.getPageUrl(p))
this.pages = pageDtos as PageDtoWithUrl[] this.pages = pageDtos as PageDtoWithUrl[]
if (page >= 1 && page <= this.pagesCount) { if (page && page >= 1 && page <= this.pagesCount) {
this.goTo(page) this.goTo(page)
} else if (this.book.readProgress?.completed === false) { } else if (this.book.readProgress?.completed === false) {
this.goTo(this.book.readProgress?.page!!) this.goTo(this.book.readProgress?.page!!)
@ -782,10 +788,11 @@ export default Vue.extend({
this.notification.message = message this.notification.message = message
this.notification.enabled = true this.notification.enabled = true
}, },
async markProgress(page: number) { markProgress: debounce(function (this: any, page: number) {
if (!this.incognito) if (!this.incognito) {
await this.$komgaBooks.updateReadProgress(this.bookId, {page: page}) this.$komgaBooks.updateReadProgress(this.bookId, {page: page})
}, }
}, 50),
downloadCurrentPage() { downloadCurrentPage() {
new jsFileDownloader({ new jsFileDownloader({
url: this.currentPage.url, url: this.currentPage.url,