From 4facf548ad9a83b3f561e1dfd18d1ab70114fd97 Mon Sep 17 00:00:00 2001 From: dvirtz Date: Sun, 12 Jan 2025 23:23:00 +0000 Subject: [PATCH] fix: improve track filtering logic in album import need to filter after matching recordings to works fixes #52 --- src/acum-work-import/import-album.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/acum-work-import/import-album.ts b/src/acum-work-import/import-album.ts index 332f97d..a5e11bd 100644 --- a/src/acum-work-import/import-album.ts +++ b/src/acum-work-import/import-album.ts @@ -5,12 +5,14 @@ import { filter, from, ignoreElements, + iif, lastValueFrom, map, merge, mergeMap, of, pipe, + repeat, scan, tap, toArray, @@ -168,12 +170,12 @@ async function selectedRecordings( from(medium.tracks!.map(track => trackRecordingState(track, recordingStateTree))) ); }), - filter((trackAndRecordingState): trackAndRecordingState is [number, MediumRecordingStateT] => { - const [, recordingState] = trackAndRecordingState; + zipWith(iif(() => entity == Entity.Work, from(workBeans).pipe(repeat()), from(workBeans))), + map(([[position, recordingState], workBean]) => [position, workBean, recordingState] as const), + filter((state): state is [number, WorkBean, MediumRecordingStateT] => { + const [, , recordingState] = state; return recordingState != null && (noSelection || recordingState.isSelected); }), - zipWith(from(workBeans)), - map(([[position, recordingState], workBean]) => [position, workBean, recordingState] as const), toArray() ) );