From 97a5f80eef8317b4ca16f84902813da6f420f8bc Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Thu, 1 Oct 2026 13:54:05 -0400 Subject: [PATCH] Check the active sort in the gallery sort menu (#4998) * Check the active sort in the gallery sort menu The grid toolbar's sort menu (and its phone-width mirror) marked the active axis by colour alone. It now also shows a leading check, the same way the version switcher and sibling menus mark the current item. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6 * Share the sort menu's selection mark and test the phone menu Both sort menus now take their active variant and check from one selectionMark helper, and the toolbar test covers the phone-width menu as well as the inline one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6 * Reset the toolbar test's breakpoint in teardown and drop a restating comment Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6 --------- Co-authored-by: Claude Opus 5.5 --- .../components/Gallery/GalleryToolbar.test.ts | 24 ++++++++++++++----- .../v2/components/Gallery/GalleryToolbar.vue | 11 +++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts b/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts index fd525c348..6419d3e51 100644 --- a/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts +++ b/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts @@ -1,5 +1,5 @@ import { mount } from "@vue/test-utils"; -import { describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { ref } from "vue"; import GalleryToolbar from "./GalleryToolbar.vue"; @@ -7,8 +7,9 @@ vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }), })); +const smAndUp = ref(true); vi.mock("@/v2/composables/useBreakpoint", () => ({ - useBreakpoint: () => ({ smAndUp: ref(true) }), + useBreakpoint: () => ({ smAndUp }), })); const modality = ref<"mouse" | "pad">("mouse"); @@ -88,6 +89,10 @@ describe("GalleryToolbar search autofocus", () => { }); describe("GalleryToolbar sort axis", () => { + afterEach(() => { + smAndUp.value = true; + }); + it("emits the picked axis so grid mode can change the sort key", async () => { const wrapper = mountWithSortOptions(); @@ -101,17 +106,24 @@ describe("GalleryToolbar sort axis", () => { wrapper.unmount(); }); - it("marks the active axis", () => { + it.each([ + ["the toolbar menu", true], + ["the phone-width menu", false], + ])("marks the active axis with a check in %s", (_, wide) => { + smAndUp.value = wide; const wrapper = mountWithSortOptions({ sortKey: "fs_size_bytes" }); - const variants = Object.fromEntries( + const marks = Object.fromEntries( sortItems(wrapper).map((item) => [ item.props("label"), - item.props("variant"), + [item.props("variant"), item.props("icon")], ]), ); - expect(variants).toMatchObject({ Size: "active", Title: "default" }); + expect(marks).toEqual({ + Size: ["active", "mdi-check"], + Title: ["default", undefined], + }); wrapper.unmount(); }); diff --git a/frontend/src/v2/components/Gallery/GalleryToolbar.vue b/frontend/src/v2/components/Gallery/GalleryToolbar.vue index b663ad09b..85349d6e6 100644 --- a/frontend/src/v2/components/Gallery/GalleryToolbar.vue +++ b/frontend/src/v2/components/Gallery/GalleryToolbar.vue @@ -232,6 +232,13 @@ function setSortDir(value: "asc" | "desc") { emit("update:sortDir", value); } +function selectionMark(selected: boolean) { + return { + variant: selected ? ("active" as const) : ("default" as const), + icon: selected ? "mdi-check" : undefined, + }; +} + function setSortKey(value: ListSortKey) { emit("update:sortKey", value); } @@ -350,7 +357,7 @@ const { smAndUp } = useBreakpoint(); v-for="item in sortKeyItems" :key="item.key" :label="item.label" - :variant="sortKeyValue === item.key ? 'active' : 'default'" + v-bind="selectionMark(sortKeyValue === item.key)" @click="setSortKey(item.key)" /> @@ -422,7 +429,7 @@ const { smAndUp } = useBreakpoint(); v-for="item in sortKeyItems" :key="item.key" :label="item.label" - :variant="sortKeyValue === item.key ? 'active' : 'default'" + v-bind="selectionMark(sortKeyValue === item.key)" @click="setSortKey(item.key)" />