diff --git a/components/connection/ServerConnectForm.vue b/components/connection/ServerConnectForm.vue index c2909281..d6b1d8f2 100644 --- a/components/connection/ServerConnectForm.vue +++ b/components/connection/ServerConnectForm.vue @@ -400,12 +400,13 @@ export default { this.setUserAndConnection(payload) } }, - async setUserAndConnection({ user, userDefaultLibraryId, serverSettings }) { + async setUserAndConnection({ user, userDefaultLibraryId, serverSettings, ereaderDevices }) { if (!user) return console.log('Successfully logged in', JSON.stringify(user)) this.$store.commit('setServerSettings', serverSettings) + this.$store.commit('libraries/setEReaderDevices', ereaderDevices) // Set library - Use last library if set and available fallback to default user library var lastLibraryId = await this.$localStore.getLastLibraryId() diff --git a/components/modals/Dialog.vue b/components/modals/Dialog.vue index 9fa46c18..9086e3a2 100644 --- a/components/modals/Dialog.vue +++ b/components/modals/Dialog.vue @@ -1,7 +1,7 @@ @@ -175,11 +180,13 @@ export default { }, data() { return { + processing: false, resettingProgress: false, isProcessingReadUpdate: false, showSelectLocalFolder: false, showMoreMenu: false, showDetailsModal: false, + showSendEbookDevicesModal: false, showFullscreenCover: false, coverRgb: 'rgb(55, 56, 56)', coverBgIsLight: false, @@ -430,6 +437,14 @@ export default { value: 'playlist', icon: 'playlist_add' }) + + if (this.ebookFile && this.$store.state.libraries.ereaderDevices?.length) { + items.push({ + text: 'Send ebook to device', + value: 'sendEbook', + icon: 'send' + }) + } } if (this.showRSSFeedOption) { @@ -464,6 +479,15 @@ export default { return items }, + ereaderDeviceItems() { + if (!this.ebookFile || !this.$store.state.libraries.ereaderDevices?.length) return [] + return this.$store.state.libraries.ereaderDevices.map((d) => { + return { + text: d.name, + value: d.name + } + }) + }, coverWidth() { let width = this.windowWidth - 94 if (width > 325) return 325 @@ -543,8 +567,31 @@ export default { this.deleteLocalItem() } else if (action === 'rssFeed') { this.clickRSSFeed() + } else if (action === 'sendEbook') { + this.showSendEbookDevicesModal = true } }, + sendEbookToDeviceAction(deviceName) { + this.showSendEbookDevicesModal = false + + const payload = { + libraryItemId: this.serverLibraryItemId, + deviceName + } + this.processing = true + this.$nativeHttp + .post(`/api/emails/send-ebook-to-device`, payload) + .then(() => { + this.$toast.success('Ebook sent successfully') + }) + .catch((error) => { + console.error('Failed to send ebook to device', error) + this.$toast.error('Failed to send ebook to device') + }) + .finally(() => { + this.processing = false + }) + }, clickRSSFeed() { this.$store.commit('globals/setRSSFeedOpenCloseModal', { id: this.serverLibraryItemId, @@ -555,6 +602,7 @@ export default { }) }, moreButtonPress() { + this.showSendEbookDevicesModal = false this.showMoreMenu = true }, readBook() { diff --git a/store/libraries.js b/store/libraries.js index 9582653e..602c8e1c 100644 --- a/store/libraries.js +++ b/store/libraries.js @@ -7,7 +7,8 @@ export const state = () => ({ showModal: false, issues: 0, filterData: null, - numUserPlaylists: 0 + numUserPlaylists: 0, + ereaderDevices: [] }) export const getters = { @@ -177,5 +178,8 @@ export const mutations = { if (genre && !state.filterData.genres.includes(genre)) state.filterData.genres.push(genre) }) } + }, + setEReaderDevices(state, ereaderDevices) { + state.ereaderDevices = ereaderDevices } } \ No newline at end of file