refactor(v2): apply simplify findings

- Route tab and subtab writes through patchQuery.
- Keep the CRT/reduced-motion rule inside useCrtMode: reduced motion hides
  CRT without erasing the saved choice, and turning CRT on turns it off.
- Reuse the global asset fade on Home's empty library.
- useLoadingPhase: refAutoReset for the skeleton hold, drop the unused delay
  parameter.
- One computed per empty state in Streaming and platform stats; drop RTable's
  unused empty slot.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAReUPhZXnp7LyiP1W4GGQ
This commit is contained in:
zurdi
2026-09-17 19:19:24 +02:00
parent b84daec449
commit 76ddf4f699
11 changed files with 87 additions and 93 deletions

View File

@@ -25,7 +25,11 @@ vi.mock("vue-i18n", () => ({
vi.mock("vue-router", async (importOriginal) => ({
...(await importOriginal<typeof import("vue-router")>()),
useRoute: () => ({ query: routeQuery, path: "/rom/1", params: {} }),
useRouter: () => ({ replace: vi.fn(), push: vi.fn() }),
useRouter: () => ({
replace: vi.fn(),
push: vi.fn(),
currentRoute: { value: { query: routeQuery } },
}),
}));
vi.mock("@/services/api/rom", () => ({
default: { uploadRoms, deleteRomFile: vi.fn() },

View File

@@ -76,6 +76,12 @@ const orderItems = computed<SliderBtnGroupItem<OrderBy>[]>(() => [
},
]);
const emptyState = computed(() =>
searchQuery.value.trim()
? { icon: "mdi-magnify-close", title: t("settings.no-matching-platforms") }
: { icon: "mdi-folder-question", title: t("settings.no-platforms") },
);
const sortedPlatforms = computed(() => {
const q = searchQuery.value.trim().toLowerCase();
let list = [...filledPlatforms.value];
@@ -331,15 +337,7 @@ function onRowClick(e: MouseEvent, platformId: number): void {
class="r-v2-plat-stats__bar"
/>
</a>
<REmptyState
v-if="sortedPlatforms.length === 0"
:icon="searchQuery.trim() ? 'mdi-magnify-close' : 'mdi-folder-question'"
:title="
searchQuery.trim()
? t('settings.no-matching-platforms')
: t('settings.no-platforms')
"
/>
<REmptyState v-if="sortedPlatforms.length === 0" v-bind="emptyState" />
</div>
</section>
</template>

View File

@@ -8,7 +8,7 @@
// an admin needs: open its desktop to configure the emulator inside it, and
// end whatever session is holding it.
import { RBtn, REmptyState, RIcon, RSpinner } from "@v2/lib";
import { onMounted, ref } from "vue";
import { computed, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { ROUTES } from "@/plugins/router";
@@ -35,6 +35,25 @@ const loadFailed = ref(false);
const containers = ref<AdminStreamingContainer[]>([]);
const releasing = ref<string | null>(null);
const emptyState = computed<{ icon: string; title: string } | null>(() => {
if (loadFailed.value) {
return {
icon: "mdi-alert-circle-outline",
title: t("settings.streaming-load-failed"),
};
}
if (!enabled.value) {
return { icon: "mdi-monitor-off", title: t("settings.streaming-disabled") };
}
if (containers.value.length === 0) {
return {
icon: "mdi-monitor-dashboard",
title: t("settings.streaming-none"),
};
}
return null;
});
async function load(): Promise<void> {
loading.value = true;
loadFailed.value = false;
@@ -120,26 +139,7 @@ onMounted(load);
<RSpinner />
</div>
<REmptyState
v-else-if="loadFailed"
size="small"
icon="mdi-alert-circle-outline"
:title="t('settings.streaming-load-failed')"
/>
<REmptyState
v-else-if="!enabled"
size="small"
icon="mdi-monitor-off"
:title="t('settings.streaming-disabled')"
/>
<REmptyState
v-else-if="containers.length === 0"
size="small"
icon="mdi-monitor-dashboard"
:title="t('settings.streaming-none')"
/>
<REmptyState v-else-if="emptyState" size="small" v-bind="emptyState" />
<template v-else>
<div

View File

@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { nextTick } from "vue";
const KEY = "settings.v2.crtMode";
const REDUCED_MOTION_KEY = "settings.v2.reducedMotion";
// `enabled` is a module-level singleton created at import time, so it reads
// localStorage exactly once on load. Re-import the module fresh after seeding
@@ -57,6 +58,26 @@ describe("useCrtMode", () => {
expect(localStorage.getItem(KEY)).toBe("true");
});
it("stays off under reduced motion without erasing the saved choice", async () => {
localStorage.setItem(KEY, "true");
localStorage.setItem(REDUCED_MOTION_KEY, "true");
const { enabled } = await loadFresh();
expect(enabled.value).toBe(false);
expect(localStorage.getItem(KEY)).toBe("true");
});
it("turns reduced motion off when switched on", async () => {
localStorage.setItem(REDUCED_MOTION_KEY, "true");
const { enabled } = await loadFresh();
enabled.value = true;
await nextTick();
expect(enabled.value).toBe(true);
expect(localStorage.getItem(REDUCED_MOTION_KEY)).toBe("false");
});
it("shares a single instance across calls within a load", async () => {
vi.resetModules();
const { useCrtMode } = await import("./index");

View File

@@ -11,8 +11,22 @@
// shared reactivity within a tab), so we create it once here and everyone
// imports the same instance.
import { useLocalStorage } from "@vueuse/core";
import { computed } from "vue";
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
const enabled = useLocalStorage("settings.v2.crtMode", false);
const stored = useLocalStorage("settings.v2.crtMode", false);
const { enabled: reducedMotion, toggle: toggleReducedMotion } =
useReducedMotion();
// Reduced motion breaks the overlay's endless animations, so it hides CRT
// without erasing the saved choice, and turning CRT on turns it off.
const enabled = computed<boolean>({
get: () => stored.value && !reducedMotion.value,
set: (on) => {
stored.value = on;
if (on && reducedMotion.value) toggleReducedMotion();
},
});
export function useCrtMode() {
/** Flip CRT mode and return the new state (true = now on). */

View File

@@ -1,8 +1,8 @@
// Picks skeleton, empty or content for a loading view. Until loading outlasts
// `delayMs` the last settled phase stays up, so a fast load never flashes.
// the skeleton delay the last settled phase stays up, so a fast load never flashes.
import { refAutoReset } from "@vueuse/core";
import {
nextTick,
onScopeDispose,
shallowRef,
toValue,
watchEffect,
@@ -22,12 +22,10 @@ export const SKELETON_MIN_MS = 300;
export function useLoadingPhase(
loading: MaybeRefOrGetter<boolean>,
empty: MaybeRefOrGetter<boolean>,
delayMs: MaybeRefOrGetter<number> = SKELETON_DELAY_MS,
): Readonly<ShallowRef<LoadingPhase>> {
const skeletonDue = useDelayedFlag(loading, delayMs);
const skeletonDue = useDelayedFlag(loading, SKELETON_DELAY_MS);
const phase = shallowRef<LoadingPhase>("idle");
const holdingSkeleton = shallowRef(false);
let holdTimer: ReturnType<typeof setTimeout> | null = null;
const holdingSkeleton = refAutoReset(false, SKELETON_MIN_MS);
// Empty at setup often means a fetch that only starts in onMounted, so the
// first "empty" waits a tick for that load to begin.
const ready = shallowRef(false);
@@ -44,16 +42,8 @@ export function useLoadingPhase(
} else if (skeletonDue.value && phase.value !== "skeleton") {
phase.value = "skeleton";
holdingSkeleton.value = true;
holdTimer = setTimeout(() => {
holdTimer = null;
holdingSkeleton.value = false;
}, SKELETON_MIN_MS);
}
});
onScopeDispose(() => {
if (holdTimer) clearTimeout(holdTimer);
});
return phase;
}

View File

@@ -1,6 +1,7 @@
// Binds a details tab's active subtab to the route's `?subtab=` param.
import { shallowRef, watch, type Ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { patchQuery } from "@/v2/utils/routeQuery";
export function useSubtabQuery<T extends string>(
tabId: string,
@@ -21,11 +22,7 @@ export function useSubtabQuery<T extends string>(
const subtab = shallowRef(fromRoute() ?? fallback) as Ref<T>;
watch(subtab, (value) => {
if (route.query.subtab === value) return;
void router.replace({
path: route.path,
query: { ...route.query, subtab: value },
});
if (route.query.subtab !== value) patchQuery(router, { subtab: value });
});
watch([() => route.query.tab, () => route.query.subtab], () => {

View File

@@ -31,7 +31,6 @@ import SoundtrackMiniPlayer from "@/v2/components/Soundtrack/MiniPlayer.vue";
import { BACKGROUND_ART_KEY } from "@/v2/composables/useBackgroundArt";
import { installBreakpointAttribute } from "@/v2/composables/useBreakpoint";
import { installPermissionsHydration } from "@/v2/composables/useCan";
import { useCrtMode } from "@/v2/composables/useCrtMode";
import { useDebugMode } from "@/v2/composables/useDebugMode";
import { installGalleryProvenance } from "@/v2/composables/useGalleryProvenance";
import { useGamepad } from "@/v2/composables/useGamepad";
@@ -62,22 +61,14 @@ installStageActiveClass();
// (not the shell root) for the same reason as the theme classes: Vuetify
// teleports overlays outside the app tree, and this keeps the flag reachable
// there too.
const { enabled: reducedMotion, toggle: toggleReducedMotion } =
useReducedMotion();
// The reduced-motion neutralize breaks CRT mode's endless animations, so the
// two exclude each other; with both saved on, reduced motion wins.
const { enabled: crtMode } = useCrtMode();
const { enabled: reducedMotion } = useReducedMotion();
watch(
reducedMotion,
(on) => {
document.documentElement.classList.toggle("r-v2-reduced-motion", on);
if (on) crtMode.value = false;
},
{ immediate: true },
);
watch(crtMode, (on) => {
if (on && reducedMotion.value) toggleReducedMotion();
});
const collectionsStore = storeCollections();
const platformsStore = storePlatforms();

View File

@@ -235,15 +235,13 @@ onBeforeUnmount(() => {
</template>
<template v-else-if="phase === 'empty'">
<slot name="empty">
<REmptyState
variant="plain"
size="small"
:icon="emptyIcon"
:icon-size="32"
:title="emptyMessage"
/>
</slot>
<REmptyState
variant="plain"
size="small"
:icon="emptyIcon"
:icon-size="32"
:title="emptyMessage"
/>
</template>
<template v-else-if="phase === 'content'">

View File

@@ -35,6 +35,7 @@ import { useRightStickScroll } from "@/v2/composables/useRightStickScroll";
import { useRomScanRefresh } from "@/v2/composables/useRomScanRefresh";
import { useWebpSupport } from "@/v2/composables/useWebpSupport";
import { isRomVerified } from "@/v2/utils/romVerification";
import { patchQuery } from "@/v2/utils/routeQuery";
const route = useRoute();
const router = useRouter();
@@ -89,11 +90,7 @@ const tab = ref<string>((route.query.tab as string) || "overview");
watch(tab, (value) => {
if (route.query.tab !== value) {
// The subtab and note belong to the tab being left.
const { subtab: _subtab, note: _note, ...query } = route.query;
router.replace({
path: route.path,
query: { ...query, tab: value },
});
patchQuery(router, { tab: value, subtab: undefined, note: undefined });
}
});
watch(

View File

@@ -282,7 +282,7 @@ function collectionCovers(c: {
<!-- Empty library state — shown when nothing has been ingested
yet. Hides every section underneath so the user lands on a
decision (upload vs scan), not on a row of skeletons. -->
<section v-if="phase === 'empty'" class="r-v2-home-empty">
<section v-if="phase === 'empty'" class="r-v2-home-empty r-v2-asset-fade">
<div class="r-v2-home-empty__hero">
<RIcon
icon="mdi-controller-classic-outline"
@@ -300,7 +300,7 @@ function collectionCovers(c: {
disk" telemetry from both entry points. -->
<div
v-if="libraryInfo && detectedPlatformCount + detectedGameCount > 0"
class="r-v2-home-empty__detected"
class="r-v2-home-empty__detected r-v2-asset-fade"
>
<RChip
size="small"
@@ -678,8 +678,6 @@ function collectionCovers(c: {
padding: var(--r-space-10) var(--r-space-6);
min-height: 60vh;
justify-content: center;
animation: r-v2-home-fade-in var(--r-motion-slow) var(--r-motion-ease-out)
both;
}
.r-v2-home-empty__hero {
@@ -720,20 +718,6 @@ function collectionCovers(c: {
justify-content: center;
gap: var(--r-space-2);
margin-top: var(--r-space-2);
animation: r-v2-home-fade-in var(--r-motion-med) var(--r-motion-ease-out) both;
}
@keyframes r-v2-home-fade-in {
from {
opacity: 0;
transform: translateY(6px);
}
}
@media (prefers-reduced-motion: reduce) {
.r-v2-home-empty,
.r-v2-home-empty__detected {
animation: none;
}
}
.r-v2-home-empty__choices {