Skip to content

Commit

Permalink
renderer: store: fix search hang when result is empty
Browse files Browse the repository at this point in the history
optional chaining! nullish coalescing! yay!
  • Loading branch information
rocka committed Oct 11, 2021
1 parent 149b6b5 commit f21a9c7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/renderer/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,44 +258,44 @@ export async function search({ state, commit }, { keyword, type, limit = 20, off
switch (type) {
case 'song':
const { songCount, songs } = resp.result;
result.total = songCount || songs.length || 0;
result.total = songCount ?? songs?.length ?? 0;
if (result.total > 0) {
const source = { name: 'search', id: state.ui.search.keyword };
result.items = songs.map(i => new Track(i, { source }));
}
break;
case 'artist':
const { artistCount, artists } = resp.result;
result.total = artistCount || artists.length || 0;
result.total = artistCount ?? artists?.length ?? 0;
if (result.total > 0) {
result.items = artists;
}
break;
case 'album':
const { albumCount, albums } = resp.result;
// sometimes, albumCount is `0` but album.length != 0
result.total = albumCount || albums.length || 0;
result.total = albumCount ?? albums?.length ?? 0;
if (result.total > 0) {
result.items = albums;
}
break;
case 'playlist':
const { playlistCount, playlists } = resp.result;
result.total = playlistCount || playlists.length || 0;
result.total = playlistCount ?? playlists?.length ?? 0;
if (result.total > 0) {
result.items = playlists;
}
break;
case 'video':
const { videoCount, videos } = resp.result;
result.total = videoCount || videos.length || 0;
result.total = videoCount ?? videos?.length ?? 0;
if (result.total > 0) {
result.items = videos.map(v => new Video(v));
}
break;
case 'user':
const { userprofileCount, userprofiles } = resp.result;
result.total = userprofileCount || userprofiles.length || 0;
result.total = userprofileCount ?? userprofiles?.length ?? 0;
if (result.total > 0) {
result.items = userprofiles;
}
Expand Down

0 comments on commit f21a9c7

Please sign in to comment.