From 4608d5696852b43046e4afd567b615bd2baed25c Mon Sep 17 00:00:00 2001 From: James Filtness Date: Wed, 9 Aug 2017 21:08:45 +0100 Subject: [PATCH] Stop the player from repeating last track in play queue --- app/actions/play-queue/index.js | 15 ++++++++++- app/actions/player/index.js | 9 +++++-- app/components/play-queue/index.js | 33 +++++++++++++---------- app/components/youtube-player/styles.scss | 3 ++- app/constants/ActionTypes.js | 2 ++ app/reducers/play-queue/index.js | 11 ++++++++ 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/actions/play-queue/index.js b/app/actions/play-queue/index.js index feb8c60..a364f6a 100644 --- a/app/actions/play-queue/index.js +++ b/app/actions/play-queue/index.js @@ -46,6 +46,19 @@ export function trashPlayQueue() { } } + +export function playQueueEnded() { + return { + type: types.PLAY_QUEUE_ENDED, + } +} + +export function resetPlayQueueEnded() { + return { + type: types.RESET_PLAY_QUEUE_ENDED, + } +} + export function setCurrentIndex(index) { return { type: types.SET_CURRENT_INDEX, @@ -147,7 +160,7 @@ export function incrementCurrentIndex() { // play the play queue from the beginning again dispatch(setCurrentIndex(0)); } else { - return; + dispatch(playQueueEnded()) } } else { dispatch({ diff --git a/app/actions/player/index.js b/app/actions/player/index.js index d68b7ca..767454c 100644 --- a/app/actions/player/index.js +++ b/app/actions/player/index.js @@ -2,7 +2,8 @@ import * as types from '../../constants/ActionTypes.js'; import { incrementCurrentIndex, decrementCurrentIndex, - playCurrentIndex + playCurrentIndex, + resetPlayQueueEnded, } from '../play-queue'; export function playVideo(videoData) { @@ -15,7 +16,11 @@ export function playVideo(videoData) { export function trackEnded() { return (dispatch, getState) => { dispatch(incrementCurrentIndex()); - dispatch(playCurrentIndex()); + if (!getState().playQueue.playQueueEnded) { + dispatch(playCurrentIndex()); + } else { + dispatch(resetPlayQueueEnded()); + } } } diff --git a/app/components/play-queue/index.js b/app/components/play-queue/index.js index 9ba3870..0aa8a6c 100644 --- a/app/components/play-queue/index.js +++ b/app/components/play-queue/index.js @@ -1,9 +1,9 @@ import React, { PropTypes } from 'react'; import classNames from 'classNames'; import { connect } from 'react-redux'; -import { - playQueueTrackSelected, - removeTrackFromQueue +import { + playQueueTrackSelected, + removeTrackFromQueue } from '../../actions/play-queue'; export class PlayQueue extends React.Component { @@ -18,7 +18,7 @@ export class PlayQueue extends React.Component { super(); this.currentScrollTop = 0; - + this.state = { renderPlayQueue: false, }; @@ -30,15 +30,20 @@ export class PlayQueue extends React.Component { componentWillReceiveProps(nextProps) { this.shouldRenderPlayQueue(nextProps); + this.savePlayQueueToLocalStorage(nextProps.tracks); if ( - this.props.playQueueCurrentIndex !== + this.props.playQueueCurrentIndex !== nextProps.playQueueCurrentIndex ) { this.scrollToCurrentIndex(nextProps); } } + savePlayQueueToLocalStorage(tracks) { + console.log('new tracks', tracks); + } + scrollToCurrentIndex(props) { let move; @@ -47,9 +52,9 @@ export class PlayQueue extends React.Component { const trackElHeight = trackEl.getBoundingClientRect().height; const trackPos = track * trackElHeight; const trackPosBottomEdge = trackPos + trackElHeight; - const playQueueHeight = this.playQueueWrap.getBoundingClientRect().height; + const playQueueHeight = this.playQueueWrap.getBoundingClientRect().height; const scrollTopPos = this.playQueueWrap.scrollTop; - + if (trackPosBottomEdge > (playQueueHeight + scrollTopPos)) { move = trackPosBottomEdge - (playQueueHeight + scrollTopPos); this.playQueueWrap.scrollTop = scrollTopPos + move; @@ -61,7 +66,7 @@ export class PlayQueue extends React.Component { shouldRenderPlayQueue(props) { let renderPlayQueue; - + if (props.tracks && props.tracks.length) { renderPlayQueue = true; } else { @@ -80,19 +85,19 @@ export class PlayQueue extends React.Component { render() { if (this.state.renderPlayQueue) { - const currentIndex = - this.props.playQueueCurrentIndex ? + const currentIndex = + this.props.playQueueCurrentIndex ? this.props.playQueueCurrentIndex : 0; return ( -
this.playQueueWrap = playQueueWrap } >