Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radioking integration #3

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3838ca2
stream + artworks working
hugomassing Dec 23, 2017
9d9fd93
refactor css
hugomassing Dec 24, 2017
019b339
history + css working
hugomassing Dec 26, 2017
58e7f04
increase history
hugomassing Dec 26, 2017
ed55881
add responsive on controls
hugomassing Dec 26, 2017
823c2fe
remove album
hugomassing Dec 26, 2017
452ccc1
change info size
hugomassing Dec 26, 2017
1f773db
change logo position
hugomassing Dec 26, 2017
714a0b3
add hover on tracks
hugomassing Dec 26, 2017
002ab63
loading on end track kinda working
hugomassing Dec 27, 2017
bfd6f12
change animation css
hugomassing Dec 29, 2017
2ffe05a
updated stream link
hugomassing Mar 18, 2018
585ff69
refactor fetching track
hugomassing Mar 18, 2018
2be939f
added https for the stream
hugomassing Mar 18, 2018
047c398
Add missing quick-hash in deps
Kerumen Apr 8, 2018
ecf7496
Fix track shrink
Kerumen Apr 8, 2018
0138d62
Clean code
Kerumen Apr 8, 2018
89d4103
Upgrade deps
Kerumen Apr 8, 2018
eed62be
Add prettier
Kerumen Apr 8, 2018
847f0fe
Add lint-staged to run prettier on commits
Kerumen Apr 8, 2018
4c0d78c
Some more code cleaning
Kerumen Apr 8, 2018
cd95170
fix(Audio): player now stop and take back to direct
hugomassing Apr 8, 2018
3078c71
fix css and stream issues
hugomassing Jul 1, 2018
fa6bc6f
add control colume and mute
hugomassing Jul 2, 2018
96afff6
remove unused variables
hugomassing Jul 2, 2018
80091e0
fix autoplay
hugomassing Jul 3, 2018
b099832
fix responsive
hugomassing Jul 3, 2018
feaadd0
fix player volume
hugomassing Jul 4, 2018
6ee9cea
fix view on mobile
hugomassing Jul 9, 2018
9404e5f
fix title
hugomassing Sep 25, 2018
4378800
Update index.js
hugomassing Sep 27, 2018
ab41d2c
refresh
hugomassing May 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
49 changes: 49 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"gh-pages": "^0.12.0",
"react-scripts": "0.8.4"
"gh-pages": "^1.1.0",
"husky": "^0.14.3",
"lint-staged": "^7.0.4",
"prettier": "^1.11.1",
"react-scripts": "1.1.4"
},
"dependencies": {
"classnames": "^2.2.5",
"lodash": "^4.17.2",
"react": "^15.4.1",
"react-addons-css-transition-group": "^15.4.1",
"react-dom": "^15.4.1",
"react-flip-move": "^2.7.4",
"react-imageloader": "^2.1.0",
"moment": "^2.20.1",
"quick-hash": "^1.0.4",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-howler": "^3.7.3",
"react-redux": "^5.0.1",
"react-sound": "^1.2.0",
"redux": "^3.6.0",
"redux-logger": "^2.7.4",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.1.0",
"velocity-animate": "^1.3.1",
"whatwg-fetch": "^2.0.1"
Expand All @@ -26,6 +30,14 @@
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"deploy": "npm run build&&gh-pages -d build"
"deploy": "npm run build && gh-pages -d build",
"prettier": "prettier --write 'src/**/*.{js,css}'",
"precommit": "lint-staged"
},
"lint-staged": {
"**/*.{js,css}": [
"prettier --write",
"git add"
]
}
}
49 changes: 11 additions & 38 deletions src/actions/playerActions.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
export const loadTrack = (index, list) =>
dispatch =>
dispatch({
type: 'LOAD_TRACK',
payload: list[index],
})

export const nextTrack = (index, list) =>
dispatch => {
const nextIndex = (index + 1) % list.length
dispatch({
type: 'NEXT_INDEX',
payload: nextIndex,
})
}

export const previousTrack = (index, list) =>
dispatch => {
const previousIndex = index ? (index - 1) : (list.length - 1)
dispatch({
type: 'NEXT_INDEX',
payload: previousIndex,
})
}

export const togglePlaying = playing =>
dispatch =>
dispatch({
type: 'UPDATE_PLAYING',
payload: !playing,
})

export const updateVolume = newVolume =>
dispatch =>
dispatch({
type: 'UPDATE_VOLUME',
payload: newVolume,
})
export const togglePlaying = playing => dispatch =>
dispatch({
type: 'UPDATE_PLAYING',
payload: !playing,
})

export const updateVolume = newVolume => dispatch =>
dispatch({
type: 'UPDATE_VOLUME',
payload: newVolume,
})
75 changes: 52 additions & 23 deletions src/actions/tracksActions.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,67 @@
import _ from 'lodash'
import 'whatwg-fetch'

const SC_CLIENT_ID = 'b8198f1a65c0235a26607a834bcc3062'
const SC_PLAYLIST_ID = '219590548'
const SC_PLAYLIST_SECRET_TOKEN = 's-suaqL'
import hash from 'quick-hash'

const requestTracks = payload => ({
type: 'REQUEST_TRACKS',
payload,
})

const requestHistory = payload => ({
type: 'REQUEST_HISTORY',
payload,
})

const receiveErrorTracks = payload => ({
type: 'TRACKS_ERROR',
payload,
})

const receiveTracks = payload => ({
type: 'RECEIVE_TRACKS',
const receiveCurrentTrack = payload => ({
type: 'RECEIVE_CURRENT_TRACK',
payload,
})

export const fetchTracks = () =>
dispatch => {
dispatch(requestTracks('requesting'))
return fetch(`https://api.soundcloud.com/playlists/${SC_PLAYLIST_ID}.json?client_id=${SC_CLIENT_ID}&secret_token=${SC_PLAYLIST_SECRET_TOKEN}`)
.then(response => response.json())
.then(({ tracks }) => {
const newTracks = tracks.map(track =>
track.artwork_url ?
_.extend({}, track, { stream_url: `${track.stream_url.split('?secret_token')[0]}?client_id=${SC_CLIENT_ID}` })
:
null
)
dispatch(receiveTracks(_.chain(newTracks).compact().shuffle().value()))
})
.catch(error => dispatch(receiveErrorTracks(error)))
}
const receiveHistory = payload => ({
type: 'RECEIVE_HISTORY',
payload,
})

const addIdToTracks = tracks => {
return tracks.map(track => ({
id: hash(track.started_at),
...track,
}))
}

export const fetchCurrentTrack = () => dispatch => {
dispatch(requestTracks('requestingCurrentTrack'))
return fetch(
`https://www.radioking.com/widgets/currenttrack.php?radio=117904&format=json`
)
.then(response => response.json())
.then(newTrack => {
dispatch(receiveCurrentTrack(...addIdToTracks([newTrack])))
})
.catch(error => {
console.log(error)
dispatch(receiveErrorTracks(error))
})
}

export const fetchHistory = () => dispatch => {
dispatch(requestHistory('requestingHistory'))
return fetch(
`https://www.radioking.com/widgets/api/v1/radio/117904/track/history?limit=20`
)
.then(response => response.json())
.then(history => {
history = addIdToTracks(history)
dispatch(
receiveHistory(history.filter(track => track.album !== 'qatataq'))
)
})
.catch(error => {
console.log(error)
dispatch(receiveErrorTracks(error))
})
}
25 changes: 12 additions & 13 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'

import Content from './Content'
import Header from './Header'
import States from './States'
import Footer from './Footer'
import { fetchTracks } from '../actions/tracksActions'
import { fetchHistory, fetchCurrentTrack } from '../actions/tracksActions'
import '../styles/App.css'

class App extends Component {
/**
* When the component will mount, fetch the tracks of the playlist
*/
componentWillMount() {
this.props.fetchTracks()
componentDidMount() {
this.props.fetchHistory()
this.props.fetchCurrentTrack()
}

render() {
return (
<div className="app">
<States />
<Header />
<Content />
<Footer />
</div>
)
}
}

const stateToProps = () => ({})
const mapStateToProps = null

const dispatchToProps = (dispatch) => ({
fetchTracks: () => dispatch(fetchTracks()),
})
const mapDispatchToProps = {
fetchHistory,
fetchCurrentTrack,
}

export default connect(stateToProps, dispatchToProps)(App)
export default connect(mapStateToProps, mapDispatchToProps)(App)
Loading