Skip to content

Commit

Permalink
Update playlists.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop authored Nov 8, 2023
1 parent 4e464c0 commit d48b6b7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/app/app/actions/playlists.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if (!(playlist.tracks?.length > 0)) {
import fs from 'fs';
import { v4 } from 'uuid';
import { remote } from 'electron';
Expand Down Expand Up @@ -134,7 +135,7 @@ export function addPlaylistFromUrl(playlist: SpotifyPlaylist, t) {
let playlists = store.get('playlists') || [];
const importedPlaylist = PlaylistHelper.formatPlaylistForStorage(playlist.name, playlist.tracks, v4(), playlist.source);

if (!playlist.tracks || playlist.tracks.length === 0) {
if (!(playlist.tracks?.length > 0)) {
dispatch(error(t('import-fail-title'), t('error-empty-data'), null, null));
return;
}
Expand All @@ -161,9 +162,9 @@ export function addPlaylistFromFile(filePath, t) {

try {
const parsed = JSON.parse(data.toString());
const name = parsed?.name;
const tracks = parsed?.tracks;
const source = parsed?.source;
const name = parsed && 'name' in parsed ? parsed.name : null;
const tracks = parsed && 'tracks' in parsed ? parsed.tracks : null;
const source = parsed && 'source' in parsed ? parsed.source : null;

if (!name || !tracks) {
throw new Error('missing tracks or name');
Expand All @@ -172,7 +173,7 @@ export function addPlaylistFromFile(filePath, t) {
let playlists = store.get('playlists') || [];
const playlist = PlaylistHelper.formatPlaylistForStorage(name, tracks, v4(), source);

if (!tracks || tracks.length === 0) {
if (!(tracks?.length > 0)) {
dispatch(error(t('import-fail-title'), t('error-empty-data'), null, null));
return;
}
Expand Down

0 comments on commit d48b6b7

Please sign in to comment.