use allplatforms

This commit is contained in:
Georges-Antoine Assi
2026-07-25 07:39:54 -04:00
parent e626c31315
commit e9539dadeb
4 changed files with 15 additions and 29 deletions

View File

@@ -2,11 +2,7 @@ import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, it } from "vitest";
import storePlatforms, { type Platform } from "@/stores/platforms";
function platform(
id: number,
displayName: string,
romCount: number,
): Platform {
function platform(id: number, displayName: string, romCount: number): Platform {
return {
id,
display_name: displayName,
@@ -29,7 +25,7 @@ describe("platform store lists", () => {
store.set([filled, empty]);
expect(store.allPlatforms).toEqual([empty, filled]);
expect(store.filledPlatforms).toEqual([filled]);
expect(store.platformIndexPlatforms).toEqual([empty, filled]);
});
});

View File

@@ -20,8 +20,6 @@ export default defineStore("platforms", {
all
.filter((p) => p.rom_count > 0)
.sort((a, b) => a.display_name.localeCompare(b.display_name)),
platformIndexPlatforms: ({ allPlatforms: all }) =>
[...all].sort((a, b) => a.display_name.localeCompare(b.display_name)),
filteredPlatforms: ({ allPlatforms: all, filterText }) =>
all
.filter(
@@ -40,7 +38,7 @@ export default defineStore("platforms", {
actions: {
_reorder() {
this.allPlatforms = uniqBy(this.allPlatforms, "id").sort((a, b) => {
return a.name.localeCompare(b.name);
return a.display_name.localeCompare(b.display_name);
});
},
fetchPlatforms(): Promise<Platform[]> {

View File

@@ -1,7 +1,7 @@
import { mount } from "@vue/test-utils";
import { createPinia, setActivePinia } from "pinia";
import { defineComponent, ref } from "vue";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { defineComponent, ref } from "vue";
import storePlatforms, { type Platform } from "@/stores/platforms";
import PlatformsIndex from "./PlatformsIndex.vue";
@@ -30,7 +30,7 @@ vi.mock("@/v2/components/Platforms/PlatformListRow.vue", () => ({
default: defineComponent({
props: ["displayName", "romCount"],
template:
"<div class=\"platform-row\">{{ displayName }} {{ romCount }}</div>",
'<div class="platform-row">{{ displayName }} {{ romCount }}</div>',
}),
}));
@@ -38,21 +38,21 @@ vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({
default: defineComponent({
props: ["displayName", "romCount"],
template:
"<div class=\"platform-tile\">{{ displayName }} {{ romCount }}</div>",
'<div class="platform-tile">{{ displayName }} {{ romCount }}</div>',
}),
}));
vi.mock("@/v2/components/shared/EmptyState.vue", () => ({
default: defineComponent({
props: ["message"],
template: "<div class=\"empty-state\">{{ message }}</div>",
template: '<div class="empty-state">{{ message }}</div>',
}),
}));
vi.mock("@/v2/components/shared/IndexShell.vue", () => ({
default: defineComponent({
template:
"<main><slot name=\"header\" /><slot name=\"toolbar\" /><slot name=\"listHeader\" /><slot /></main>",
'<main><slot name="header" /><slot name="toolbar" /><slot name="listHeader" /><slot /></main>',
}),
}));
@@ -88,11 +88,7 @@ vi.mock("@/v2/composables/useWrapGridNav", () => ({
useWrapGridNav: vi.fn(),
}));
function platform(
id: number,
displayName: string,
romCount: number,
): Platform {
function platform(id: number, displayName: string, romCount: number): Platform {
return {
id,
display_name: displayName,
@@ -110,10 +106,7 @@ describe("PlatformsIndex", () => {
it("renders empty database platforms so they remain reachable", () => {
const platforms = storePlatforms();
platforms.set([
platform(2, "Nintendo 64", 12),
platform(1, "Game Boy", 0),
]);
platforms.set([platform(2, "Nintendo 64", 12), platform(1, "Game Boy", 0)]);
const wrapper = mount(PlatformsIndex);

View File

@@ -41,8 +41,7 @@ import { useWrapGridNav } from "@/v2/composables/useWrapGridNav";
const { t } = useI18n();
const platformsStore = storePlatforms();
const { platformIndexPlatforms, fetchingPlatforms } =
storeToRefs(platformsStore);
const { allPlatforms, fetchingPlatforms } = storeToRefs(platformsStore);
const { groupBy, layout } = useGalleryMode();
useGalleryViewModeUrl();
@@ -62,7 +61,7 @@ useWrapGridNav(gridRoot, { cellSelector: ".plat-tile" });
const playableById = computed(() => {
const fn = isPlayable.value;
const map = new Map<number | string, boolean>();
for (const p of platformIndexPlatforms.value) map.set(p.id, fn(p.slug));
for (const p of allPlatforms.value) map.set(p.id, fn(p.slug));
return map;
});
@@ -202,8 +201,8 @@ onMounted(() => {
const filtered = computed<Platform[]>(() => {
const term = searchTerm.value.trim().toLowerCase();
if (!term) return platformIndexPlatforms.value;
return platformIndexPlatforms.value.filter((p) =>
if (!term) return allPlatforms.value;
return allPlatforms.value.filter((p) =>
p.display_name.toLowerCase().includes(term),
);
});
@@ -223,7 +222,7 @@ const sortedForList = computed<Platform[]>(() => {
);
});
const totalCount = computed(() => platformIndexPlatforms.value.length);
const totalCount = computed(() => allPlatforms.value.length);
const noResults = computed(
() =>
!fetchingPlatforms.value &&