From 578a946ca54eb209825380b55b86b36f36c8cfd9 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 13 May 2022 16:51:54 -0500 Subject: [PATCH] Fix:Update changes to filterdata (authors, narrators, genres, tags, languages, series) --- client/layouts/default.vue | 3 +- client/store/libraries.js | 84 ++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 450a1bb5..a1a98ada 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -186,13 +186,14 @@ export default { } }, libraryItemAdded(libraryItem) { - // this.$store.commit('libraries/updateFilterDataWithAudiobook', libraryItem) + this.$store.commit('libraries/updateFilterDataWithItem', libraryItem) }, libraryItemUpdated(libraryItem) { if (this.$store.state.selectedLibraryItem && this.$store.state.selectedLibraryItem.id === libraryItem.id) { this.$store.commit('setSelectedLibraryItem', libraryItem) } this.$eventBus.$emit(`${libraryItem.id}_updated`, libraryItem) + this.$store.commit('libraries/updateFilterDataWithItem', libraryItem) }, libraryItemRemoved(item) { if (this.$route.name.startsWith('item')) { diff --git a/client/store/libraries.js b/client/store/libraries.js index 7890a4e7..acd8e96e 100644 --- a/client/store/libraries.js +++ b/client/store/libraries.js @@ -206,11 +206,11 @@ export const mutations = { setLibraryFilterData(state, filterData) { state.filterData = filterData }, - updateFilterDataWithAudiobook(state, audiobook) { - if (!audiobook || !audiobook.book || !state.filterData) return - if (state.currentLibraryId !== audiobook.libraryId) return + updateFilterDataWithItem(state, libraryItem) { + if (!libraryItem || !state.filterData) return + if (state.currentLibraryId !== libraryItem.libraryId) return /* - var filterdata = { + var data = { authors: [], genres: [], tags: [], @@ -219,36 +219,70 @@ export const mutations = { languages: [] } */ + var mediaMetadata = libraryItem.media.metadata - if (audiobook.book.authorFL) { - audiobook.book.authorFL.split(', ').forEach((author) => { - if (author && !state.filterData.authors.includes(author)) { + // Add/update book authors + if (mediaMetadata.authors && mediaMetadata.authors.length) { + mediaMetadata.authors.forEach((author) => { + var indexOf = state.filterData.authors.findIndex(au => au.id === author.id) + if (indexOf >= 0) { + state.filterData.authors.splice(indexOf, 1, author) + } else { state.filterData.authors.push(author) + state.filterData.authors.sort((a, b) => (a.name || '').localeCompare((b.name || ''))) } }) } - if (audiobook.book.narratorFL) { - audiobook.book.narratorFL.split(', ').forEach((narrator) => { - if (narrator && !state.filterData.narrators.includes(narrator)) { + + // Add/update series + if (mediaMetadata.series && mediaMetadata.series.length) { + mediaMetadata.series.forEach((series) => { + var indexOf = state.filterData.series.findIndex(se => se.id === series.id) + if (indexOf >= 0) { + state.filterData.series.splice(indexOf, 1, { id: series.id, name: series.name }) + } else { + state.filterData.series.push({ id: series.id, name: series.name }) + state.filterData.series.sort((a, b) => (a.name || '').localeCompare((b.name || ''))) + } + }) + } + + // Add genres + if (mediaMetadata.genres && mediaMetadata.genres.length) { + mediaMetadata.genres.forEach((genre) => { + if (!state.filterData.genres.includes(genre)) { + state.filterData.genres.push(genre) + state.filterData.genres.sort((a, b) => a.localeCompare(b)) + } + }) + } + + // Add tags + if (libraryItem.media.tags && libraryItem.media.tags.length) { + libraryItem.media.tags.forEach((tag) => { + if (!state.filterData.tags.includes(tag)) { + state.filterData.tags.push(tag) + state.filterData.tags.sort((a, b) => a.localeCompare(b)) + } + }) + } + + // Add narrators + if (mediaMetadata.narrators && mediaMetadata.narrators.length) { + mediaMetadata.narrators.forEach((narrator) => { + if (!state.filterData.narrators.includes(narrator)) { state.filterData.narrators.push(narrator) + state.filterData.narrators.sort((a, b) => a.localeCompare(b)) } }) } - if (audiobook.book.series && !state.filterData.series.includes(audiobook.book.series)) { - state.filterData.series.push(audiobook.book.series) - } - if (audiobook.tags && audiobook.tags.length) { - audiobook.tags.forEach((tag) => { - if (tag && !state.filterData.tags.includes(tag)) state.filterData.tags.push(tag) - }) - } - if (audiobook.book.genres && audiobook.book.genres.length) { - audiobook.book.genres.forEach((genre) => { - if (genre && !state.filterData.genres.includes(genre)) state.filterData.genres.push(genre) - }) - } - if (audiobook.book.language && !state.filterData.languages.includes(audiobook.book.language)) { - state.filterData.languages.push(audiobook.book.language) + + // Add language + if (mediaMetadata.language) { + if (!state.filterData.languages.includes(mediaMetadata.language)) { + state.filterData.languages.push(mediaMetadata.language) + state.filterData.languages.sort((a, b) => a.localeCompare(b)) + } } } } \ No newline at end of file