forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert connectivity and dashboard (nukeop#1034)
* Convert connectivity and dashboard * Fix types
- Loading branch information
Showing
9 changed files
with
363 additions
and
595 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createStandardAction } from 'typesafe-actions'; | ||
import { Connectivity } from './actionTypes'; | ||
|
||
export const changeConnectivity = createStandardAction(Connectivity.CHANGE_CONNECTIVITY)(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import logger from 'electron-timber'; | ||
import { rest } from '@nuclear/core'; | ||
import { getBestNewAlbums, getBestNewTracks } from 'pitchfork-bnm'; | ||
import { Deezer } from '@nuclear/core/src/rest'; | ||
|
||
import globals from '../globals'; | ||
import { Dashboard } from './actionTypes'; | ||
import { createAsyncAction } from 'typesafe-actions'; | ||
|
||
const lastfm = new rest.LastFmApi( | ||
globals.lastfmApiKey, | ||
globals.lastfmApiSecret | ||
); | ||
|
||
export const loadTopTagsAction = createAsyncAction( | ||
Dashboard.LOAD_TOP_TAGS_START, | ||
Dashboard.LOAD_TOP_TAGS_SUCCESS, | ||
Dashboard.LOAD_TOP_TAGS_ERROR | ||
)<undefined, unknown, undefined>(); | ||
|
||
export function loadTopTags() { | ||
return dispatch => { | ||
dispatch(loadTopTagsAction.request()); | ||
lastfm | ||
.getTopTags() | ||
.then(response => response.json()) | ||
.then(results => { | ||
dispatch(loadTopTagsAction.success(results.toptags.tag)); | ||
}) | ||
.catch(error => { | ||
dispatch(loadTopTagsAction.failure()); | ||
logger.error(error); | ||
}); | ||
}; | ||
} | ||
|
||
export const loadBestNewAlbumsAction = createAsyncAction( | ||
Dashboard.LOAD_BEST_NEW_ALBUMS_START, | ||
Dashboard.LOAD_BEST_NEW_ALBUMS_SUCCESS, | ||
Dashboard.LOAD_BEST_NEW_ALBUMS_ERROR | ||
)<undefined, unknown, undefined>(); | ||
|
||
export function loadBestNewAlbums() { | ||
return dispatch => { | ||
dispatch(loadBestNewAlbumsAction.request()); | ||
getBestNewAlbums() | ||
.then(albums => { | ||
dispatch(loadBestNewAlbumsAction.success(albums)); | ||
}) | ||
.catch(error => { | ||
dispatch(loadBestNewAlbumsAction.failure()); | ||
logger.error(error); | ||
}); | ||
}; | ||
} | ||
|
||
export const loadBestNewTracksAction = createAsyncAction( | ||
Dashboard.LOAD_BEST_NEW_TRACKS_START, | ||
Dashboard.LOAD_BEST_NEW_TRACKS_SUCCESS, | ||
Dashboard.LOAD_BEST_NEW_TRACKS_ERROR | ||
)<undefined, unknown, undefined>(); | ||
|
||
export function loadBestNewTracks() { | ||
return dispatch => { | ||
dispatch(loadBestNewTracksAction.request()); | ||
getBestNewTracks() | ||
.then(tracks => { | ||
dispatch(loadBestNewTracksAction.success(tracks)); | ||
}) | ||
.catch(error => { | ||
dispatch(loadBestNewTracksAction.failure()); | ||
logger.error(error); | ||
}); | ||
}; | ||
} | ||
|
||
export const loadTopTracksAction = createAsyncAction( | ||
Dashboard.LOAD_TOP_TRACKS_START, | ||
Dashboard.LOAD_TOP_TRACKS_SUCCESS, | ||
Dashboard.LOAD_TOP_TRACKS_ERROR | ||
)<undefined, unknown, undefined>(); | ||
|
||
export const loadTopTracks = () => async (dispatch) => { | ||
dispatch(loadTopTracksAction.request()); | ||
|
||
try { | ||
const tracks = await Deezer.getTopTracks(); | ||
dispatch(loadTopTracksAction.success(tracks.data.map(Deezer.mapDeezerTrackToInternal))); | ||
} catch (error) { | ||
dispatch(loadTopTracksAction.failure()); | ||
logger.error(error); | ||
} | ||
}; |
5 changes: 3 additions & 2 deletions
5
packages/app/app/reducers/connectivity.js → packages/app/app/reducers/connectivity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters