Finish lazy bookshelf,Fix:Async sql db,Fix:Load user progress

This commit is contained in:
advplyr
2021-12-05 18:31:47 -06:00
parent 37d3021302
commit 3232b519d3
42 changed files with 613 additions and 1878 deletions
+9 -35
View File
@@ -12,9 +12,7 @@ export const state = () => ({
bookshelfCoverSize: 120
},
settingsListeners: [],
userAudiobooksListeners: [],
collections: [],
collectionsLoaded: false
userAudiobooksListeners: []
})
export const getters = {
@@ -33,9 +31,6 @@ export const getters = {
},
getFilterOrderKey: (state) => {
return Object.values(state.settings).join('-')
},
getCollection: state => id => {
return state.collections.find(c => c.id === id)
}
}
@@ -61,23 +56,14 @@ export const actions = {
commit('setSettings', payload)
}
},
loadUserCollections({ state, commit }) {
if (!this.$server.connected) {
console.error('Not loading collections - not connected')
return []
async loadOfflineUserAudiobookData({ state, commit }) {
var localUserAudiobookData = await this.$sqlStore.getAllUserAudiobookData() || []
if (localUserAudiobookData.length) {
console.log('loadOfflineUserAudiobookData found', localUserAudiobookData.length, 'user audiobook data')
commit('setAllUserAudiobookData', localUserAudiobookData)
} else {
console.log('loadOfflineUserAudiobookData No user audiobook data')
}
if (state.collectionsLoaded) {
console.log('Collections already loaded')
return state.collections
}
return this.$axios.$get('/api/collections').then((collections) => {
commit('setCollections', collections)
return collections
}).catch((error) => {
console.error('Failed to get collections', error)
return []
})
},
async syncUserAudiobookData({ state, commit }) {
if (!state.user) {
@@ -167,17 +153,5 @@ export const mutations = {
},
removeUserAudiobookListener(state, listenerId) {
state.userAudiobooksListeners = state.userAudiobooksListeners.filter(l => l.id !== listenerId)
},
setCollections(state, collections) {
state.collections = collections
state.collectionsLoaded = true
},
addUpdateCollection(state, collection) {
var index = state.collections.findIndex(c => c.id === collection.id)
if (index >= 0) {
state.collections.splice(index, 1, collection)
} else {
state.collections.push(collection)
}
},
}
}