feat(library): remove a track from the library without deleting the file
RemoveFromLibrary deletes the audio_files rows the way the scan's own orphan cleanup does and records each path in excluded_paths. The exclusion is not an enhancement: without it the next scan finds the file, sees no row and imports it again, so the button undoes itself. The soft scan compares files on disk against rows in the database, so surveyAudioFiles and countAudioFiles both take the exclusion set — otherwise an excluded path makes the two disagree forever and queues a full scan on every launch. Deleting a row cascades to queue_tracks, so the removal calls the same CompactQueue hook RemoveLibrary does. Also lands the requested badge: library-status-indicator is a button again where it can act, utils/library-status.ts states once what owning and wanting mean, and the long-declared queued state finally has a producer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UDCbcCZQepnpSQYJ6SxxZm
This commit is contained in:
@@ -383,6 +383,35 @@ describe('shortcut dispatch: scope', () => {
|
||||
|
||||
expect(fired).toBe(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* `tracklist.delete` was advertised in Settings for six phases with
|
||||
* nothing dispatching for it. What it dispatches now only *opens* a
|
||||
* confirmation, which is what makes a destructive action defensible
|
||||
* on an unmodified key one row from the user's music.
|
||||
*/
|
||||
it('dispatches for tracklist.delete, which had nothing on the other end', () => {
|
||||
bindings({ 'tracklist.delete': 'Delete' });
|
||||
|
||||
const panel = mount(document.createElement('div'));
|
||||
const row = document.createElement('div');
|
||||
|
||||
row.tabIndex = 0;
|
||||
panel.dataset['shortcutScope'] = 'tracklist';
|
||||
panel.append(row);
|
||||
row.focus();
|
||||
|
||||
let fired = 0;
|
||||
const listener = (): void => {
|
||||
fired += 1;
|
||||
};
|
||||
|
||||
document.addEventListener('shortcut:tracklist-delete', listener);
|
||||
press('Delete');
|
||||
document.removeEventListener('shortcut:tracklist-delete', listener);
|
||||
|
||||
expect(fired).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -175,6 +175,55 @@ describe('library store: caching', () => {
|
||||
expect(calls()).toEqual([]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Removing tracks is the same bargain the play count makes, one
|
||||
* collection wider: the event carries the paths so the tracks array
|
||||
* — the expensive one — is patched rather than refetched, while the
|
||||
* album/artist/genre summaries, whose counts really did change, are
|
||||
* dropped and reloaded.
|
||||
*/
|
||||
describe('tracks removed from the library', () => {
|
||||
beforeEach(async () => {
|
||||
emit(Events.TracksRemovedFromLibrary, {
|
||||
filePaths: ['/a.mp3'],
|
||||
count: 1,
|
||||
});
|
||||
await flush();
|
||||
});
|
||||
|
||||
it('does not refetch the tracks', () => {
|
||||
expect(calls('library.Library.GetAllTracks')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('splices the removed track out in place', () => {
|
||||
expect(libraryStore.getCachedTracks()?.map((t) => t.FilePath)).toEqual([
|
||||
'/b.mp3',
|
||||
]);
|
||||
});
|
||||
|
||||
it('reloads the summaries, whose counts changed', () => {
|
||||
expect(
|
||||
[
|
||||
'library.Library.GetAllAlbums',
|
||||
'library.Library.GetAllArtists',
|
||||
'library.Library.GetAllGenresWithCounts',
|
||||
].map((path) => calls(path).length),
|
||||
).toEqual([1, 1, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores a removal naming a track it does not hold, without dropping the array', async () => {
|
||||
const before = libraryStore.getCachedTracks();
|
||||
|
||||
emit(Events.TracksRemovedFromLibrary, {
|
||||
filePaths: ['/not-in-this-library.mp3'],
|
||||
count: 1,
|
||||
});
|
||||
await flush();
|
||||
|
||||
expect(libraryStore.getCachedTracks()).toBe(before);
|
||||
});
|
||||
|
||||
it('resets scroll positions on invalidation, so a shorter list is not scrolled past its end', async () => {
|
||||
libraryStore.setScrollPosition('albums', 4200);
|
||||
emit(Events.LibraryScanComplete);
|
||||
|
||||
Reference in New Issue
Block a user