Skip to content

Commit 83dd1b3

Browse files
simplify filtering
1 parent 88ed4fe commit 83dd1b3

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/renderer/components/Browser.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,14 @@ export default function Browser({ onClose }: BrowserProps) {
104104
useEffect(() => {
105105
if (!storeLibrary) return;
106106

107-
const filteredSongs = { ...storeLibrary };
108-
Object.keys(filteredSongs).forEach((key) => {
109-
const song = filteredSongs[key];
110-
if (
111-
(selection.artist && song.common.artist !== selection.artist) ||
112-
(selection.album && song.common.album !== selection.album)
113-
) {
114-
delete filteredSongs[key];
115-
}
116-
});
107+
const filteredSongs = Object.fromEntries(
108+
Object.entries(storeLibrary).filter(([_, song]) => {
109+
return (
110+
(!selection.artist || song.common.artist === selection.artist) &&
111+
(!selection.album || song.common.album === selection.album)
112+
);
113+
}),
114+
);
117115

118116
setFilteredLibrary(filteredSongs);
119117
}, [selection, storeLibrary, setFilteredLibrary]);

0 commit comments

Comments
 (0)