|
@@ -7,10 +7,12 @@ import { translate, Trans } from "react-i18next";
|
|
|
import Player from "./Player";
|
|
|
import Seekerbar from "./Seekerbar";
|
|
|
import VolumeSlider from "./VolumeSlider";
|
|
|
+import Overlays from "./Views/Overlays";
|
|
|
|
|
|
import { changeVolume } from "actions/volume";
|
|
|
-import { changeSong, setTimeElapsed, timePaused } from "actions/songPlayer";
|
|
|
+import { changeSong, setTimeElapsed, timePaused, receivedRatings, receivedOwnRatings } from "actions/songPlayer";
|
|
|
import { pauseStation, resumeStation } from "actions/station";
|
|
|
+import { openOverlay1 } from "actions/stationOverlay";
|
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
@@ -18,10 +20,6 @@ import io from "io";
|
|
|
import config from "config";
|
|
|
import {updateTimePaused} from "../../actions/songPlayer";
|
|
|
|
|
|
-const Aux = (props) => {
|
|
|
- return props.children;
|
|
|
-};
|
|
|
-
|
|
|
const formatTime = (duration) => {
|
|
|
let d = moment.duration(duration, "seconds");
|
|
|
if (duration < 0) return "0:00";
|
|
@@ -34,10 +32,15 @@ const formatTime = (duration) => {
|
|
|
role: state.user.get("role"),
|
|
|
},
|
|
|
loggedIn: state.user.get("loggedIn"),
|
|
|
+ songId: state.songPlayer.get("songId"),
|
|
|
songTitle: state.songPlayer.get("title"),
|
|
|
songDuration: state.songPlayer.get("duration"),
|
|
|
songTimeElapsed: state.songPlayer.get("timeElapsed"),
|
|
|
songArtists: state.songPlayer.get("artists"),
|
|
|
+ songLikes: state.songPlayer.get("likes"),
|
|
|
+ songLiked: state.songPlayer.get("liked"),
|
|
|
+ songDislikes: state.songPlayer.get("dislikes"),
|
|
|
+ songDisliked: state.songPlayer.get("disliked"),
|
|
|
simpleSong: state.songPlayer.get("simple"),
|
|
|
songExists: state.songPlayer.get("exists"),
|
|
|
station: {
|
|
@@ -64,21 +67,23 @@ export default class Station extends Component {
|
|
|
|
|
|
io.getSocket(socket => {
|
|
|
socket.emit("stations.join", props.station.name, res => {
|
|
|
- console.log(res);
|
|
|
if (res.status === 'success') {
|
|
|
if (res.data.currentSong) {
|
|
|
res.data.currentSong.startedAt = res.data.startedAt;
|
|
|
res.data.currentSong.timePaused = res.data.timePaused;
|
|
|
}
|
|
|
+
|
|
|
this.props.dispatch(changeSong(res.data.currentSong));
|
|
|
+ this.getOwnRatings();
|
|
|
}
|
|
|
|
|
|
socket.on('event:songs.next', data => {
|
|
|
if (data.currentSong) {
|
|
|
- data.currentSong.startedAt = res.data.startedAt;
|
|
|
- data.currentSong.timePaused = res.data.timePaused;
|
|
|
+ data.currentSong.startedAt = data.startedAt;
|
|
|
+ data.currentSong.timePaused = data.timePaused;
|
|
|
}
|
|
|
this.props.dispatch(changeSong(data.currentSong));
|
|
|
+ this.getOwnRatings();
|
|
|
});
|
|
|
|
|
|
socket.on('event:stations.pause', pausedAt => {
|
|
@@ -89,6 +94,47 @@ export default class Station extends Component {
|
|
|
this.props.dispatch(updateTimePaused(data.timePaused));
|
|
|
this.props.dispatch(resumeStation());
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+ socket.on('event:song.like', data => {
|
|
|
+ console.log("LIKE");
|
|
|
+ if (this.props.songExists) {
|
|
|
+ if (data.songId === this.props.songId) {
|
|
|
+ this.props.dispatch(receivedRatings(data.likes, data.dislikes));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ socket.on('event:song.dislike', data => {
|
|
|
+ console.log("DISLIKE");
|
|
|
+ if (this.props.songExists) {
|
|
|
+ if (data.songId === this.props.songId) {
|
|
|
+ this.props.dispatch(receivedRatings(data.likes, data.dislikes));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ socket.on('event:song.unlike', data => {
|
|
|
+ console.log("UNLIKE");
|
|
|
+ if (this.props.songExists) {
|
|
|
+ if (data.songId === this.props.songId) {
|
|
|
+ this.props.dispatch(receivedRatings(data.likes, data.dislikes));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ socket.on('event:song.undislike', data => {
|
|
|
+ console.log("UNDISLIKE");
|
|
|
+ if (this.props.songExists) {
|
|
|
+ if (data.songId === this.props.songId) {
|
|
|
+ this.props.dispatch(receivedRatings(data.likes, data.dislikes));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ socket.on('event:song.newRatings', data => {
|
|
|
+ if (this.props.songExists) {
|
|
|
+ if (data.songId === this.props.songId) {
|
|
|
+ this.props.dispatch(receivedOwnRatings(data.liked, data.disliked));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -101,17 +147,9 @@ export default class Station extends Component {
|
|
|
|
|
|
getOwnRatings = () => {
|
|
|
io.getSocket((socket) => {
|
|
|
- if (!this.state.currentSongExists) return;
|
|
|
- socket.emit('songs.getOwnSongRatings', this.state.currentSong.songId, (data) => {
|
|
|
- if (this.state.currentSong.songId === data.songId) {
|
|
|
- this.setState({
|
|
|
- currentSong: {
|
|
|
- ...this.state.currentSong,
|
|
|
- liked: data.liked,
|
|
|
- disliked: data.disliked,
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
+ if (!this.props.songExists) return;
|
|
|
+ socket.emit('songs.getOwnSongRatings', this.props.songId, (data) => {
|
|
|
+ if (this.props.songId === data.songId) this.props.dispatch(receivedOwnRatings(data.liked, data.disliked));
|
|
|
});
|
|
|
});
|
|
|
};
|
|
@@ -149,6 +187,58 @@ export default class Station extends Component {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ getRatings = () => {
|
|
|
+ const likes = <span>{ this.props.songLikes }</span>;
|
|
|
+ const dislikes = <span>{ this.props.songDislikes }</span>;
|
|
|
+ let likeButton = <i className="material-icons disabled">thumb_up</i>;
|
|
|
+ let dislikeButton = <i className="material-icons disabled">thumb_down</i>;
|
|
|
+
|
|
|
+ if (this.props.loggedIn) {
|
|
|
+ if (this.props.songLiked) likeButton = <i className="material-icons liked" onClick={ this.unlike }>thumb_up</i>;
|
|
|
+ else likeButton = <i className="material-icons" onClick={ this.like }>thumb_up</i>;
|
|
|
+
|
|
|
+ if (this.props.songDisliked) dislikeButton = <i className="material-icons disliked" onClick={ this.undislike }>thumb_down</i>;
|
|
|
+ else dislikeButton = <i className="material-icons" onClick={ this.dislike }>thumb_down</i>;
|
|
|
+ }
|
|
|
+
|
|
|
+ return <div>
|
|
|
+ { likeButton }
|
|
|
+ { likes }
|
|
|
+ { dislikeButton }
|
|
|
+ { dislikes }
|
|
|
+ </div>;
|
|
|
+ };
|
|
|
+
|
|
|
+ like = () => {
|
|
|
+ io.getSocket(socket => {
|
|
|
+ socket.emit('songs.like', this.props.songId, data => {});
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ dislike = () => {
|
|
|
+ io.getSocket(socket => {
|
|
|
+ socket.emit('songs.dislike', this.props.songId, data => {});
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ unlike = () => {
|
|
|
+ io.getSocket(socket => {
|
|
|
+ socket.emit('songs.unlike', this.props.songId, data => {});
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ undislike = () => {
|
|
|
+ io.getSocket(socket => {
|
|
|
+ socket.emit('songs.undislike', this.props.songId, data => {});
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ skip = () => {
|
|
|
+ io.getSocket(socket => {
|
|
|
+ socket.emit('stations.forceSkip', this.props.station.stationId, data => {});
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
const { t } = this.props;
|
|
|
|
|
@@ -156,15 +246,21 @@ export default class Station extends Component {
|
|
|
|
|
|
return (
|
|
|
<main id="station">
|
|
|
+ <Overlays />
|
|
|
+
|
|
|
+ <button onClick={ () => { this.props.dispatch(openOverlay1("settings")) } }>Open settings</button>
|
|
|
+
|
|
|
<h1>{ this.props.station.displayName }</h1>
|
|
|
|
|
|
{ (this.props.station.paused) ? <button onClick={ this.resumeStation }>Resume</button> : <button onClick={ this.pauseStation }>Pause</button>}
|
|
|
|
|
|
<button onClick={ this.addSongTemp }>Add song to queue TEMP</button>
|
|
|
+ <button onClick={ this.skip }>Skip</button>
|
|
|
|
|
|
<hr/>
|
|
|
<div className={(!this.props.songExists) ? "hidden" : ""}>
|
|
|
<Player onRef={ ref => (this.player = ref) }/>
|
|
|
+ { (this.props.station.paused) ? <div><span>Paused</span><i className="material-icons">pause</i></div> : null }
|
|
|
</div>
|
|
|
|
|
|
{ (this.props.songExists) ? (
|
|
@@ -172,15 +268,17 @@ export default class Station extends Component {
|
|
|
<div key="content">
|
|
|
<h1>Title: { this.props.songTitle }</h1>
|
|
|
<br/>
|
|
|
- Paused: { (this.props.station.paused) ? "true" : "false" }
|
|
|
- <br/>
|
|
|
<span>Artists: { this.props.songArtists.join(", ") }</span>
|
|
|
+ <br/>
|
|
|
<span key="time">
|
|
|
{ formatTime(this.props.songTimeElapsed) } - { formatTime(this.props.songDuration) }
|
|
|
</span>
|
|
|
<div key="seekerbar" className="seekerbar-container" style={{"width": "100%", "background-color": "yellow", "height": "20px", "display": "block"}}>
|
|
|
<Seekerbar/>
|
|
|
</div>
|
|
|
+ {
|
|
|
+ (!this.props.simpleSong) ? this.getRatings() : null
|
|
|
+ }
|
|
|
<VolumeSlider key="volumeSlider"/>
|
|
|
</div>,
|
|
|
]) : (
|