From 50d021d43709e66681df51f69ed2ab2601ff4d4e Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Sun, 25 Oct 2026 20:52:22 -0500 Subject: [PATCH] chore(frontend): remove the deprecated gallery-list state from the roms store (#5354) * chore(frontend): remove the deprecated gallery-list state from the roms store The v1 gallery list (current platform and collections, _allRoms, paging, order-by, selection, fetchRoms) had no caller left after the v1 UI was removed. What remains is what production code uses: the detailed-ROM cache, Home's recent and continue-playing rows, currentRom, and reset (which logout calls on every store). The consumers that still read or wrote the removed state were dead branches and are dropped with it. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01JKqnUCfoaS7bWkMLmGJ5qq * docs(frontend): trim the comments left by the roms store cleanup Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01JKqnUCfoaS7bWkMLmGJ5qq * docs(frontend): shorten the removeCachedRoms docstring Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01JKqnUCfoaS7bWkMLmGJ5qq --------- Co-authored-by: Claude Sonnet 5.5 --- .../components/Dialogs/DeleteRomDialog.vue | 1 - .../Dialogs/ManageCollectionsDialog.test.ts | 4 +- .../components/Gallery/SelectionBar.test.ts | 5 +- frontend/src/composables/useFavoriteToggle.ts | 7 +- .../src/composables/useRomSync/index.test.ts | 7 +- frontend/src/composables/useRomSync/index.ts | 13 +- .../src/composables/useScanLifecycle/index.ts | 5 - frontend/src/stores/galleryRoms.ts | 24 +- frontend/src/stores/gallerySelection.ts | 10 +- frontend/src/stores/roms.ts | 325 +----------------- 10 files changed, 21 insertions(+), 380 deletions(-) diff --git a/frontend/src/components/Dialogs/DeleteRomDialog.vue b/frontend/src/components/Dialogs/DeleteRomDialog.vue index 2aad55da2..e8cf23084 100644 --- a/frontend/src/components/Dialogs/DeleteRomDialog.vue +++ b/frontend/src/components/Dialogs/DeleteRomDialog.vue @@ -140,7 +140,6 @@ async function deleteRoms() { }); } } - romsStore.resetSelection(); removeCachedRoms(deletedRoms); // Deletion is permanent, so unlike the other `removeCachedRoms` callers // this one also takes the ROMs out of Home's rows. diff --git a/frontend/src/components/Dialogs/ManageCollectionsDialog.test.ts b/frontend/src/components/Dialogs/ManageCollectionsDialog.test.ts index 2f220e8b1..e1faa39c6 100644 --- a/frontend/src/components/Dialogs/ManageCollectionsDialog.test.ts +++ b/frontend/src/components/Dialogs/ManageCollectionsDialog.test.ts @@ -6,7 +6,7 @@ import storeAuth from "@/stores/auth"; import storeCollections, { type Collection } from "@/stores/collections"; import storeGalleryRoms from "@/stores/galleryRoms"; import storeGallerySelection from "@/stores/gallerySelection"; -import storeRoms, { type SimpleRom } from "@/stores/roms"; +import type { SimpleRom } from "@/stores/roms"; import type { Events } from "@/types/emitter"; import { collectionFixture } from "@/utils/collection.fixtures"; import { romFixture } from "@/utils/rom.fixtures"; @@ -130,7 +130,6 @@ describe("ManageCollectionsDialog gallery reconcile", () => { const galleryRemove = vi.spyOn(gallery, "remove").mockImplementation(() => { /* the real one refetches the gallery */ }); - const romsRemove = vi.spyOn(storeRoms(), "remove"); const selection = storeGallerySelection(); [rom(1), rom(2)].forEach((r, i) => selection.toggle(r, i)); @@ -139,7 +138,6 @@ describe("ManageCollectionsDialog gallery reconcile", () => { expect(removeRomsFromCollection).toHaveBeenCalledWith(12, [1, 2]); expect(galleryRemove).toHaveBeenCalledTimes(1); expect(galleryRemove.mock.calls[0]![0].map((r) => r.id)).toEqual([1, 2]); - expect(romsRemove).toHaveBeenCalledTimes(1); expect(selection.count).toBe(0); }); diff --git a/frontend/src/components/Gallery/SelectionBar.test.ts b/frontend/src/components/Gallery/SelectionBar.test.ts index 4a6adbe68..f37c68863 100644 --- a/frontend/src/components/Gallery/SelectionBar.test.ts +++ b/frontend/src/components/Gallery/SelectionBar.test.ts @@ -5,7 +5,7 @@ import storeAuth from "@/stores/auth"; import storeCollections, { type Collection } from "@/stores/collections"; import storeGalleryRoms from "@/stores/galleryRoms"; import storeGallerySelection from "@/stores/gallerySelection"; -import storeRoms, { type SimpleRom } from "@/stores/roms"; +import type { SimpleRom } from "@/stores/roms"; import { stubResizeObserver } from "@/test-utils/resizeObserver"; import { collectionFixture } from "@/utils/collection.fixtures"; import { romFixture } from "@/utils/rom.fixtures"; @@ -221,15 +221,12 @@ describe("SelectionBar bulk favorite", () => { const galleryRemove = vi.spyOn(gallery, "remove").mockImplementation(() => { /* the real one refetches the gallery */ }); - const roms = storeRoms(); - const romsRemove = vi.spyOn(roms, "remove"); select(rom(1), rom(2)); await clickHeart(mountBar()); expect(galleryRemove).toHaveBeenCalledTimes(1); expect(galleryRemove.mock.calls[0]![0].map((r) => r.id)).toEqual([1, 2]); - expect(romsRemove).toHaveBeenCalledTimes(1); expect(storeGallerySelection().count).toBe(0); }); diff --git a/frontend/src/composables/useFavoriteToggle.ts b/frontend/src/composables/useFavoriteToggle.ts index 842c8102b..171e11804 100644 --- a/frontend/src/composables/useFavoriteToggle.ts +++ b/frontend/src/composables/useFavoriteToggle.ts @@ -2,12 +2,11 @@ import type { Emitter } from "mitt"; import { storeToRefs } from "pinia"; import collectionApi from "@/services/api/collection"; import storeCollections from "@/stores/collections"; -import storeRoms, { type SimpleRom } from "@/stores/roms"; +import type { SimpleRom } from "@/stores/roms"; import type { Events } from "@/types/emitter"; export function useFavoriteToggle(emitter?: Emitter) { const collectionsStore = storeCollections(); - const romsStore = storeRoms(); const { favoriteCollection } = storeToRefs(collectionsStore); async function ensureFavoriteCollection() { @@ -51,10 +50,6 @@ export function useFavoriteToggle(emitter?: Emitter) { collectionsStore.updateCollection(data); - if (currentlyFav && romsStore.currentCollection?.id === fav.id) { - romsStore.remove([rom]); - } - emitter?.emit("snackbarShow", { msg: `${rom.name} ${currentlyFav ? "removed from" : "added to"} ${data.name} successfully!`, icon: "mdi-check-bold", diff --git a/frontend/src/composables/useRomSync/index.test.ts b/frontend/src/composables/useRomSync/index.test.ts index 774537a0e..3163aebb8 100644 --- a/frontend/src/composables/useRomSync/index.test.ts +++ b/frontend/src/composables/useRomSync/index.test.ts @@ -236,14 +236,12 @@ describe("useRomSync", () => { expect(getRoms).not.toHaveBeenCalled(); }); - // The three caches a removed ROM has to leave. Missing any one of them is + // The caches a removed ROM has to leave. Missing any one of them is // what #4151 and #4204 each had to fix, one call site at a time. - it("removeCachedRoms drops the ROMs from the gallery, the v1 store and the selection", () => { + it("removeCachedRoms drops the ROMs from the gallery and the selection", () => { const removed = namedRom({ id: 1 }); const kept = namedRom({ id: 2 }); const gallery = seedGallery(removed); - const romsStore = storeRoms(); - romsStore._allRoms = [removed, kept]; const selection = storeGallerySelection(); selection.setSelection([removed, kept]); @@ -251,7 +249,6 @@ describe("useRomSync", () => { expect(gallery.byPosition.size).toBe(0); expect(getRoms).toHaveBeenCalled(); - expect(romsStore._allRoms).toEqual([kept]); expect([...selection.selected.keys()]).toEqual([2]); }); diff --git a/frontend/src/composables/useRomSync/index.ts b/frontend/src/composables/useRomSync/index.ts index 5b644c154..239a2213c 100644 --- a/frontend/src/composables/useRomSync/index.ts +++ b/frontend/src/composables/useRomSync/index.ts @@ -72,19 +72,10 @@ export function useRomSync() { } } - /** Drop ROMs that have left the current view from every cache holding - * them: the gallery's windowed cache, the v1 store, and the selection. - * Missing any one of the three leaves the cards on screen. - * - * Says nothing about *why* they left. Callers that remove a ROM from a - * view (a bulk unfavourite, a collection removal) and callers that delete - * it outright both need these three, but only the latter should also - * prune Home's recent / continue-playing rows: a game taken out of a - * collection still belongs in Continue Playing. That pruning stays with - * the caller that means it. */ + /** Drop ROMs that have left the current view from the gallery cache and the + * selection. Callers that delete a ROM outright must also prune Home's rows. */ function removeCachedRoms(roms: SimpleRom[]) { gallerySelection.removeIds(roms.map((rom) => rom.id)); - romsStore.remove(roms); galleryRomsStore.remove(roms); } diff --git a/frontend/src/composables/useScanLifecycle/index.ts b/frontend/src/composables/useScanLifecycle/index.ts index 26b2bd358..4994bb8bd 100644 --- a/frontend/src/composables/useScanLifecycle/index.ts +++ b/frontend/src/composables/useScanLifecycle/index.ts @@ -139,11 +139,6 @@ export function installScanLifecycle() { if (galleryRomsStore.currentPlatform?.id === rom.platform_id) { refreshGallery(); } - if (romsStore.currentPlatform?.id === rom.platform_id) { - const existing = romsStore.filteredRoms.find((r) => r.id === rom.id); - if (existing) romsStore.update(rom); - else romsStore.add([rom]); - } let scannedPlatform = scanningStore.scanningPlatforms.find( (p) => p.fs_slug === rom.platform_fs_slug, diff --git a/frontend/src/stores/galleryRoms.ts b/frontend/src/stores/galleryRoms.ts index 7958dc561..bcf7c82f5 100644 --- a/frontend/src/stores/galleryRoms.ts +++ b/frontend/src/stores/galleryRoms.ts @@ -1,6 +1,5 @@ -// galleryRoms (v2): windowed/sparse store for the active gallery list. +// galleryRoms: windowed/sparse store for the active gallery list. // -// Replaces v1's `stores/roms.ts` for the gallery-list responsibility. // What lives here: // - the gallery context (currentPlatform / Collection / Virtual / Smart), // - the total ROM count + per-letter offset table from the backend, @@ -8,20 +7,12 @@ // fetched so far, // - book-keeping for in-flight / loaded / failed windows. // -// Why a NEW store rather than extending v1: -// v1 collapses pagination into `fetchRoms()` advancing a single -// `fetchOffset`. v2 needs random-access window loads (driven by which -// rows enter the virtualiser's viewport, including skeleton rows for -// positions we've never touched). Forking lets v2 model that cleanly -// while v1 stays frozen. Per the constitution, the v1 gallery-list -// surface is annotated `@deprecated` with a pointer here. +// Visible rows drive random-access window loads, including rows whose +// positions have not been fetched yet. // // What does NOT live here: -// - detailedRoms (lives in `stores/roms`, GameDetails reads it), -// - recentRoms / continuePlayingRoms (Home consumers stay on v1), -// - selection state, order-by/order-dir, -// These are still served by the v1 store; the v2 gallery view doesn't -// need them. +// - detailedRoms, recentRoms and continuePlayingRoms (`stores/roms`), +// - selection state (`stores/gallerySelection`). import axios from "axios"; import { defineStore } from "pinia"; import type { SimpleRomSchema } from "@/__generated__/"; @@ -254,9 +245,8 @@ interface State { // Whether the last answer to an unset sort came back in relevance order, // which the backend signals with no letter positions. Kept across refetches. relevanceLed: boolean; - // Order params: gallery-list scoped (separate from v1's localStorage - // keys so v1/v2 don't fight over the same value). `null` leaves the - // order to the backend, which ranks a search by relevance. + // Order params: gallery-list scoped. `null` leaves the order to the + // backend, which ranks a search by relevance. orderBy: GalleryOrderKey | null; orderDir: GalleryOrderDir; } diff --git a/frontend/src/stores/gallerySelection.ts b/frontend/src/stores/gallerySelection.ts index 8df568d15..07058c1db 100644 --- a/frontend/src/stores/gallerySelection.ts +++ b/frontend/src/stores/gallerySelection.ts @@ -1,8 +1,5 @@ -// v2GallerySelection: multi-select state for the gallery views -// (Platform / Search / Collection). v2-only; v1's `stores/roms.ts` -// still owns the legacy selection fields and is the canonical store -// for v1: v2 starts fresh so the existing surface can be improved -// without bending the v1 contract. +// gallerySelection: multi-select state for the gallery views +// (Platform / Search / Collection). // // Selection model: // - `selected: Map`, the source of truth, keyed @@ -20,8 +17,7 @@ // array, because v2's gallery is virtualised + sparse. // - `enabled` getter: true when at least one ROM is selected. The // "selection mode" is implicit (no separate flag): first toggle -// enters it, `clear()` exits it. Simpler than v1's -// `selectingRoms: boolean` toggle, and matches the user-facing +// enters it, `clear()` exits it. That matches the user-facing // expectation: "I am selecting iff I have selections." // // Scope: diff --git a/frontend/src/stores/roms.ts b/frontend/src/stores/roms.ts index 320f596b3..ea4f93c71 100644 --- a/frontend/src/stores/roms.ts +++ b/frontend/src/stores/roms.ts @@ -1,29 +1,10 @@ -import { isNull, isUndefined } from "lodash"; import { defineStore } from "pinia"; import type { DetailedRomSchema, SimpleRomSchema, SearchRomSchema, } from "@/__generated__/"; -import type { CustomLimitOffsetPage_SimpleRomSchema_ as GetRomsResponse } from "@/__generated__/models/CustomLimitOffsetPage_SimpleRomSchema_"; -import { - userStorage, - useUserLocalStorage, -} from "@/composables/useUserLocalStorage"; import cachedApiService from "@/services/cache/api"; -import { - type Collection, - type VirtualCollection, - type SmartCollection, -} from "@/stores/collections"; -import storeGalleryFilter from "@/stores/galleryFilter"; -import storePlatforms from "@/stores/platforms"; -import { type Platform } from "@/stores/platforms"; -import type { ExtractPiniaStoreType } from "@/types"; -import { toError } from "@/utils/toError"; - -type GalleryFilterStore = ExtractPiniaStoreType; -type PlatformsStore = ExtractPiniaStoreType; export type SimpleRom = SimpleRomSchema; export type SearchRom = SearchRomSchema; @@ -33,62 +14,11 @@ export type DetailedRom = DetailedRomSchema; // the player view that picks up the details page's record. export const DETAILED_ROM_CACHE_SIZE = 3; -const orderByStorage = useUserLocalStorage("roms.orderBy", ""); -const orderDirStorage = useUserLocalStorage("roms.orderDir", "asc"); - -// NOTE on deprecation: the gallery-list responsibility (currentPlatform / -// Collection / Virtual / Smart, _allRoms, fetchOffset, fetchTotalRoms, -// characterIndex, romIdIndex, fetchRoms / resetPagination / reset, plus -// the order-by setters) has moved to the v2 store at -// `src/stores/galleryRoms.ts` (windowed sparse loading). v1 keeps the -// originals for the frozen v1 UI; v2 imports the new store. Per-field -// @deprecated tags annotate the migrated surface so v1 cleanup is -// trivial when the time comes. -const defaultRomsState = { - /** @deprecated v2: use `useGalleryRoms().currentPlatform` from - * `@/stores/galleryRoms`. */ - currentPlatform: null as Platform | null, - /** @deprecated v2: use `useGalleryRoms().currentCollection`. */ - currentCollection: null as Collection | null, - /** @deprecated v2: use `useGalleryRoms().currentVirtualCollection`. */ - currentVirtualCollection: null as VirtualCollection | null, - /** @deprecated v2: use `useGalleryRoms().currentSmartCollection`. */ - currentSmartCollection: null as SmartCollection | null, - /** @deprecated v2: read the route's ROM with `useRouteRom()`, which - * looks it up in `detailedRoms`. */ - currentRom: null as DetailedRom | null, - /** @deprecated v2: rooms live in a sparse `byPosition` map on - * `useGalleryRoms()`; iterate via `getRomAt(position)`. */ - _allRoms: [] as SimpleRom[], - selectedIDs: new Set(), - recentRoms: [] as SimpleRom[], - continuePlayingRoms: [] as SimpleRom[], - lastSelectedIndex: -1, - selectingRoms: false, - /** @deprecated v2: per-window flags live on `useGalleryRoms()` - * (`pendingWindows`, `initialFetching`). */ - fetchingRoms: false, - initialSearch: false, - /** @deprecated v2: window position is implicit in the sparse map; - * read `useGalleryRoms().total` for the total count. */ - fetchOffset: 0, - /** @deprecated v2: use `useGalleryRoms().total`. */ - fetchTotalRoms: 0, - fetchLimit: 72, - /** @deprecated v2: use `useGalleryRoms().charIndex`. */ - characterIndex: {} as Record, - selectedCharacter: null as string | null, - /** @deprecated v2: use `useGalleryRoms().romIdIndex`. */ - romIdIndex: [] as number[], - /** @deprecated v2: use `useGalleryRoms().orderBy` (gallery-scoped). */ - orderBy: orderByStorage.value as keyof SimpleRom | "", - /** @deprecated v2: use `useGalleryRoms().orderDir`. */ - orderDir: orderDirStorage.value as "asc" | "desc", -}; - export default defineStore("roms", { state: () => ({ - ...defaultRomsState, + currentRom: null as DetailedRom | null, + recentRoms: [] as SimpleRom[], + continuePlayingRoms: [] as SimpleRom[], /** Detailed ROMs by id, most recently cached last. */ detailedRoms: new Map(), }), @@ -96,28 +26,9 @@ export default defineStore("roms", { getters: { getDetailedRom: (state) => (id: number) => state.detailedRoms.get(id) ?? null, - filteredRoms: (state) => state._allRoms, - selectedRoms: (state) => - state._allRoms.filter((rom) => state.selectedIDs.has(rom.id)), - onGalleryView: (state) => - !!( - state.currentPlatform || - state.currentCollection || - state.currentVirtualCollection || - state.currentSmartCollection - ), }, actions: { - _shouldGroupRoms(): boolean { - return isNull(userStorage.getItem("settings.groupRoms")) - ? true - : userStorage.getItem("settings.groupRoms") === "true"; - }, - /** @deprecated v2: use `useGalleryRoms().setCurrentPlatform`. */ - setCurrentPlatform(platform: Platform | null) { - this.currentPlatform = platform; - }, setCurrentRom(rom: DetailedRom) { this.currentRom = rom; this.cacheDetailedRom(rom); @@ -149,167 +60,6 @@ export default defineStore("roms", { setContinuePlayingRoms(roms: SimpleRom[]) { this.continuePlayingRoms = roms; }, - /** @deprecated v2: use `useGalleryRoms().setCurrentCollection`. */ - setCurrentCollection(collection: Collection | null) { - this.currentCollection = collection; - }, - /** @deprecated v2: use `useGalleryRoms().setCurrentVirtualCollection`. */ - setCurrentVirtualCollection(collection: VirtualCollection | null) { - this.currentVirtualCollection = collection; - }, - /** @deprecated v2: use `useGalleryRoms().setCurrentSmartCollection`. */ - setCurrentSmartCollection(collection: SmartCollection | null) { - this.currentSmartCollection = collection; - }, - // Fetching multiple roms - _buildRequestParams(galleryFilter: GalleryFilterStore) { - // Determine platform IDs - let platformIds: number[] | null = null; - - // Prioritize currentPlatform if set, as it indicates a single platform view - if (this.currentPlatform) { - platformIds = [this.currentPlatform.id]; - } else if (galleryFilter.selectedPlatforms.length > 0) { - // Otherwise, use multi-select platforms from filter - platformIds = galleryFilter.selectedPlatforms.map((p) => p.id); - } else if (galleryFilter.selectedPlatform) { - // Fallback to single selected platform from filter - platformIds = [galleryFilter.selectedPlatform.id]; - } - - const params = { - searchTerm: galleryFilter.searchTerm, - platformIds: platformIds, - collectionId: this.currentCollection?.id ?? null, - virtualCollectionId: this.currentVirtualCollection?.id ?? null, - smartCollectionId: this.currentSmartCollection?.id ?? null, - limit: this.fetchLimit, - offset: this.fetchOffset, - orderBy: this.orderBy, - orderDir: this.orderDir, - groupByMetaId: this._shouldGroupRoms() && this.onGalleryView, - filterMatched: galleryFilter.filterMatched, - filterFavorites: galleryFilter.filterFavorites, - filterDuplicates: galleryFilter.filterDuplicates, - filterPlayables: galleryFilter.filterPlayables, - filterRA: galleryFilter.filterRA, - filterMissing: galleryFilter.filterMissing, - filterVerified: galleryFilter.filterVerified, - selectedGenres: galleryFilter.selectedGenres, - selectedFranchises: galleryFilter.selectedFranchises, - selectedCollections: galleryFilter.selectedCollections, - selectedCompanies: galleryFilter.selectedCompanies, - selectedAgeRatings: galleryFilter.selectedAgeRatings, - selectedRegions: galleryFilter.selectedRegions, - selectedLanguages: galleryFilter.selectedLanguages, - selectedPlayerCounts: galleryFilter.selectedPlayerCounts, - selectedMetadataProviders: galleryFilter.selectedMetadataProviders, - selectedTags: galleryFilter.selectedTags, - selectedStatuses: galleryFilter.selectedStatuses, - // Logic operators - genresLogic: galleryFilter.genresLogic, - franchisesLogic: galleryFilter.franchisesLogic, - collectionsLogic: galleryFilter.collectionsLogic, - companiesLogic: galleryFilter.companiesLogic, - ageRatingsLogic: galleryFilter.ageRatingsLogic, - regionsLogic: galleryFilter.regionsLogic, - languagesLogic: galleryFilter.languagesLogic, - statusesLogic: galleryFilter.statusesLogic, - playerCountsLogic: galleryFilter.playerCountsLogic, - metadataProvidersLogic: galleryFilter.metadataProvidersLogic, - tagsLogic: galleryFilter.tagsLogic, - }; - return params; - }, - _postFetchRoms( - response: GetRomsResponse, - galleryFilter: GalleryFilterStore, - platformsStore: PlatformsStore, - concat: boolean, - ) { - const { items, offset, total, char_index, rom_id_index, filter_values } = - response; - if (!concat || this.fetchOffset === 0) { - this._allRoms = items; - } else { - this._allRoms = this._allRoms.concat(items); - } - - // Update the offset and total ROMs in filtered database result - if (offset !== null) this.fetchOffset = offset + this.fetchLimit; - if (total !== null) this.fetchTotalRoms = total; - - // Set the character index for the current platform - this.characterIndex = char_index; - this.romIdIndex = rom_id_index; - - // Only set the list of platforms on first fetch - if (galleryFilter.filterPlatforms.length === 0) { - const platformIds = filter_values?.platforms ?? []; - galleryFilter.setFilterPlatforms( - platformsStore.allPlatforms.filter((p) => platformIds.includes(p.id)), - ); - } - - if (filter_values) { - galleryFilter.setFilterCollections(filter_values.collections); - galleryFilter.setFilterGenres(filter_values.genres); - galleryFilter.setFilterFranchises(filter_values.franchises); - galleryFilter.setFilterCompanies(filter_values.companies); - galleryFilter.setFilterAgeRatings(filter_values.age_ratings); - galleryFilter.setFilterRegions(filter_values.regions); - galleryFilter.setFilterLanguages(filter_values.languages); - galleryFilter.setFilterPlayerCounts(filter_values.player_counts); - galleryFilter.setFilterTags(filter_values.tags); - } - }, - /** @deprecated v2: use `useGalleryRoms().fetchWindowAt(position)` for - * windowed loading. The page-by-page model here is kept for v1 only. */ - async fetchRoms(concat = true): Promise { - if (this.fetchingRoms) return Promise.resolve([]); - this.fetchingRoms = true; - - const galleryFilterStore = storeGalleryFilter(); - const platformsStore = storePlatforms(); - - // Capture current request parameters to validate background updates - const currentRequestParams = this._buildRequestParams(galleryFilterStore); - - return new Promise((resolve, reject) => { - cachedApiService - .getRoms(currentRequestParams, (response) => { - if (concat && this.fetchOffset != 0) return; - - // Check if parameters have changed since the request was made - const currentParams = this._buildRequestParams(galleryFilterStore); - const paramsChanged = - JSON.stringify(currentParams) !== - JSON.stringify(currentRequestParams); - if (paramsChanged) return; - this._postFetchRoms( - response, - galleryFilterStore, - platformsStore, - concat, - ); - }) - .then((response) => { - this._postFetchRoms( - response.data, - galleryFilterStore, - platformsStore, - concat, - ); - resolve(response.data.items); - }) - .catch((error) => { - reject(toError(error)); - }) - .finally(() => { - this.fetchingRoms = false; - }); - }); - }, // Recent ROMs for home page async fetchRecentRoms(): Promise { const response = await cachedApiService.getRecentRoms((data) => { @@ -328,9 +78,6 @@ export default defineStore("roms", { this.setContinuePlayingRoms(items); return items; }, - add(roms: SimpleRom[]) { - this._allRoms = this._allRoms.concat(roms); - }, addToRecent(rom: SimpleRom) { this.recentRoms = [rom, ...this.recentRoms]; void cachedApiService.clearRecentRomsCache(); @@ -350,9 +97,6 @@ export default defineStore("roms", { void cachedApiService.clearRecentPlayedRomsCache(); }, update(rom: SimpleRom) { - this._allRoms = this._allRoms.map((value) => - value.id === rom.id ? rom : value, - ); this.recentRoms = this.recentRoms.map((value) => value.id === rom.id ? rom : value, ); @@ -363,71 +107,10 @@ export default defineStore("roms", { // view on stale `rom_user` data until the next route entry. this.mergeIntoDetailedRom(rom); }, - remove(roms: SimpleRom[]) { - this._allRoms = this._allRoms.filter((value) => { - return !roms.find((rom) => { - return rom.id === value.id; - }); - }); - }, - /** @deprecated v2: use `useGalleryRoms().resetGallery()`. */ + // Logout calls `reset` on every store. reset() { - this.currentPlatform = null; - this.currentCollection = null; - this.currentVirtualCollection = null; - this.currentSmartCollection = null; this.currentRom = null; this.detailedRoms.clear(); - this._allRoms = []; - this.selectedIDs = new Set(); - this.lastSelectedIndex = -1; - this.selectingRoms = false; - this.fetchingRoms = false; - this.initialSearch = false; - this.characterIndex = {}; - this.selectedCharacter = null; - this.romIdIndex = []; - this.resetPagination(); - }, - /** @deprecated v2: use `useGalleryRoms().invalidateWindows()`. */ - resetPagination() { - this.fetchOffset = 0; - this.fetchTotalRoms = 0; - }, - setSelection(roms: SimpleRom[]) { - this.selectedIDs = new Set(roms.map((rom) => rom.id)); - }, - addToSelection(rom: SimpleRom) { - this.selectedIDs.add(rom.id); - }, - removeFromSelection(rom: SimpleRom) { - this.selectedIDs.delete(rom.id); - }, - updateLastSelected(index: number) { - this.lastSelectedIndex = index; - }, - setSelecting() { - this.selectingRoms = !this.selectingRoms; - }, - resetSelection() { - this.selectedIDs = new Set(); - this.lastSelectedIndex = -1; - }, - /** @deprecated v2: use `useGalleryRoms().setOrderBy`. */ - setOrderBy(orderBy: keyof SimpleRom | "") { - this.orderBy = orderBy; - orderByStorage.value = orderBy; - }, - /** @deprecated v2: use `useGalleryRoms().setOrderDir`. */ - setOrderDir(orderDir: "asc" | "desc") { - this.orderDir = orderDir; - orderDirStorage.value = orderDir; - }, - setLimit(limit: number) { - this.fetchLimit = limit; - }, - isSimpleRom(rom: SimpleRom | SearchRom): rom is SimpleRom { - return !isNull(rom.id) && !isUndefined(rom.id); }, }, });