Skip to content

Commit 9b78238

Browse files
authored
Force sync on player ready (#52)
* Force sync on player ready * Only render player if user is Spotify authorized
1 parent 646b834 commit 9b78238

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/containers/SpotifyPlayer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import {fetchAuthToken, setSyncMode} from "../actions/user";
22
import Script from "react-load-script";
33
import React from "react";
44
import {connect} from 'react-redux';
5+
import {SYNC_OPTIONS} from "../components/ForceSyncOption";
56

67
const SpotifyPlayer = (props) => {
78
const {user} = props;
8-
if (!user) return "";
9+
if (!user || !user.spotifyAuthorized) return "";
910
// initialize Spotify web player
1011
const initializePlayer = () => {
1112
window.onSpotifyWebPlaybackSDKReady = () => {
@@ -23,7 +24,9 @@ const SpotifyPlayer = (props) => {
2324
player.connect();
2425
// notify backend about newly connected device as soon as it's ready
2526
player.addListener('ready', () => {
26-
props.dispatch(setSyncMode(user, user.syncMode));
27+
const syncMode = user.syncMode;
28+
props.dispatch(setSyncMode(user, SYNC_OPTIONS.FORCE_SYNC));
29+
props.dispatch(setSyncMode(user, syncMode));
2730
});
2831
};
2932
};

0 commit comments

Comments
 (0)