@@ -31,11 +31,13 @@ import storeRoms, { type SimpleRom } from "@/stores/roms";
3131import storeScanning , { type ScanningPlatform } from "@/stores/scanning" ;
3232import type { Events } from "@/types/emitter" ;
3333import { useSocketEvent } from "@/v2/composables/useSocketEvent" ;
34+ import storeGalleryRoms from "@/v2/stores/galleryRoms" ;
3435
3536export 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 ) ;
0 commit comments