fixed library scan using event listeners instead of store pattern

This commit is contained in:
2026-02-24 15:04:35 -05:00
parent 1221a403cf
commit d764fefb10
14 changed files with 612 additions and 136 deletions
@@ -4,7 +4,6 @@ import {
state,
query,
} from 'lit/decorators.js';
import { EventsOn } from '@runtime/runtime';
import '@lit-labs/virtualizer';
import type {
LitVirtualizer,
@@ -24,7 +23,6 @@ import {
contextMenuStyles,
} from '@utils/context-menu-controller.js';
import type { ContextMenuHost } from '@utils/context-menu-controller.js';
import { Events } from '../../events';
import '@awesome.me/webawesome/dist/components/icon/icon.js';
import '@awesome.me/webawesome/dist/components/popup/popup.js';
import '@awesome.me/webawesome/dist/components/dropdown-item/dropdown-item.js';
@@ -60,9 +58,12 @@ export class ArtistsView
private libraryCtrl = new LibraryController(this);
private searchCtrl = new SearchController(this);
private ctxMenu = new ContextMenuController(this);
private cancelScanComplete?: () => void;
private wheelListenerAttached = false;
private lastSearchTerm = '';
/** Tracks the store's cached array reference to detect refreshes. */
private lastArtistsRef: library.Artist[] | null =
null;
private scrollDebounceTimer: ReturnType<
typeof setTimeout
> | null = null;
@@ -376,15 +377,10 @@ export class ArtistsView
super.connectedCallback();
this.loadCardSize();
this.loadArtists();
this.cancelScanComplete = EventsOn(
Events.LibraryScanComplete,
() => this.loadArtists(),
);
}
override disconnectedCallback() {
super.disconnectedCallback();
this.cancelScanComplete?.();
this.detachWheelListener();
if (this.scrollDebounceTimer !== null) {
@@ -404,6 +400,19 @@ export class ArtistsView
this.lastSearchTerm = currentTerm;
this.clearSelection();
}
// Re-fetch when the store delivers fresh
// data after eager refetch on invalidation.
const cached =
this.libraryCtrl.cachedArtists;
if (
cached !== null &&
cached !== this.lastArtistsRef
) {
this.lastArtistsRef = cached;
this.loadArtists();
}
}
/* ================================================================