New data model updates for bookshelf, covers, cards

This commit is contained in:
advplyr
2022-03-23 17:59:14 -05:00
parent 84bab5de1b
commit 03312390cb
16 changed files with 1094 additions and 454 deletions
+32
View File
@@ -0,0 +1,32 @@
export const state = () => ({
})
export const getters = {
getLibraryItemCoverSrc: (state, getters, rootState, rootGetters) => (libraryItem, placeholder = '/book_placeholder.jpg') => {
if (!libraryItem) return placeholder
var media = libraryItem.media
if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder
// Absolute URL covers (should no longer be used)
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
var userToken = rootGetters['user/getToken']
var lastUpdate = libraryItem.updatedAt || Date.now()
if (process.env.NODE_ENV !== 'production') { // Testing
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}`
}
var url = new URL(`/api/items/${libraryItem.id}/cover`, rootState.serverUrl)
return `${url}?token=${userToken}&ts=${lastUpdate}`
}
}
export const actions = {
}
export const mutations = {
}
+4 -6
View File
@@ -2,6 +2,7 @@ import Vue from 'vue'
import { Network } from '@capacitor/network'
export const state = () => ({
streamLibraryItem: null,
streamAudiobook: null,
playingDownload: null,
playOnLoad: false,
@@ -80,6 +81,9 @@ export const mutations = {
setPlayOnLoad(state, val) {
state.playOnLoad = val
},
setLibraryItemStream(state, libraryItem) {
state.streamLibraryItem = libraryItem
},
setStreamAudiobook(state, audiobook) {
if (audiobook) {
state.playingDownload = null
@@ -111,12 +115,6 @@ export const mutations = {
state.networkConnected = val.connected
state.networkConnectionType = val.connectionType
},
setStreamListener(state, val) {
state.streamListener = val
},
removeStreamListener(state) {
state.streamListener = null
},
openReader(state, audiobook) {
state.selectedBook = audiobook
state.showReader = true
+4
View File
@@ -20,6 +20,10 @@ export const getters = {
getToken: (state) => {
return state.user ? state.user.token : null
},
getUserLibraryItemProgress: (state) => (libraryItemId) => {
if (!state.user.libraryItemProgress) return null
return state.user.libraryItemProgress.find(li => li.id == libraryItemId)
},
getUserAudiobookData: (state, getters) => (audiobookId) => {
return getters.getUserAudiobook(audiobookId)
},