├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── Soundize-screen-one.PNG ├── Soundize-screen-two.PNG ├── index.html ├── package.json ├── server.js ├── src ├── actions │ ├── album_actions.js │ ├── alert_actions.js │ ├── artist_actions.js │ ├── category_actions.js │ ├── player_actions.js │ ├── playlist_actions.js │ ├── search_actions.js │ ├── spotifyApi_actions.js │ ├── track_actions.js │ └── user_actions.js ├── components │ ├── AlbumDetail.js │ ├── App.js │ ├── ArtistDetail.js │ ├── AudioPlayer.js │ ├── Callback.js │ ├── Discover.js │ ├── DiscoverCategory.js │ ├── ExtraInfolist.js │ ├── Home.js │ ├── Login.js │ ├── MusicBar.js │ ├── MusicBarActions.js │ ├── Nav.js │ ├── NewReleases.js │ ├── PieChart.js │ ├── PlaylistDetail.js │ ├── Playlists.js │ ├── Search.js │ ├── Toplists.js │ ├── Track.js │ ├── TrackDetail.js │ ├── TrackMenu.js │ ├── Tracklist.js │ ├── TracklistBanner.js │ ├── TracklistBannerScroll.js │ ├── general │ │ ├── Loading.js │ │ └── RequireAuth.js │ └── modals │ │ ├── AddTrackToPlaylistModal.js │ │ ├── CreateNewPlaylistModal.js │ │ ├── DeletePlaylistModal.js │ │ └── UnfollowPlaylistModal.js ├── helpers │ ├── renderer.js │ └── serverStore.js ├── images │ ├── Soundize-logo2.PNG │ └── devices.png ├── index.js ├── reducers │ ├── album_reducer.js │ ├── artist_reducer.js │ ├── category_reducer.js │ ├── index.js │ ├── player_reducer.js │ ├── playlist_reducer.js │ ├── search_reducer.js │ ├── track_reducer.js │ └── user_reducer.js ├── routes.js ├── store │ └── index.js └── stylesheets │ ├── base.scss │ ├── components │ ├── albumDetail.scss │ ├── alert.scss │ ├── artistDetail.scss │ ├── discover.scss │ ├── discoverCategory.scss │ ├── extraInfolist.scss │ ├── login.scss │ ├── musicbar.scss │ ├── musicbarActions.scss │ ├── nav.scss │ ├── newReleases.scss │ ├── playlists.scss │ ├── search.scss │ ├── toplists.scss │ ├── track.scss │ ├── trackDetail.scss │ ├── trackMenu.scss │ ├── tracklist.scss │ ├── tracklistBanner.scss │ └── tracklistBannerScroll.scss │ ├── main.scss │ ├── modals.scss │ └── variables.scss ├── webpack.common.js ├── webpack.dev.config.js ├── webpack.devserver.config.js ├── webpack.prod.config.js └── webpack.prodserver.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env", "react", "stage-3", "stage-2"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/** 2 | .DS_STORE 3 | ./idea 4 | /public/* 5 | /build/* 6 | /dist/* 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alex Lööf 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Soundize 2 | 3 | A homemade server side rendering client built with React and Redux, powered by 4 | the Spotify API 5 | 6 | Live at: https://soundize.herokuapp.com 7 | 8 | The app: 9 | ![alt text](https://github.com/Alexloof/Soundize/blob/master/Soundize-screen-one.PNG "My Music") 10 | 11 | ![alt text](https://github.com/Alexloof/Soundize/blob/master/Soundize-screen-two.PNG "Track Detail") 12 | 13 | Run the app locally: 14 | 15 | ``` 16 | npm install 17 | npm run dev 18 | Visit http://localhost:8080 19 | ``` 20 | -------------------------------------------------------------------------------- /Soundize-screen-one.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexloof/Soundize/bee397de65c439f884fd40dab587508520d9c2ed/Soundize-screen-one.PNG -------------------------------------------------------------------------------- /Soundize-screen-two.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexloof/Soundize/bee397de65c439f884fd40dab587508520d9c2ed/Soundize-screen-two.PNG -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Soundize 9 | 10 | 11 | 12 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "soundize", 3 | "version": "0.1.0", 4 | "private": false, 5 | "description": "A client-side webapp powered by Spotify API", 6 | "author": "Alex Lööf", 7 | "license": "ISC", 8 | "main": "dist/server.js", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/Alexloof/Soundize.git" 12 | }, 13 | "scripts": { 14 | "start": "node ./dist/server.js", 15 | "dev": "npm-run-all --parallel dev:*", 16 | "prod": "npm-run-all --parallel prod:*", 17 | "dev:build-server": "webpack --config webpack.devserver.config.js --watch", 18 | "dev:build-client": "webpack --config webpack.dev.config.js --watch", 19 | "dev:server": "nodemon --exec node dist/server.js --watch", 20 | "prod:build-server": "webpack --config webpack.prodserver.config.js", 21 | "prod:build-client": "webpack --config webpack.prod.config.js", 22 | "alex": 23 | "webpack-dev-server --config webpack.dev.config.js --progress --colors --hot --history-api-fallback" 24 | }, 25 | "dependencies": { 26 | "autoprefixer": "^6.4.1", 27 | "axios": "^0.16.2", 28 | "babel-polyfill": "^6.26.0", 29 | "body-parser": "^1.16.0", 30 | "express": "^4.15.4", 31 | "express-session": "^1.15.0", 32 | "prop-types": "^15.5.10", 33 | "querystring": "^0.2.0", 34 | "react": "^16.0.0", 35 | "react-dom": "^16.0.0", 36 | "react-flip-move": "^2.9.15", 37 | "react-redux": "^5.0.6", 38 | "react-router": "^4.2.0", 39 | "react-router-config": "^1.0.0-beta.4", 40 | "react-router-dom": "^4.2.2", 41 | "react-s-alert": "^1.3.2", 42 | "redux": "^3.7.2", 43 | "redux-persist": "^5.3.4", 44 | "redux-thunk": "^2.2.0", 45 | "screenfull": "^3.3.1", 46 | "serialize-javascript": "^1.4.0" 47 | }, 48 | "devDependencies": { 49 | "babel-core": "^6.23.1", 50 | "babel-loader": "^6.3.2", 51 | "babel-preset-env": "^1.6.0", 52 | "babel-preset-latest": "^6.24.1", 53 | "babel-preset-react": "^6.24.1", 54 | "babel-preset-stage-2": "^6.24.1", 55 | "babel-preset-stage-3": "^6.24.1", 56 | "css-loader": "^0.26.1", 57 | "file-loader": "^0.11.2", 58 | "image-webpack-loader": "^3.4.2", 59 | "json-loader": "^0.5.7", 60 | "node-sass": "^4.5.3", 61 | "nodemon": "^1.12.1", 62 | "npm-run-all": "^4.1.2", 63 | "sass-loader": "^6.0.6", 64 | "style-loader": "^0.13.1", 65 | "uglifyjs-webpack-plugin": "^1.1.2", 66 | "url-loader": "^0.6.2", 67 | "webpack": "^2.7.0", 68 | "webpack-dev-middleware": "^1.12.0", 69 | "webpack-dev-server": "^2.4.1", 70 | "webpack-merge": "^4.1.1", 71 | "webpack-node-externals": "^1.6.0" 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | 3 | import { matchRoutes } from 'react-router-config' 4 | import Routes from './src/routes' 5 | import renderer from './src/helpers/renderer' 6 | import createStore from './src/helpers/serverStore' 7 | 8 | const app = express() 9 | 10 | app.use(express.static('dist')) 11 | 12 | app.get('*', (req, res) => { 13 | const store = createStore(req) 14 | 15 | const promises = matchRoutes(Routes, req.path) 16 | .map(({ route }) => { 17 | return route.loadData ? route.loadData(store) : null 18 | }) 19 | .map(promise => { 20 | if (promise) { 21 | return new Promise((resolve, reject) => { 22 | promise.then(resolve).catch(resolve) 23 | }) 24 | } 25 | }) 26 | 27 | Promise.all(promises).then(() => { 28 | const context = {} 29 | const content = renderer(req, store, context) 30 | if (context.url) { 31 | return res.redirect(301, context.url) 32 | } 33 | if (context.notFound) { 34 | res.status(404) 35 | } 36 | return res.send(content) 37 | }) 38 | }) 39 | 40 | var port = process.env.PORT || 8080 41 | 42 | app.listen(port, () => { 43 | console.log('Listning on port 8080') 44 | }) 45 | -------------------------------------------------------------------------------- /src/actions/album_actions.js: -------------------------------------------------------------------------------- 1 | import { fetchAlbum } from './spotifyApi_actions' 2 | 3 | export const SET_ALBUM = 'set_album' 4 | 5 | export const getAlbum = id => async dispatch => { 6 | let album = await fetchAlbum(id) 7 | 8 | if (album) { 9 | dispatch({ type: SET_ALBUM, payload: album }) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/actions/alert_actions.js: -------------------------------------------------------------------------------- 1 | import Alert from 'react-s-alert' 2 | 3 | export const showSuccessAlert = text => dispatch => { 4 | Alert.success(text, { 5 | position: 'top-right', 6 | effect: 'slide', 7 | beep: false, 8 | timeout: 4000, 9 | offset: 30 10 | }) 11 | } 12 | 13 | export const showErrorAlert = text => dispatch => { 14 | Alert.error(text, { 15 | position: 'top-right', 16 | effect: 'slide', 17 | beep: false, 18 | timeout: 4000, 19 | offset: 30 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /src/actions/artist_actions.js: -------------------------------------------------------------------------------- 1 | import { 2 | fetchArtist, 3 | fetchArtistAlbums, 4 | fetchArtistTopTracks, 5 | fetchRelatedArtists 6 | } from './spotifyApi_actions' 7 | 8 | export const SET_ARTIST = 'set_artist' 9 | export const SET_ARTIST_ALBUMS = 'set_artist_albums' 10 | export const SET_ARTIST_TOP_TRACKS = 'set_artist_top_tracks' 11 | export const SET_ARTIST_RELATED_ARTISTS = 'set_artist_related_artists' 12 | 13 | export const getArtistDetail = id => async dispatch => { 14 | let artist = await fetchArtist(id) 15 | let artistAlbums = await fetchArtistAlbums(id) 16 | let artistTopTracks = await fetchArtistTopTracks(id) 17 | let relatedArtists = await fetchRelatedArtists(id) 18 | 19 | if (artist) { 20 | dispatch({ type: SET_ARTIST, payload: artist }) 21 | } 22 | if (artistAlbums) { 23 | dispatch({ type: SET_ARTIST_ALBUMS, payload: artistAlbums }) 24 | } 25 | if (artistTopTracks) { 26 | dispatch({ type: SET_ARTIST_TOP_TRACKS, payload: artistTopTracks }) 27 | } 28 | if (relatedArtists) { 29 | dispatch({ type: SET_ARTIST_RELATED_ARTISTS, payload: relatedArtists }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/actions/category_actions.js: -------------------------------------------------------------------------------- 1 | import { 2 | getCategoriesCall, 3 | getActiveCategoryPlaylistsCall 4 | } from './spotifyApi_actions' 5 | 6 | // Actions 7 | export const SET_CATEGORIES = 'set_categories' 8 | export const SET_ACTIVE_CATEGORY_PLAYLISTS = 'set_active_category_playlists' 9 | 10 | export const getCategories = () => async dispatch => { 11 | let categories = await getCategoriesCall() 12 | 13 | if (categories) { 14 | dispatch({ type: SET_CATEGORIES, payload: categories }) 15 | } 16 | } 17 | 18 | export const getActiveCategoryPlaylists = category => async dispatch => { 19 | let playlists = await getActiveCategoryPlaylistsCall(category) 20 | 21 | if (playlists) { 22 | dispatch({ type: SET_ACTIVE_CATEGORY_PLAYLISTS, payload: playlists }) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/actions/player_actions.js: -------------------------------------------------------------------------------- 1 | import { 2 | removeTrackFromQueuedTracks, 3 | setActiveTrack, 4 | setActiveTrackindex 5 | } from './track_actions' 6 | 7 | // actions 8 | export const PLAY_ACTIVE_TRACK = 'play_active_track' 9 | export const PAUSE_ACTIVE_TRACK = 'pause_active_track' 10 | export const TOGGLE_ACTIVE_TRACK = 'toogle_active_track' 11 | export const SHOW_MUSICBAR = 'show_musicbar' 12 | export const SET_PLAYED_TIME = 'set_played_time' 13 | export const START_SEEK = 'start_seek' 14 | export const STOP_SEEK = 'stop_seek' 15 | export const CHANGE_SEEK = 'change_seek' 16 | export const ZERO_PLAYED_TIME = 'zero_played_time' 17 | export const TOGGLE_SHUFFLE = 'toggle_suffle' 18 | 19 | export const playActiveTrack = () => async dispatch => { 20 | dispatch({ type: PLAY_ACTIVE_TRACK }) 21 | } 22 | 23 | export const pauseActiveTrack = () => async dispatch => { 24 | dispatch({ type: PAUSE_ACTIVE_TRACK }) 25 | } 26 | 27 | export const toggleStartPauseTrack = () => async dispatch => { 28 | dispatch({ type: TOGGLE_ACTIVE_TRACK }) 29 | } 30 | 31 | export const showMusicbar = () => async dispatch => { 32 | dispatch({ type: SHOW_MUSICBAR }) 33 | } 34 | 35 | export const setPlayedTime = playedTime => async dispatch => { 36 | dispatch({ type: SET_PLAYED_TIME, payload: playedTime }) 37 | } 38 | 39 | export const startSeek = () => async dispatch => { 40 | dispatch({ type: START_SEEK }) 41 | } 42 | 43 | export const stopSeek = () => async dispatch => { 44 | dispatch({ type: STOP_SEEK }) 45 | } 46 | 47 | export const changeSeek = event => async dispatch => { 48 | dispatch({ type: CHANGE_SEEK, payload: event }) 49 | } 50 | 51 | export const zeroPlayedTime = () => async dispatch => { 52 | dispatch({ type: ZERO_PLAYED_TIME }) 53 | } 54 | 55 | export const toggleShuffle = () => async dispatch => { 56 | dispatch({ type: TOGGLE_SHUFFLE }) 57 | } 58 | 59 | export const playNextTrack = () => async (dispatch, getState) => { 60 | const queuedTracklist = getState().track.queuedTracks 61 | const activeTrackIndex = getState().track.activeTrackIndex 62 | const playingTracklist = getState().track.playingTracklist 63 | const isShuffling = getState().player.isShuffling 64 | let nextTrack 65 | if (queuedTracklist.length > 0) { 66 | nextTrack = queuedTracklist[0] 67 | dispatch(removeTrackFromQueuedTracks(0)) 68 | await dispatch(setActiveTrack(nextTrack)) 69 | dispatch(playActiveTrack()) 70 | } else { 71 | if (isShuffling) { 72 | const randomIndex = Math.floor( 73 | Math.random() * (playingTracklist.tracks.items.length - 1) 74 | ) 75 | nextTrack = playingTracklist.tracks.items[randomIndex].track 76 | let nextTrackIndex 77 | playingTracklist.tracks.items.map((item, index) => { 78 | if (item.track.id === nextTrack.id) { 79 | nextTrackIndex = index 80 | } 81 | }) 82 | if (!nextTrack.preview_url) { 83 | setTimeout(() => { 84 | dispatch(playNextTrack()) 85 | }, 100) 86 | } else { 87 | await dispatch(setActiveTrack(nextTrack, nextTrackIndex)) 88 | dispatch(playActiveTrack()) 89 | } 90 | } else { 91 | if (activeTrackIndex !== playingTracklist.tracks.items.length - 1) { 92 | nextTrack = playingTracklist.tracks.items[activeTrackIndex + 1].track 93 | if (!nextTrack.preview_url) { 94 | await dispatch(setActiveTrackindex(activeTrackIndex + 1)) 95 | setTimeout(() => { 96 | dispatch(playNextTrack()) 97 | }, 100) 98 | } else { 99 | await dispatch(setActiveTrack(nextTrack, activeTrackIndex + 1)) 100 | dispatch(playActiveTrack()) 101 | } 102 | } 103 | } 104 | } 105 | } 106 | 107 | export const playPrevTrack = () => async (dispatch, getState) => { 108 | const latestPlayedTracks = getState().track.latestPlayedTracks 109 | let nextTrackPlay 110 | if (latestPlayedTracks.length > 1) { 111 | nextTrackPlay = latestPlayedTracks[latestPlayedTracks.length - 2] 112 | await dispatch(setActiveTrack(nextTrackPlay)) 113 | dispatch(playActiveTrack()) 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/actions/playlist_actions.js: -------------------------------------------------------------------------------- 1 | import { 2 | fetchPlaylists, 3 | fetchFeaturedPlaylists, 4 | createUserPlaylist, 5 | unfollowPlaylistCall, 6 | followPlaylistCall, 7 | deleteUserPlaylist, 8 | fetchNewReleases 9 | } from './spotifyApi_actions' 10 | 11 | // actions 12 | export const SET_PLAYLISTS = 'set_playlists' 13 | export const SET_PRIVATE_PLAYLISTS = 'set_private_playlists' 14 | export const SET_FEATURED_PLAYLISTS = 'set_featured_playlists' 15 | export const SET_ACTIVE_PLAYLIST = 'set_active_playlist' 16 | export const SET_NEW_RELEASES = 'set_new_releases' 17 | 18 | export const getPlaylists = userId => async dispatch => { 19 | let playlists = await fetchPlaylists(userId, dispatch) 20 | 21 | if (playlists) { 22 | dispatch({ type: SET_PLAYLISTS, payload: playlists }) 23 | } 24 | } 25 | 26 | export const getPrivatePlaylists = ( 27 | playlists = [], 28 | userId 29 | ) => async dispatch => { 30 | let privatePlaylists = [] 31 | playlists.map(playlist => { 32 | if (playlist.collaborative === true || playlist.owner.id === userId) { 33 | privatePlaylists.push(playlist) 34 | } 35 | }) 36 | dispatch({ type: SET_PRIVATE_PLAYLISTS, payload: privatePlaylists }) 37 | } 38 | 39 | export const getFeaturedPlaylists = () => async dispatch => { 40 | let timestamp = new Date().toISOString() 41 | let featuredPlaylists = await fetchFeaturedPlaylists(timestamp, dispatch) 42 | 43 | if (featuredPlaylists) { 44 | dispatch({ type: SET_FEATURED_PLAYLISTS, payload: featuredPlaylists }) 45 | } 46 | } 47 | 48 | export const getNewReleases = () => async dispatch => { 49 | let newReleases = await fetchNewReleases() 50 | 51 | if (newReleases) { 52 | dispatch({ type: SET_NEW_RELEASES, payload: newReleases }) 53 | } 54 | } 55 | 56 | export const createPlaylist = (userId, name, desc) => async dispatch => { 57 | await createUserPlaylist(userId, name, desc, dispatch) 58 | } 59 | 60 | export const unfollowPlaylist = (ownerId, playlistId) => async dispatch => { 61 | await unfollowPlaylistCall(ownerId, playlistId, dispatch) 62 | } 63 | 64 | export const followPlaylist = (ownerId, playlistId) => async dispatch => { 65 | await followPlaylistCall(ownerId, playlistId, dispatch) 66 | } 67 | 68 | export const deletePlaylist = (userId, playlistId) => async dispatch => { 69 | await deleteUserPlaylist(userId, playlistId, dispatch) 70 | } 71 | 72 | export const setActivePlaylist = playlistId => async dispatch => { 73 | dispatch({ type: SET_ACTIVE_PLAYLIST, payload: playlistId }) 74 | } 75 | -------------------------------------------------------------------------------- /src/actions/search_actions.js: -------------------------------------------------------------------------------- 1 | import { 2 | getSearchedArtistsCall, 3 | getSearchedTracksCall, 4 | getSearchedPlaylistsCall 5 | } from './spotifyApi_actions' 6 | 7 | // Actions 8 | export const SET_SEARCHED_ARTISTS = 'set_searched_artists' 9 | export const SET_SEARCHED_TRACKS = 'set_searched_tracks' 10 | export const SET_SEARCHED_PLAYLISTS = 'set_searched_playlists' 11 | 12 | export const getSearchedArtists = word => async dispatch => { 13 | let artists = await getSearchedArtistsCall(word) 14 | 15 | if (artists) { 16 | dispatch({ type: SET_SEARCHED_ARTISTS, payload: artists }) 17 | } 18 | } 19 | 20 | export const getSearchedTracks = word => async dispatch => { 21 | let tracks = await getSearchedTracksCall(word) 22 | 23 | if (tracks) { 24 | dispatch({ type: SET_SEARCHED_TRACKS, payload: tracks }) 25 | } 26 | } 27 | 28 | export const getSearchedPlaylists = word => async dispatch => { 29 | let playlists = await getSearchedPlaylistsCall(word) 30 | 31 | if (playlists) { 32 | dispatch({ type: SET_SEARCHED_PLAYLISTS, payload: playlists }) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/actions/track_actions.js: -------------------------------------------------------------------------------- 1 | import { 2 | getTracklistOfPlaylist, 3 | addTrackToPlaylistCall, 4 | removeTrackFromPlaylistCall, 5 | fetchTrackDetails, 6 | fetchTrack 7 | } from './spotifyApi_actions' 8 | 9 | import { showSuccessAlert } from './alert_actions' 10 | 11 | import { ZERO_PLAYED_TIME } from './player_actions' 12 | 13 | // actions 14 | export const SET_ACTIVE_TRACKLIST = 'set_active_tracklist' 15 | export const SET_PLAYING_TRACKLIST = 'set_playing_tracklist' 16 | export const ADD_TRACK_TO_QUEUED_LIST = 'add_track_to_queued_list' 17 | export const REMOVE_TRACK_FROM_QUEUED_LIST = 'remove_track_from_queued_list' 18 | export const ADD_TRACK_TO_LATEST_PLAYED = 'add_track_to_latest_played' 19 | export const SET_ACTIVE_TRACK = 'set_active_track' 20 | export const SET_ACTIVE_TRACKINDEX = 'set_active_trackindex' 21 | export const SET_TRACK_DETAIL = 'set_track_detail' 22 | 23 | export const setActiveTracklist = (ownerId, playlistId) => async dispatch => { 24 | let tracklist = await getTracklistOfPlaylist(ownerId, playlistId, dispatch) 25 | 26 | if (tracklist) { 27 | dispatch(setActiveTracklistSolo(tracklist)) 28 | } 29 | } 30 | 31 | export const setActiveTracklistSolo = tracklist => async dispatch => { 32 | dispatch({ type: SET_ACTIVE_TRACKLIST, payload: tracklist }) 33 | } 34 | 35 | export const getTrackDetail = id => async dispatch => { 36 | let track = await fetchTrack(id) 37 | let trackdetails = await fetchTrackDetails(id) 38 | let fullTrack = { ...trackdetails, ...track } 39 | 40 | if (trackdetails && track) { 41 | dispatch({ type: SET_TRACK_DETAIL, payload: fullTrack }) 42 | } 43 | } 44 | 45 | export const setPlayingTracklist = tracklist => async dispatch => { 46 | dispatch({ type: SET_PLAYING_TRACKLIST, payload: tracklist }) 47 | } 48 | 49 | export const addTrackToQueuedList = track => async dispatch => { 50 | dispatch({ type: ADD_TRACK_TO_QUEUED_LIST, payload: track }) 51 | dispatch(showSuccessAlert('Track was queued')) 52 | } 53 | 54 | export const removeTrackFromQueuedTracks = indexToRemove => async dispatch => { 55 | dispatch({ type: REMOVE_TRACK_FROM_QUEUED_LIST, payload: indexToRemove }) 56 | } 57 | 58 | export const addTrackToLatestPlayed = track => async dispatch => { 59 | dispatch({ type: ADD_TRACK_TO_LATEST_PLAYED, payload: track }) 60 | } 61 | 62 | export const addTrackToPlaylist = ( 63 | ownerId, 64 | playlistId, 65 | spotifyURI 66 | ) => async dispatch => { 67 | await addTrackToPlaylistCall(ownerId, playlistId, spotifyURI, dispatch) 68 | } 69 | 70 | export const removeTrackFromPlaylist = ( 71 | ownerId, 72 | playlistId, 73 | spotifyURI 74 | ) => async dispatch => { 75 | const tracks = [{ uri: spotifyURI }] 76 | await removeTrackFromPlaylistCall(ownerId, playlistId, spotifyURI, dispatch) 77 | } 78 | 79 | export const setActiveTrack = (track, trackIndex) => async dispatch => { 80 | dispatch({ type: SET_ACTIVE_TRACK, payload: track }) 81 | dispatch({ type: SET_ACTIVE_TRACKINDEX, payload: trackIndex }) 82 | dispatch({ type: ZERO_PLAYED_TIME }) 83 | dispatch(addTrackToLatestPlayed(track)) 84 | } 85 | 86 | export const setActiveTrackindex = trackIndex => async dispatch => { 87 | dispatch({ type: SET_ACTIVE_TRACKINDEX, payload: trackIndex }) 88 | } 89 | -------------------------------------------------------------------------------- /src/actions/user_actions.js: -------------------------------------------------------------------------------- 1 | import { fetchUser, setAccessToken } from './spotifyApi_actions' 2 | 3 | export const SET_USER = 'set_user' 4 | export const FAIL_USER = 'fail_user' 5 | 6 | export const setupAuthToAPI = token => async dispatch => { 7 | setAccessToken(token, dispatch) 8 | } 9 | 10 | export const getCurrentUser = () => async dispatch => { 11 | let user = await fetchUser(dispatch) 12 | 13 | if (user) { 14 | dispatch({ type: SET_USER, payload: user }) 15 | } else { 16 | dispatch({ type: FAIL_USER }) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/components/AlbumDetail.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { withRouter } from 'react-router-dom' 3 | import { connect } from 'react-redux' 4 | 5 | import Track from './Track' 6 | 7 | import { setActiveTracklistSolo } from '../actions/track_actions' 8 | import { setupAuthToAPI } from '../actions/user_actions' 9 | import { getAlbum } from '../actions/album_actions' 10 | 11 | class AlbumDetail extends Component { 12 | async componentDidMount() { 13 | window.scroll(0, 0) 14 | await this.props.getAlbum(this.props.match.params.id) 15 | let tracklist = { 16 | owner: {}, 17 | name: '', 18 | tracks: { 19 | items: [] 20 | } 21 | } 22 | if (this.props.album.tracks) { 23 | this.props.album.tracks.items.map(track => { 24 | const extraAttribut = { 25 | album: { 26 | images: [ 27 | { 28 | url: this.props.album.images[0] 29 | ? this.props.album.images[0].url 30 | : null 31 | } 32 | ] 33 | } 34 | } 35 | const newTrack = { ...track, ...extraAttribut } 36 | tracklist.tracks.items.push({ track: newTrack }) 37 | }) 38 | this.props.setActiveTracklistSolo(tracklist) 39 | } 40 | } 41 | renderTracks = tracks => { 42 | return tracks.map((track, index) => { 43 | const extraAttribut = { 44 | album: { 45 | images: [ 46 | { 47 | url: this.props.album.images[0] 48 | ? this.props.album.images[0].url 49 | : null 50 | } 51 | ] 52 | } 53 | } 54 | const newTrack = { ...track, ...extraAttribut } 55 | return ( 56 | 62 | ) 63 | }) 64 | } 65 | render() { 66 | return ( 67 |
68 |
69 |
70 |
71 |

Album

72 |

{this.props.album.name}

73 |
74 |
75 |
76 |

Release date: {this.props.album.release_date}

77 |
78 |
79 |
80 |
81 | {this.props.album.images ? ( 82 | 0 85 | ? this.props.album.images[0].url 86 | : null 87 | } 88 | /> 89 | ) : null} 90 |
91 |
92 | 97 |
98 | ) 99 | } 100 | } 101 | 102 | const mapStateToProps = ({ album, track, player }) => { 103 | return { 104 | album: album.album, 105 | activeTracklist: track.activeTracklist, 106 | playingTracklistId: track.playingTracklist.id, 107 | isPlaying: player.isPlaying 108 | } 109 | } 110 | 111 | export default withRouter( 112 | connect(mapStateToProps, { 113 | setupAuthToAPI, 114 | getAlbum, 115 | setActiveTracklistSolo 116 | })(AlbumDetail) 117 | ) 118 | -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { Link, Redirect, Route } from 'react-router-dom' 3 | import { connect } from 'react-redux' 4 | import { renderRoutes } from 'react-router-config' 5 | import Alert from 'react-s-alert' 6 | 7 | import RequireAuth from './general/RequireAuth' 8 | import Nav from './Nav' 9 | import MusicBar from './MusicBar' 10 | import Home from './Home' 11 | import Search from './Search' 12 | 13 | class App extends Component { 14 | render() { 15 | return ( 16 |
17 |
22 | ) 23 | } 24 | } 25 | 26 | const mapStateToProps = ({ user }) => { 27 | return { user: user.user } 28 | } 29 | 30 | export default connect(mapStateToProps, null)(RequireAuth(App)) 31 | -------------------------------------------------------------------------------- /src/components/ArtistDetail.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { withRouter } from 'react-router-dom' 3 | import { connect } from 'react-redux' 4 | 5 | import Track from './Track' 6 | 7 | import { getArtistDetail } from '../actions/artist_actions' 8 | import { setupAuthToAPI } from '../actions/user_actions' 9 | import { setActiveTracklistSolo } from '../actions/track_actions' 10 | 11 | class ArtistDetail extends Component { 12 | async componentWillMount() { 13 | window.scroll(0, 0) 14 | this.getArtistDetail(this.props.match.params.id) 15 | this.unlisten = this.props.history.listen((location, action) => { 16 | let incID = location.pathname.slice(13) 17 | let artists = location.pathname.slice(5, 12) 18 | if (incID && artists == 'artists') { 19 | if (incID !== this.props.match.params.id) { 20 | this.getArtistDetail(incID) 21 | } 22 | } 23 | }) 24 | } 25 | getArtistDetail = async id => { 26 | await this.props.getArtistDetail(id) 27 | 28 | let tracklist = { 29 | owner: {}, 30 | name: '', 31 | tracks: { 32 | items: [] 33 | } 34 | } 35 | this.props.artistTopTracks.map(track => { 36 | tracklist.tracks.items.push({ track: track }) 37 | }) 38 | this.props.setActiveTracklistSolo(tracklist) 39 | } 40 | componentWillUnmount() { 41 | this.unlisten() 42 | } 43 | 44 | componentWillReceiveProps(newProps) { 45 | if (newProps.artist.id !== this.props.artist.id) { 46 | this.props.getArtistDetail(this.props.match.params.id) 47 | } 48 | } 49 | navigateToAlbum = id => { 50 | this.props.history.push(`/app/albums/${id}`) 51 | } 52 | navigateToArtist = id => { 53 | this.props.history.push(`/app/artists/${id}`) 54 | } 55 | renderGenres = genres => { 56 | if (genres) { 57 | return genres.map((genre, index) => { 58 | return ( 59 | 60 | {genre} 61 | 62 | ) 63 | }) 64 | } 65 | } 66 | renderTracks = () => { 67 | return this.props.artistTopTracks.map((track, index) => { 68 | if (track !== null) { 69 | return 70 | } 71 | }) 72 | } 73 | renderAlbums = () => { 74 | return this.props.artistAlbums.map((album, index) => { 75 | return ( 76 |
  • this.navigateToAlbum(album.id)} 80 | > 81 | 88 |

    {album.name}

    89 |
  • 90 | ) 91 | }) 92 | } 93 | renderRelated = () => { 94 | return this.props.relatedArtists.map((artist, index) => { 95 | return ( 96 |
  • this.navigateToArtist(artist.id)} 100 | > 101 | 108 |

    {artist.name}

    109 |
  • 110 | ) 111 | }) 112 | } 113 | render() { 114 | return ( 115 |
    116 |
    117 |
    118 | 126 | {this.props.artist.images ? ( 127 |
    128 | ) : null} 129 |

    {this.props.artist.name}

    130 |
    131 |
    132 |

    133 | {this.renderGenres(this.props.artist.genres)} 134 |

    135 |

    136 | Followers: 137 | {this.props.artist.followers 138 | ? this.props.artist.followers.total.toLocaleString() 139 | : null} 140 |

    141 |

    142 | Popularity: {this.props.artist.popularity} 143 |

    144 |
    145 |
    146 |

    Similar artists

    147 |
      148 | {this.props.relatedArtists.length > 0 ? ( 149 | this.renderRelated() 150 | ) : ( 151 |
    • 152 | Artist has no similar artists 153 |
    • 154 | )} 155 |
    156 |
    157 |
    158 |
    159 |

    Album

    160 |
      161 | {this.props.artistAlbums.length > 0 ? ( 162 | this.renderAlbums() 163 | ) : ( 164 |
    • Artist has no album
    • 165 | )} 166 |
    167 |
    168 |
    169 |

    Tracks

    170 |
      171 | {this.props.artistTopTracks.length > 0 ? ( 172 | this.renderTracks() 173 | ) : ( 174 |
    • Artist has no tracks
    • 175 | )} 176 |
    177 |
    178 |
    179 | ) 180 | } 181 | } 182 | 183 | const mapStateToProps = ({ artist }) => { 184 | return { 185 | artist: artist.artist, 186 | artistAlbums: artist.albums, 187 | artistTopTracks: artist.topTracks, 188 | relatedArtists: artist.relatedArtists 189 | } 190 | } 191 | 192 | export default withRouter( 193 | connect(mapStateToProps, { 194 | setupAuthToAPI, 195 | getArtistDetail, 196 | setActiveTracklistSolo 197 | })(ArtistDetail) 198 | ) 199 | -------------------------------------------------------------------------------- /src/components/AudioPlayer.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | 3 | class AudioPlayer extends Component { 4 | state = { 5 | isPlaying: false, 6 | muted: false, 7 | volume: '', 8 | playbackRate: '', 9 | url: '' 10 | } 11 | 12 | componentWillReceiveProps(nextProps) { 13 | if (this.props.url !== nextProps.url) { 14 | this.setState({ url: nextProps.url }, () => { 15 | this.startPlayer() 16 | }) 17 | } 18 | 19 | if (nextProps.isPlaying && !this.state.isPlaying) { 20 | this.startPlayer() 21 | } 22 | if (!nextProps.isPlaying && this.state.isPlaying) { 23 | this.pausePlayer() 24 | } 25 | if (this.state.volume !== nextProps.volume && !nextProps.muted) { 26 | this.audioPlayer.volume = nextProps.volume 27 | } 28 | if (this.state.muted !== nextProps.muted) { 29 | this.audioPlayer.volume = nextProps.muted ? 0 : nextProps.volume 30 | } 31 | if ( 32 | this.state.playbackRate !== nextProps.playbackRate && 33 | this.audioPlayer.setPlaybackRate 34 | ) { 35 | this.audioPlayer.setPlaybackRate(nextProps.playbackRate) 36 | this.setState({ playbackRate: nextProps.playbackRate }) 37 | } 38 | } 39 | timeUpdate = e => { 40 | const duration = this.audioPlayer.duration 41 | if (duration) { 42 | this.props.onProgress(this.audioPlayer.currentTime / duration) 43 | } 44 | } 45 | startPlayer = () => { 46 | this.audioPlayer.play() 47 | this.setState({ isPlaying: true }) 48 | } 49 | pausePlayer = () => { 50 | this.audioPlayer.pause() 51 | this.setState({ isPlaying: false }) 52 | } 53 | stopPlayer = () => { 54 | this.audioPlayer.removeAttribute('src') 55 | return 56 | } 57 | render() { 58 | return ( 59 |