reverted old changes and fixed library switching

This commit is contained in:
Vito0912 2025-01-03 10:20:16 +01:00
parent 47272d6136
commit bd41f23438
No known key found for this signature in database
GPG Key ID: 29A3D509FE70B237
3 changed files with 16 additions and 52 deletions

View File

@ -87,12 +87,6 @@
<ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" :menu-width="110" class="ml-2" @action="contextMenuAction" /> <ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" :menu-width="110" class="ml-2" @action="contextMenuAction" />
</template> </template>
<!-- library stats page -->
<template v-else-if="isLibraryStatsPage">
<div class="flex-grow" />
<ui-btn color="primary" small @click="updateLibraryStats">
{{ this.showAllLibraryStats ? currentLibraryName : $strings.LabelShowAll }}</ui-btn>
</template>
<!-- search page --> <!-- search page -->
<template v-else-if="page === 'search'"> <template v-else-if="page === 'search'">
<div class="flex-grow" /> <div class="flex-grow" />
@ -269,9 +263,6 @@ export default {
isPlaylistsPage() { isPlaylistsPage() {
return this.page === 'playlists' return this.page === 'playlists'
}, },
isLibraryStatsPage() {
return this.page === 'library-stats'
},
isHomePage() { isHomePage() {
return this.$route.name === 'library-library' return this.$route.name === 'library-library'
}, },
@ -619,12 +610,6 @@ export default {
updateAuthorSort() { updateAuthorSort() {
this.saveSettings() this.saveSettings()
}, },
updateLibraryStats() {
this.$emit('library-stats-updated', !this.showAllLibraryStats)
this.$nextTick(() => {
this.showAllLibraryStats = !this.showAllLibraryStats
})
},
saveSettings() { saveSettings() {
this.$store.dispatch('user/updateUserSettings', this.settings) this.$store.dispatch('user/updateUserSettings', this.settings)
}, },

View File

@ -20,9 +20,9 @@
<tr v-for="library in bookLibraryListStats"> <tr v-for="library in bookLibraryListStats">
<td> <td>
<p class="text-sm md:text-base text-gray-100"> <p class="text-sm md:text-base text-gray-100">
<nuxt-link :to="`/library/${library.id}/stats`" class="hover:underline"> <a :href="'/library/' + library.id + '/stats'" class="hover:underline" @click.prevent="switchLibrary(library.id)">
{{ library.name }} {{ library.name }}
</nuxt-link> </a>
</p> </p>
</td> </td>
<td> <td>
@ -59,9 +59,9 @@
<tr v-for="library in podcastLibraryListStats"> <tr v-for="library in podcastLibraryListStats">
<td> <td>
<p class="text-sm md:text-base text-gray-100"> <p class="text-sm md:text-base text-gray-100">
<nuxt-link :to="`/library/${library.id}/stats`" class="hover:underline"> <a :href="'/library/' + library.id + '/stats'" class="hover:underline" @click.prevent="switchLibrary(library.id)">
{{ library.name }} {{ library.name }}
</nuxt-link> </a>
</p> </p>
</td> </td>
<td> <td>
@ -141,10 +141,6 @@ export default {
if (a['type'] > b['type']) return 1 if (a['type'] > b['type']) return 1
return 0 return 0
}) })
console.log(this.bookLibraryIndex)
console.log(this.podcastLibraryIndex)
}, },
totalHours(duration) { totalHours(duration) {
return Math.round(duration / (60 * 60)) return Math.round(duration / (60 * 60))
@ -159,6 +155,11 @@ export default {
totalSizeMod(size) { totalSizeMod(size) {
return this.totalSizePretty(size).split(' ')[1] return this.totalSizePretty(size).split(' ')[1]
}, },
async switchLibrary(libraryId) {
await this.$store.dispatch('libraries/fetch', libraryId);
await this.$router.push(`/library/${libraryId}/stats`)
}
}, },
mounted() { mounted() {
this.init() this.init()

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="page relative" :class="streamLibraryItem ? 'streaming' : ''"> <div class="page relative" :class="streamLibraryItem ? 'streaming' : ''">
<app-book-shelf-toolbar page="library-stats" is-home @library-stats-updated="toggleStats" /> <app-book-shelf-toolbar page="library-stats" is-home />
<div id="bookshelf" class="w-full h-full px-1 py-4 md:p-8 relative overflow-y-auto"> <div id="bookshelf" class="w-full h-full px-1 py-4 md:p-8 relative overflow-y-auto">
<div class="w-full max-w-4xl mx-auto"> <div class="w-full max-w-4xl mx-auto">
<stats-preview-icons v-if="totalItems" :library-stats="libraryStats" /> <stats-preview-icons v-if="totalItems" :library-stats="libraryStats" />
@ -102,8 +102,7 @@ export default {
}, },
data() { data() {
return { return {
libraryStats: null, libraryStats: null
showAllLibraryStats: false
} }
}, },
watch: { watch: {
@ -111,12 +110,6 @@ export default {
if (newVal) { if (newVal) {
this.init() this.init()
} }
},
showAllLibraryStats(newVal) {
console.log('showAllLibraryStats', newVal)
if (newVal) {
this.init()
}
} }
}, },
computed: { computed: {
@ -171,26 +164,11 @@ export default {
}, },
methods: { methods: {
async init() { async init() {
this.libraryStats = null this.libraryStats = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/stats`).catch((err) => {
if (this.showAllLibraryStats === true) { console.error('Failed to get library stats', err)
this.libraryStats = (await this.$axios.$get(`/api/libraries/stats`).catch((err) => { var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error'
console.error('Failed to get library stats', err) this.$toast.error(`Failed to get library stats: ${errorMsg}`)
var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error' })
this.$toast.error(`Failed to get library stats: ${errorMsg}`)
}))['combined']
} else {
this.libraryStats = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/stats`).catch((err) => {
console.error('Failed to get library stats', err)
var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error'
this.$toast.error(`Failed to get library stats: ${errorMsg}`)
})
}
},
toggleStats(value) {
this.showAllLibraryStats = value;
this.$nextTick(() => {
this.init();
});
} }
}, },
mounted() { mounted() {