Skip to content

Commit

Permalink
Filter search result by category
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Dec 27, 2024
1 parent 5783ea0 commit 1329a3a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/components/dialog/content/SettingDialogContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
v-model:modelValue="searchQuery"
@search="handleSearch"
:placeholder="$t('g.searchSettings') + '...'"
:debounceTime="100"
/>
<Listbox
v-model="activeCategory"
Expand Down Expand Up @@ -68,13 +67,7 @@
</template>

<script setup lang="ts">
import {
ref,
computed,
onMounted,
watch,
defineAsyncComponent
} from 'vue'
import { ref, computed, onMounted, watch, defineAsyncComponent } from 'vue'
import Listbox from 'primevue/listbox'
import Tabs from 'primevue/tabs'
import TabPanels from 'primevue/tabpanels'
Expand Down Expand Up @@ -196,11 +189,18 @@ const searchResults = computed<ISettingGroup[]>(() => {
filteredSettingIds.value.forEach((id) => {
const setting = settingStore.settings[id]
const groupLabel = getSettingInfo(setting).subCategory
if (!groupedSettings[groupLabel]) {
groupedSettings[groupLabel] = []
const info = getSettingInfo(setting)
const groupLabel = info.subCategory
if (
activeCategory.value === null ||
activeCategory.value.label === info.category
) {
if (!groupedSettings[groupLabel]) {
groupedSettings[groupLabel] = []
}
groupedSettings[groupLabel].push(setting)
}
groupedSettings[groupLabel].push(setting)
})
return Object.entries(groupedSettings).map(([label, settings]) => ({
Expand All @@ -223,7 +223,7 @@ const searchResultsCategories = computed<Set<string>>(() => {
const handleSearch = (query: string) => {
if (!query) {
filteredSettingIds.value = []
activeCategory.value = getDefaultCategory()
activeCategory.value ??= getDefaultCategory()
return
}
Expand Down Expand Up @@ -254,6 +254,13 @@ const inSearch = computed(
const tabValue = computed(() =>
inSearch.value ? 'Search Results' : activeCategory.value?.label
)
// Don't allow null category to be set outside of search.
// In search mode, the active category can be null to show all search results.
watch(activeCategory, (_, oldValue) => {
if (!tabValue.value) {
activeCategory.value = oldValue
}
})
</script>

<style>
Expand Down

0 comments on commit 1329a3a

Please sign in to comment.