Fix:Remove last saved library id when changing servers so home page shelves load on init

This commit is contained in:
advplyr 2022-06-05 16:32:28 -05:00
parent d7dcaa22a6
commit 870774b408
10 changed files with 33 additions and 16 deletions

View file

@ -122,11 +122,15 @@ export default {
this.show = false this.show = false
}, },
async logout() { async logout() {
await this.$axios.$post('/logout').catch((error) => { if (this.user) {
console.error(error) await this.$axios.$post('/logout').catch((error) => {
}) console.error(error)
})
}
this.$socket.logout() this.$socket.logout()
await this.$db.logout() await this.$db.logout()
this.$localStore.removeLastLibraryId()
this.$store.commit('user/logout') this.$store.commit('user/logout')
this.$router.push('/connect') this.$router.push('/connect')
}, },

View file

@ -382,7 +382,7 @@ export default {
this.resetEntities() this.resetEntities()
} }
}, },
libraryChanged(libid) { libraryChanged() {
if (this.hasFilter) { if (this.hasFilter) {
this.clearFilter() this.clearFilter()
} else { } else {

View file

@ -51,7 +51,7 @@ export default {
async clickedOption(lib) { async clickedOption(lib) {
this.show = false this.show = false
await this.$store.dispatch('libraries/fetch', lib.id) await this.$store.dispatch('libraries/fetch', lib.id)
this.$eventBus.$emit('library-changed', lib.id) this.$eventBus.$emit('library-changed')
this.$localStore.setLastLibraryId(lib.id) this.$localStore.setLastLibraryId(lib.id)
} }
}, },

View file

@ -170,8 +170,8 @@ export default {
this.inittingLibraries = true this.inittingLibraries = true
await this.$store.dispatch('libraries/load') await this.$store.dispatch('libraries/load')
console.log(`[default] initLibraries loaded ${this.currentLibraryId}`) console.log(`[default] initLibraries loaded ${this.currentLibraryId}`)
await this.$store.dispatch('libraries/fetch', this.currentLibraryId)
this.$eventBus.$emit('library-changed') this.$eventBus.$emit('library-changed')
this.$store.dispatch('libraries/fetch', this.currentLibraryId)
this.inittingLibraries = false this.inittingLibraries = false
}, },
async syncLocalMediaProgress() { async syncLocalMediaProgress() {

View file

@ -53,11 +53,15 @@ export default {
}, },
methods: { methods: {
async logout() { async logout() {
await this.$axios.$post('/logout').catch((error) => { if (this.user) {
console.error(error) await this.$axios.$post('/logout').catch((error) => {
}) console.error(error)
})
}
this.$socket.logout() this.$socket.logout()
await this.$db.logout() await this.$db.logout()
this.$localStore.removeLastLibraryId()
this.$store.commit('user/logout') this.$store.commit('user/logout')
this.$router.push('/connect') this.$router.push('/connect')
} }

View file

@ -4,10 +4,6 @@
<home-bookshelf-toolbar v-show="!isHome" /> <home-bookshelf-toolbar v-show="!isHome" />
<div id="bookshelf-wrapper" class="main-content overflow-y-auto overflow-x-hidden relative" :class="isHome ? 'home-page' : ''"> <div id="bookshelf-wrapper" class="main-content overflow-y-auto overflow-x-hidden relative" :class="isHome ? 'home-page' : ''">
<nuxt-child /> <nuxt-child />
<!-- <div v-if="isLoading" class="absolute top-0 left-0 w-full h-full flex items-center justify-center">
<ui-loading-indicator />
</div>-->
</div> </div>
</div> </div>
</template> </template>

View file

@ -135,7 +135,7 @@ export default {
} }
this.loading = false this.loading = false
}, },
async libraryChanged(libid) { async libraryChanged() {
if (this.currentLibraryId) { if (this.currentLibraryId) {
await this.fetchCategories() await this.fetchCategories()
} }

View file

@ -83,7 +83,16 @@ class LocalStorage {
await Storage.set({ key: 'lastLibraryId', value: libraryId }) await Storage.set({ key: 'lastLibraryId', value: libraryId })
console.log('[LocalStorage] Set Last Library Id', libraryId) console.log('[LocalStorage] Set Last Library Id', libraryId)
} catch (error) { } catch (error) {
console.error('[LocalStorage] Failed to set current library', error) console.error('[LocalStorage] Failed to set last library id', error)
}
}
async removeLastLibraryId() {
try {
await Storage.remove({ key: 'lastLibraryId' })
console.log('[LocalStorage] Remove Last Library Id')
} catch (error) {
console.error('[LocalStorage] Failed to remove last library id', error)
} }
} }

View file

@ -22,13 +22,16 @@ export const getters = {
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
var userToken = rootGetters['user/getToken'] var userToken = rootGetters['user/getToken']
var serverAddress = rootGetters['user/getServerAddress']
if (!userToken || !serverAddress) return placeholder
var lastUpdate = libraryItem.updatedAt || Date.now() var lastUpdate = libraryItem.updatedAt || Date.now()
if (process.env.NODE_ENV !== 'production') { // Testing if (process.env.NODE_ENV !== 'production') { // Testing
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}` // return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}`
} }
var url = new URL(`/api/items/${libraryItem.id}/cover`, rootGetters['user/getServerAddress']) var url = new URL(`/api/items/${libraryItem.id}/cover`, serverAddress)
return `${url}?token=${userToken}&ts=${lastUpdate}` return `${url}?token=${userToken}&ts=${lastUpdate}`
}, },
getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => { getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => {

View file

@ -90,6 +90,7 @@ export const mutations = {
}, },
reset(state) { reset(state) {
state.lastLoad = 0 state.lastLoad = 0
state.currentLibraryId = null
state.libraries = [] state.libraries = []
}, },
setCurrentLibrary(state, val) { setCurrentLibrary(state, val) {