mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-07 01:15:44 +02:00
Fix:Set next accessible library when currently selected library is removed
This commit is contained in:
parent
049ae73d74
commit
ceb163570f
@ -161,8 +161,28 @@ export default {
|
|||||||
libraryUpdated(library) {
|
libraryUpdated(library) {
|
||||||
this.$store.commit('libraries/addUpdate', library)
|
this.$store.commit('libraries/addUpdate', library)
|
||||||
},
|
},
|
||||||
libraryRemoved(library) {
|
async libraryRemoved(library) {
|
||||||
this.$store.commit('libraries/remove', library)
|
this.$store.commit('libraries/remove', library)
|
||||||
|
|
||||||
|
// When removed currently selected library then set next accessible library
|
||||||
|
const currLibraryId = this.$store.state.libraries.currentLibraryId
|
||||||
|
if (currLibraryId === library.id) {
|
||||||
|
var nextLibrary = this.$store.getters['libraries/getNextAccessibleLibrary']
|
||||||
|
if (nextLibrary) {
|
||||||
|
await this.$store.dispatch('libraries/fetch', nextLibrary.id)
|
||||||
|
|
||||||
|
if (this.$route.name.startsWith('config')) {
|
||||||
|
// No need to refresh
|
||||||
|
} else if (this.$route.name.startsWith('library')) {
|
||||||
|
var newRoute = this.$route.path.replace(currLibraryId, nextLibrary.id)
|
||||||
|
this.$router.push(newRoute)
|
||||||
|
} else {
|
||||||
|
this.$router.push(`/library/${nextLibrary.id}`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('User has no accessible libraries')
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
libraryItemAdded(libraryItem) {
|
libraryItemAdded(libraryItem) {
|
||||||
// this.$store.commit('libraries/updateFilterDataWithAudiobook', libraryItem)
|
// this.$store.commit('libraries/updateFilterDataWithAudiobook', libraryItem)
|
||||||
|
@ -29,6 +29,19 @@ export const getters = {
|
|||||||
var library = state.libraries.find(l => l.id === libraryId)
|
var library = state.libraries.find(l => l.id === libraryId)
|
||||||
if (!library) return null
|
if (!library) return null
|
||||||
return library.provider
|
return library.provider
|
||||||
|
},
|
||||||
|
getNextAccessibleLibrary: (state, getters, rootState, rootGetters) => {
|
||||||
|
var librariesSorted = getters['getSortedLibraries']()
|
||||||
|
if (!librariesSorted.length) return null
|
||||||
|
|
||||||
|
var canAccessAllLibraries = rootGetters['user/getUserCanAccessAllLibraries']
|
||||||
|
var userAccessibleLibraries = rootGetters['user/getLibrariesAccessible']
|
||||||
|
if (canAccessAllLibraries) return librariesSorted[0]
|
||||||
|
librariesSorted = librariesSorted.filter((lib) => {
|
||||||
|
return userAccessibleLibraries.includes(lib.id)
|
||||||
|
})
|
||||||
|
if (!librariesSorted.length) return null
|
||||||
|
return librariesSorted[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user