From 17b8cf19b7e02305894876921c8aedc3bc309ba9 Mon Sep 17 00:00:00 2001 From: Vincent Schmandt Date: Tue, 21 Mar 2023 13:34:21 +0100 Subject: [PATCH] Add Location Storage --- client/components/readers/EpubReader.vue | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/client/components/readers/EpubReader.vue b/client/components/readers/EpubReader.vue index 47678c17..6fd652f8 100644 --- a/client/components/readers/EpubReader.vue +++ b/client/components/readers/EpubReader.vue @@ -107,18 +107,29 @@ export default { height: window.innerHeight * 0.9 }); - reader.rendition.display(cfi); + reader.rendition.display(this.userMediaProgress?.currentTime); reader.book.ready.then(() => { reader.rendition.on('relocated', reader.relocated); reader.rendition.on('keydown', reader.keyUp) document.addEventListener('keydown', reader.keyUp, false); - reader.book.locations.generate(); + if (reader.userMediaProgress?.duration) { + reader.book.locations.load(reader.userMediaProgress.duration) + } else { + reader.book.locations.generate().then(() => { + var updatePayload = { + duration: reader.book.locations.save(), + } + this.$axios.$patch(`/api/me/progress/${this.libraryItemId}`, updatePayload).catch((error) => { + console.error('Failed', error) + }) + }); + } }); }, }, mounted() { - this.initEpub(this.userMediaProgress?.currentTime); + this.initEpub(); }, };