Skip to content

Commit

Permalink
Merge pull request #241 from Brn9hrd7/master
Browse files Browse the repository at this point in the history
Removed a few duplicated code lines
  • Loading branch information
nukeop authored Feb 7, 2019
2 parents 5cf3a5e + cc73d5d commit cb29478
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
10 changes: 5 additions & 5 deletions app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function unifiedSearchError () {

function discogsSearch (terms, searchType, dispatchType) {
return dispatch => {
return searchType(terms)
return discogs.search(terms, searchType)
.then(searchResults => searchResults.json())
.then(searchResultsJson => {
dispatch({
Expand All @@ -85,11 +85,11 @@ function discogsSearch (terms, searchType, dispatchType) {
}

export function albumSearch (terms) {
return discogsSearch(terms, discogs.searchReleases, 'ALBUM_SEARCH_SUCCESS');
return discogsSearch(terms, 'albums', 'ALBUM_SEARCH_SUCCESS');
}

export function artistSearch (terms) {
return discogsSearch(terms, discogs.searchArtists, 'ARTIST_SEARCH_SUCCESS');
return discogsSearch(terms, 'artists', 'ARTIST_SEARCH_SUCCESS');
}

export function lastFmTrackSearchStart (terms) {
Expand Down Expand Up @@ -286,7 +286,7 @@ export function artistReleasesSearch (artistId) {
export function artistInfoSearchByName (artistName, history) {
return dispatch => {
discogs
.searchArtists(artistName)
.search(artistName, 'artists')
.then(searchResults => searchResults.json())
.then(searchResultsJson => {
let artist = searchResultsJson.results[0];
Expand All @@ -305,7 +305,7 @@ export function artistInfoSearchByName (artistName, history) {
export function albumInfoSearchByName (albumName, history) {
return dispatch => {
discogs
.searchAlbums(albumName)
.search(albumName, 'albums')
.then(searchResults => searchResults.json())
.then(searchResultsJson => {
let album = searchResultsJson.results[0];
Expand Down
2 changes: 1 addition & 1 deletion app/components/TrackInfo/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.track_name {
margin-bottom: 10px;
font-size: 22px;
overflow: hidden;
overflow: visible;
white-space: nowrap;
text-overflow: ellipsis;
}
Expand Down
28 changes: 5 additions & 23 deletions app/rest/Discogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ const secret = 'uluhDSPtelRtLUvjrvQhRBnNwpZMtkZq';

function addToken (query, first = false) {
let newQuery = query + '&token=' + userToken;
if (first) {
return newQuery.replace('&', '?');
} else {
return newQuery;
}
return first ? newQuery.replace('&', '?') : newQuery;
}

function addKeys (query, first = false) {
let newQuery = query + '&key=' + key + '&secret=' + secret;
if (first) {
return newQuery.replace('&', '?');
} else {
return newQuery;
}
return first ? newQuery.replace('&', '?') : newQuery;
}

function searchQuery (terms, count = 15) {
Expand All @@ -30,16 +22,8 @@ function searchQuery (terms, count = 15) {
);
}

function searchAlbums (terms, count = 15) {
return fetch(searchQuery(terms, count) + '&type=albums');
}

function searchArtists (terms, count = 15) {
return fetch(searchQuery(terms, count) + '&type=artist');
}

function searchReleases (terms, count = 15) {
return fetch(searchQuery(terms, count) + '&type=master');
function search (terms, type, count = 15) {
return fetch(searchQuery(terms, count) + '&type=' + type);
}

function releaseInfo (releaseId, releaseType) {
Expand Down Expand Up @@ -69,9 +53,7 @@ function artistReleases (artistId) {
}

module.exports = {
searchAlbums,
searchArtists,
searchReleases,
search,
releaseInfo,
artistInfo,
artistReleases
Expand Down

0 comments on commit cb29478

Please sign in to comment.