From 8f189763f0c12f4e7db447ebd751b776e7d1c563 Mon Sep 17 00:00:00 2001 From: Tiberiu Ichim Date: Sun, 15 Feb 2026 16:37:03 +0200 Subject: [PATCH] Reset filters and search when switching libraries --- .../reset_filters_on_library_switch.md | 31 +++++++++++++++++++ client/components/controls/GlobalSearch.vue | 7 +++++ client/components/ui/LibrariesDropdown.vue | 2 +- client/store/libraries.js | 2 +- client/store/user.js | 8 ++++- 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 artifacts/2026-02-15/reset_filters_on_library_switch.md diff --git a/artifacts/2026-02-15/reset_filters_on_library_switch.md b/artifacts/2026-02-15/reset_filters_on_library_switch.md new file mode 100644 index 000000000..3b4bd63fa --- /dev/null +++ b/artifacts/2026-02-15/reset_filters_on_library_switch.md @@ -0,0 +1,31 @@ +# Specification: Reset Filters on Library Switch + +## Problem +Currently, when a user switches from one library to another in the UI, the previously applied filters (e.g., search query, genre, series, etc.) remain active. This can lead to confusing results, especially if the filters from the previous library don't return any results in the new library. + +## Goal +Automatically reset all library filters to their default state whenever the active library is changed. + +## Proposed Changes +1. **Detect Library Switch**: Identify the mechanism used to switch libraries (e.g., route change or Vuex store update). +2. **Reset Filters**: Trigger a reset of the filter state when a library switch is detected. + - Fields to reset: search, genre, series, series filter, tags, progress, etc. +3. **UI Updates**: Ensure the filter UI (dropdowns, search bar) reflects the reset state. + +## Implementation Details + +### 1. Store Updates (`client/store/user.js`) +- Update `checkUpdateLibrarySortFilter` action to accept a `libraryChanging` flag. +- If `libraryChanging` is true, reset `filterBy` to `'all'` and `seriesFilterBy` to `'all'`. +- This ensures that when the store's current library is updated, the filter state is also cleared, preventing components (like `LazyBookshelf.vue`) from re-applying old filters to the URL. + +### 2. Library Switcher Update (`client/components/ui/LibrariesDropdown.vue`) +- Update the `updateLibrary` method to pass `libraryChanging: true` when calling `libraries/fetch`. +- Modify the navigation logic: + - If on the search page, redirect to the bookshelf of the new library (clearing the search). + - If on a series item page, redirect to the series list of the new library (already doing this). + - Otherwise, ensure it navigates to the equivalent page in the new library but without query parameters. + +### 3. Global Search Reset (`client/components/controls/GlobalSearch.vue`) +- Add a watcher or listener to reset the local search state when the `currentLibraryId` changes. +- This ensures the search input in the header is cleared when the library changes. diff --git a/client/components/controls/GlobalSearch.vue b/client/components/controls/GlobalSearch.vue index 6f3a819bf..8ab898991 100644 --- a/client/components/controls/GlobalSearch.vue +++ b/client/components/controls/GlobalSearch.vue @@ -128,6 +128,13 @@ export default { return this.bookResults.length + this.seriesResults.length + this.authorResults.length + this.tagResults.length + this.genreResults.length + this.podcastResults.length + this.narratorResults.length + this.episodeResults.length } }, + watch: { + currentLibraryId(newVal, oldVal) { + if (newVal && oldVal && newVal !== oldVal) { + this.clearResults() + } + } + }, methods: { clickOption() { this.clearResults() diff --git a/client/components/ui/LibrariesDropdown.vue b/client/components/ui/LibrariesDropdown.vue index 37cf3ff5f..1573eac11 100644 --- a/client/components/ui/LibrariesDropdown.vue +++ b/client/components/ui/LibrariesDropdown.vue @@ -88,7 +88,7 @@ export default { // For series item page redirect to root series page this.$router.push(`/library/${library.id}/bookshelf/series`) } else if (this.$route.name === 'library-library-search') { - this.$router.push(this.$route.fullPath.replace(currLibraryId, library.id)) + this.$router.push(`/library/${library.id}/bookshelf`) } else if (this.$route.name.startsWith('library')) { this.$router.push(this.$route.path.replace(currLibraryId, library.id)) } else { diff --git a/client/store/libraries.js b/client/store/libraries.js index a6cf1dd39..f14a033bc 100644 --- a/client/store/libraries.js +++ b/client/store/libraries.js @@ -119,7 +119,7 @@ export const actions = { const issues = data.issues || 0 const numUserPlaylists = data.numUserPlaylists - dispatch('user/checkUpdateLibrarySortFilter', library.mediaType, { root: true }) + dispatch('user/checkUpdateLibrarySortFilter', { mediaType: library.mediaType, libraryChanging }, { root: true }) if (libraryChanging) { commit('setCollections', []) diff --git a/client/store/user.js b/client/store/user.js index 96e79d12f..7f7203ca4 100644 --- a/client/store/user.js +++ b/client/store/user.js @@ -83,8 +83,14 @@ export const getters = { export const actions = { // When changing libraries make sure sort and filter is still valid - checkUpdateLibrarySortFilter({ state, dispatch, commit }, mediaType) { + checkUpdateLibrarySortFilter({ state, dispatch, commit }, { mediaType, libraryChanging }) { const settingsUpdate = {} + + if (libraryChanging) { + settingsUpdate.filterBy = 'all' + settingsUpdate.seriesFilterBy = 'all' + } + if (mediaType == 'podcast') { if (state.settings.orderBy == 'media.metadata.authorName' || state.settings.orderBy == 'media.metadata.authorNameLF') { settingsUpdate.orderBy = 'media.metadata.author'