fix(covers): reset result-bound cover filters on new results (code-review)

- Resolution, style and uploader picks come from the loaded results, so
  they reset when a new result set arrives instead of hiding covers once
  their select disappears.
- The Filters count only includes the content switches while they are
  rendered.
- The provider chip row no longer scrolls, which clipped the chips'
  focus ring.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SZKZYnWkAQoTQ6k7z7CrWT
This commit is contained in:
zurdi
2026-09-18 11:42:35 +02:00
parent a4d6a90adb
commit 791116908f
3 changed files with 51 additions and 27 deletions

View File

@@ -332,7 +332,7 @@ function closeDialog() {
<template #toolbar>
<div class="r-v2-sgdb__toolbar">
<div class="r-v2-sgdb__providers r-v2-scroll-hidden">
<div class="r-v2-sgdb__providers">
<MatchRomProviderFilter
v-for="provider in gridProviders"
:key="provider.key"
@@ -610,11 +610,6 @@ function closeDialog() {
display: flex;
align-items: center;
gap: 8px;
overflow-x: auto;
padding-bottom: 2px;
}
.r-v2-sgdb__providers > * {
flex-shrink: 0;
}
.r-v2-sgdb__search-row {
@@ -673,8 +668,6 @@ function closeDialog() {
gap: 12px;
}
/* Phones: the search button drops to a full-width row under the field, the
filter and sort buttons share their row, and the content toggles center. */
html[data-bp~="xs"] .r-v2-sgdb__search-row {
grid-template-columns: 1fr;
}

View File

@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from "vitest";
import { ref } from "vue";
import { nextTick, ref } from "vue";
import type { CoverResource, SearchCoverSchema } from "@/__generated__";
import { useCoverFilters } from "./index";
@@ -85,4 +85,27 @@ describe("useCoverFilters activeFilterCount", () => {
filters.resetFilters();
expect(filters.activeFilterCount.value).toBe(0);
});
it("skips the content switches while their controls are hidden", () => {
const filters = setup([STEAM]);
filters.showNsfw.value = true;
expect(filters.activeFilterCount.value).toBe(0);
});
});
describe("useCoverFilters new results", () => {
it("drops a style picked from the previous results", async () => {
const covers = ref([SGDB]);
const filters = useCoverFilters(covers, ref([]));
filters.styleFilter.value = "alternate";
filters.showNsfw.value = true;
covers.value = [STEAM];
await nextTick();
expect(filters.styleFilter.value).toBe("all");
expect(filters.showNsfw.value).toBe(true);
expect(filters.filteredCovers.value).toHaveLength(1);
});
});

View File

@@ -8,7 +8,7 @@
// The dialog owns the search flow and passes the raw `covers` /
// `providerCovers` refs in; this composable owns the filter state
// and every derived view of those two lists.
import { computed, ref, type Ref } from "vue";
import { computed, ref, watch, type Ref } from "vue";
import { useI18n } from "vue-i18n";
import type { CoverResource, SearchCoverSchema } from "@/__generated__";
import type { MatchedSource } from "@/v2/components/MatchRom/types";
@@ -55,33 +55,26 @@ export function useCoverFilters(
activeProviders.value[provider] = !activeProviders.value[provider];
}
function resetFilters() {
activeProviders.value = { ...ALL_PROVIDERS_ACTIVE };
coverType.value = "all";
// These options come from the loaded results, so a pick from an earlier
// search would keep hiding covers once the new results drop its select.
function resetResultFilters() {
resolutionFilter.value = "all";
styleFilter.value = "all";
uploaderFilter.value = "all";
uploaderSearch.value = "";
}
watch(covers, resetResultFilters);
function resetFilters() {
activeProviders.value = { ...ALL_PROVIDERS_ACTIVE };
coverType.value = "all";
resetResultFilters();
showNsfw.value = false;
showHumor.value = true;
showEpilepsy.value = true;
sortMode.value = "relevance";
}
// Filters narrowing the results away from their `resetFilters` defaults.
const activeFilterCount = computed(
() =>
[
coverType.value !== "all",
resolutionFilter.value !== "all",
styleFilter.value !== "all",
uploaderFilter.value !== "all",
showNsfw.value,
!showHumor.value,
!showEpilepsy.value,
].filter(Boolean).length,
);
function styleLabel(style: string): string {
const key = STYLE_LABEL_KEYS[style];
return key ? t(key) : style;
@@ -101,6 +94,21 @@ export function useCoverFilters(
covers.value.some((g) => g.provider === "sgdb" && g.resources.length > 0),
);
// Filters moved off their `resetFilters` defaults. The content switches
// only render when SteamGridDB answered, so only then do they count.
const activeFilterCount = computed(() => {
const changed = [
coverType.value !== "all",
resolutionFilter.value !== "all",
styleFilter.value !== "all",
uploaderFilter.value !== "all",
];
if (hasSgdbCovers.value) {
changed.push(showNsfw.value, !showHumor.value, !showEpilepsy.value);
}
return changed.filter(Boolean).length;
});
const resolutionValues = computed(() => {
const set = new Set<string>();
for (const r of allResources.value) {