Skip to content

Commit

Permalink
Solved Code Quality Issues (no-use-before-define)
Browse files Browse the repository at this point in the history
  • Loading branch information
trekiteasy committed Jan 16, 2019
1 parent 5b394dc commit 507e193
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 66 deletions.
66 changes: 33 additions & 33 deletions app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ export function artistSearch(terms) {
return discogsSearch(terms, discogs.searchArtists, 'ARTIST_SEARCH_SUCCESS');
}

export function lastFmTrackSearchStart(terms) {
return {
type: LASTFM_TRACK_SEARCH_START,
payload: terms,
};
}

export function lastFmTrackSearchSuccess(terms, searchResults) {
return {
type: LASTFM_TRACK_SEARCH_SUCCESS,
payload: {
id: terms,
info: searchResults,
},
};
}

export function lastFmTrackSearch(terms) {
return dispatch => {
dispatch(lastFmTrackSearchStart(terms));
Promise.all([lastfmRest.searchTracks(terms)])
.then(results => Promise.all(results.map(info => info.json())))
.then(results => {
dispatch(
lastFmTrackSearchSuccess(terms, results[0].results.trackmatches.track)
);
})
.catch(error => {
logger.error(error);
});
};
}

export function unifiedSearch(terms, history) {
return dispatch => {
dispatch(unifiedSearchStart());
Expand Down Expand Up @@ -272,36 +305,3 @@ export function lastFmArtistInfoSearch(artist, artistId) {
});
};
}

export function lastFmTrackSearchStart(terms) {
return {
type: LASTFM_TRACK_SEARCH_START,
payload: terms,
};
}

export function lastFmTrackSearchSuccess(terms, searchResults) {
return {
type: LASTFM_TRACK_SEARCH_SUCCESS,
payload: {
id: terms,
info: searchResults,
},
};
}

export function lastFmTrackSearch(terms) {
return dispatch => {
dispatch(lastFmTrackSearchStart(terms));
Promise.all([lastfmRest.searchTracks(terms)])
.then(results => Promise.all(results.map(info => info.json())))
.then(results => {
dispatch(
lastFmTrackSearchSuccess(terms, results[0].results.trackmatches.track)
);
})
.catch(error => {
logger.error(error);
});
};
}
34 changes: 17 additions & 17 deletions app/actions/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ export const UPDATE_SEEK = 'UPDATE_SEEK';
export const UPDATE_VOLUME = 'UPDATE_VOLUME';
export const UPDATE_PLAYBACK_STREAM_LOADING = 'UPDATE_PLAYBACK_STREAM_LOADING';

export function togglePlayback(currentState) {
return dispatch => {
if (currentState === Sound.status.PLAYING) {
dispatch(pausePlayback());
} else {
dispatch(startPlayback());
}
};
}

export function startPlayback() {
sendPlay();
return {
type: START_PLAYBACK,
payload: null
payload: null,
};
}

export function pausePlayback() {
sendPaused();
return {
type: PAUSE_PLAYBACK,
payload: null
payload: null,
};
}

export function togglePlayback(currentState) {
return dispatch => {
if (currentState === Sound.status.PLAYING) {
dispatch(pausePlayback());
} else {
dispatch(startPlayback());
}
};
}

Expand All @@ -39,28 +39,28 @@ export function updatePlaybackProgress(progress, seek) {
type: UPDATE_PLAYBACK_PROGRESS,
payload: {
progress,
seek
}
seek,
},
};
}

export function updateSeek(seek) {
return {
type: UPDATE_SEEK,
payload: seek
payload: seek,
};
}

export function updateVolume(volume) {
return {
type: UPDATE_VOLUME,
payload: volume
payload: volume,
};
}

export function updateStreamLoading(state) {
return {
type: UPDATE_PLAYBACK_STREAM_LOADING,
payload: state
payload: state,
};
}
18 changes: 8 additions & 10 deletions app/persistence/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@ import electronStore from 'electron-store';
import options from '../constants/settings';

const store = new electronStore();
initStore();

function initStore() {
if(!store.get('lastFm')){
if (!store.get('lastFm')) {
store.set('lastFm', {});
}

if(!store.get('settings')){
if (!store.get('settings')) {
store.set('settings', {});
}

if(!store.get('playlists')){
if (!store.get('playlists')) {
store.set('playlists', []);
}
}

initStore();

function getOption(key) {
let settings = store.get('settings') || {};
let value = settings[key];
if (value === undefined) {
value = _.find(options, { name: key }).default;
value = _.find(options, { name: key }).default;
}

return value;
}

function setOption(key, value) {
let settings = store.get('settings') || {};
store.set(
'settings',
Object.assign({}, settings, {[`${key}`]: value})
);
store.set('settings', Object.assign({}, settings, { [`${key}`]: value }));
}

export { store, getOption, setOption };
12 changes: 6 additions & 6 deletions app/rest/LastFm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import globals from '../globals';
let lastfmApiKey = globals.lastfmApiKey;
let lastfmApiSecret = globals.lastfmApiSecret;

function makeLastfmRequest(parameters) {
return fetch(
apiUrl + parameters + '&api_key=' + lastfmApiKey + '&format=json'
);
}

function searchTracks(terms) {
let parameters = 'track.search&track=' + encodeURI(terms);
return makeLastfmRequest(parameters);
Expand All @@ -15,12 +21,6 @@ function getTopTracks() {
return makeLastfmRequest(parameters);
}

function makeLastfmRequest(parameters) {
return fetch(
apiUrl + parameters + '&api_key=' + lastfmApiKey + '&format=json'
);
}

module.exports = {
searchTracks,
getTopTracks,
Expand Down

0 comments on commit 507e193

Please sign in to comment.