Skip to content

Commit e20f842

Browse files
committed
fix: refresh gallery after scanned ROMs
Generated-By: PostHog Code Task-Id: b131c873-6e03-47dd-bf51-c99f01ef1f5f
1 parent ea6f3fb commit e20f842

2 files changed

Lines changed: 11 additions & 36 deletions

File tree

frontend/src/v2/composables/useScanLifecycle/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import type { Emitter } from "mitt";
2626
import { inject } from "vue";
2727
import type { ScanStats } from "@/__generated__";
2828
import platformApi from "@/services/api/platform";
29-
import storeGalleryFilter from "@/stores/galleryFilter";
3029
import storePlatforms from "@/stores/platforms";
3130
import storeRoms, { type SimpleRom } from "@/stores/roms";
3231
import storeScanning, { type ScanningPlatform } from "@/stores/scanning";
@@ -38,7 +37,6 @@ export function installScanLifecycle() {
3837
const scanningStore = storeScanning();
3938
const romsStore = storeRoms();
4039
const platformsStore = storePlatforms();
41-
const galleryFilterStore = storeGalleryFilter();
4240
const galleryRomsStore = storeGalleryRoms();
4341
const emitter = inject<Emitter<Events>>("emitter");
4442

@@ -91,6 +89,14 @@ export function installScanLifecycle() {
9189
// ROM. Queue drains every 100ms; matches the v1 behavior. Stored
9290
// outside the handler so multiple events share the same queue + flush.
9391
const romUpdateQueue: SimpleRom[] = [];
92+
const refreshGallery = debounce(
93+
() => {
94+
galleryRomsStore.invalidateWindows();
95+
void galleryRomsStore.fetchInitialMetadata();
96+
},
97+
250,
98+
{ maxWait: 1000 },
99+
);
94100
const processRomUpdates = debounce(() => {
95101
if (romUpdateQueue.length === 0) return;
96102
const updates = romUpdateQueue.splice(0, romUpdateQueue.length);
@@ -101,13 +107,9 @@ export function installScanLifecycle() {
101107
romsStore.addToRecent(rom);
102108

103109
// If the user is currently looking at the gallery of the platform
104-
// being scanned, fold the new ROM into the visible list.
105-
if (
106-
galleryRomsStore.currentPlatform?.id === rom.platform_id &&
107-
!galleryFilterStore.searchTerm &&
108-
!galleryFilterStore.isFiltered()
109-
) {
110-
galleryRomsStore.addLiveRom(rom);
110+
// being scanned, refresh from the server to preserve sorting/filtering.
111+
if (galleryRomsStore.currentPlatform?.id === rom.platform_id) {
112+
refreshGallery();
111113
}
112114
if (romsStore.currentPlatform?.id === rom.platform_id) {
113115
const existing = romsStore.filteredRoms.find((r) => r.id === rom.id);

frontend/src/v2/stores/galleryRoms.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -228,33 +228,6 @@ export default defineStore("v2GalleryRoms", {
228228
return null;
229229
},
230230

231-
/** Add a ROM announced by the scan socket to the active gallery. */
232-
addLiveRom(rom: SimpleRom) {
233-
let existingPosition: number | undefined;
234-
for (const [position, existing] of this.byPosition) {
235-
if (existing.id === rom.id) {
236-
existingPosition = position;
237-
break;
238-
}
239-
}
240-
if (existingPosition !== undefined) {
241-
this.byPosition.set(existingPosition, rom);
242-
return;
243-
}
244-
245-
const position = this.total;
246-
this.byPosition.set(position, rom);
247-
this.total += 1;
248-
this.romIdIndex.push(rom.id);
249-
250-
if (this.currentPlatform?.id === rom.platform_id) {
251-
this.currentPlatform = {
252-
...this.currentPlatform,
253-
rom_count: this.currentPlatform.rom_count + 1,
254-
};
255-
}
256-
},
257-
258231
/** Drop everything tied to the previous gallery context but keep
259232
* order-by / order-dir. Call before switching platform / collection
260233
* or when filters change. */

0 commit comments

Comments
 (0)