Skip to content

Commit 76bb948

Browse files
authored
Merge pull request #3745 from rommapp/posthog-code/live-scan-platform-games
fix: remove deleted games from gallery store
2 parents 7f94fdb + c43cd26 commit 76bb948

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

frontend/src/v2/components/Dialogs/DeleteRomDialog.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import storeConfig from "@/stores/config";
1414
import storeRoms, { type SimpleRom } from "@/stores/roms";
1515
import type { Events } from "@/types/emitter";
1616
import { useSnackbar } from "@/v2/composables/useSnackbar";
17+
import storeGalleryRoms from "@/v2/stores/galleryRoms";
1718
1819
defineOptions({ inheritAttrs: false });
1920
@@ -22,6 +23,7 @@ const router = useRouter();
2223
const route = useRoute();
2324
const show = ref(false);
2425
const romsStore = storeRoms();
26+
const galleryRomsStore = storeGalleryRoms();
2527
const roms = ref<SimpleRom[]>([]);
2628
const romsToDeleteFromFs = ref<number[]>([]);
2729
const excludeOnDelete = ref(false);
@@ -100,6 +102,7 @@ async function deleteRoms() {
100102
}
101103
romsStore.resetSelection();
102104
romsStore.remove(roms.value);
105+
galleryRomsStore.remove(roms.value);
103106
romsStore.setRecentRoms(
104107
romsStore.recentRoms.filter(
105108
(r) => !roms.value.some((rom) => rom.id === r.id),

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import storeRoms, { type SimpleRom } from "@/stores/roms";
3131
import storeScanning, { type ScanningPlatform } from "@/stores/scanning";
3232
import type { Events } from "@/types/emitter";
3333
import { useSocketEvent } from "@/v2/composables/useSocketEvent";
34+
import storeGalleryRoms from "@/v2/stores/galleryRoms";
3435

3536
export function installScanLifecycle() {
3637
const scanningStore = storeScanning();
3738
const romsStore = storeRoms();
3839
const platformsStore = storePlatforms();
40+
const galleryRomsStore = storeGalleryRoms();
3941
const emitter = inject<Emitter<Events>>("emitter");
4042

4143
useSocketEvent<ScanningPlatform>(
@@ -87,6 +89,14 @@ export function installScanLifecycle() {
8789
// ROM. Queue drains every 100ms; matches the v1 behavior. Stored
8890
// outside the handler so multiple events share the same queue + flush.
8991
const romUpdateQueue: SimpleRom[] = [];
92+
const refreshGallery = debounce(
93+
() => {
94+
galleryRomsStore.invalidateWindows();
95+
void galleryRomsStore.fetchInitialMetadata();
96+
},
97+
250,
98+
{ maxWait: 1000 },
99+
);
90100
const processRomUpdates = debounce(() => {
91101
if (romUpdateQueue.length === 0) return;
92102
const updates = romUpdateQueue.splice(0, romUpdateQueue.length);
@@ -97,7 +107,10 @@ export function installScanLifecycle() {
97107
romsStore.addToRecent(rom);
98108

99109
// If the user is currently looking at the gallery of the platform
100-
// being scanned, fold the new ROM into the visible list.
110+
// being scanned, refresh from the server to preserve sorting/filtering.
111+
if (galleryRomsStore.currentPlatform?.id === rom.platform_id) {
112+
refreshGallery();
113+
}
101114
if (romsStore.currentPlatform?.id === rom.platform_id) {
102115
const existing = romsStore.filteredRoms.find((r) => r.id === rom.id);
103116
if (existing) romsStore.update(rom);

frontend/src/v2/stores/galleryRoms.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,24 @@ export default defineStore("v2GalleryRoms", {
566566
}
567567
},
568568

569-
/** Drop ROMs by id (delete flow). Positions become "holes" — kept
570-
* sparse rather than re-indexed; the next gallery refresh closes the
571-
* gaps. */
569+
/** Reconcile the gallery after ROMs are deleted. */
572570
remove(roms: SimpleRom[]) {
573-
const ids = new Set(roms.map((r) => r.id));
574-
for (const [pos, existing] of this.byPosition) {
575-
if (ids.has(existing.id)) this.byPosition.delete(pos);
571+
if (this.currentPlatform) {
572+
const removedFromPlatform = roms.filter(
573+
(rom) => rom.platform_id === this.currentPlatform?.id,
574+
).length;
575+
this.currentPlatform = {
576+
...this.currentPlatform,
577+
rom_count: Math.max(
578+
0,
579+
this.currentPlatform.rom_count - removedFromPlatform,
580+
),
581+
};
582+
}
583+
584+
if (this.onGalleryView && roms.length > 0) {
585+
this.invalidateWindows();
586+
void this.fetchInitialMetadata();
576587
}
577588
},
578589
},

0 commit comments

Comments
 (0)