From 6e6af71ad1e289cc7895ffd89a7a7f601ffb6d07 Mon Sep 17 00:00:00 2001 From: Ahmed-Ayman Date: Fri, 21 Dec 2018 13:37:14 +0200 Subject: [PATCH] fix #22 add related videos section for video player --- src/components/RelatedVideos.js | 50 ++++++++++++++++++++++++++ src/components/VideoPlayer.js | 61 +++++++++++++++++++++++++++----- src/stylesheets/globals.scss | 1 + src/stylesheets/random-item.scss | 3 +- 4 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 src/components/RelatedVideos.js diff --git a/src/components/RelatedVideos.js b/src/components/RelatedVideos.js new file mode 100644 index 0000000..6660b7f --- /dev/null +++ b/src/components/RelatedVideos.js @@ -0,0 +1,50 @@ +import Grid from 'react-css-grid' +import React from 'react'; +import PropTypes from 'prop-types'; +import VideoItem from "./VideoItem"; +import RandomItemTitle from "./SectionHeading"; +import {Link} from 'react-router-dom'; +class RandomTopic extends React.Component { + + shuffleTopic() { + this.props.getRandomTopicVideos(this.props.allTopics); + } + + render() { + return ( +
+

Related Videos

+ + {/* Shuffle button */} + + + + + {this.props.videos.map(video => + + )} + +
+ + ) + } +} + +RandomTopic.propTypes = { + topicName: PropTypes.string, + allTopics: PropTypes.array, + videos: PropTypes.array, + loading: PropTypes.bool, + topicCount: PropTypes.number, + getRandomTopicVideos: PropTypes.func +}; + +export default (RandomTopic); \ No newline at end of file diff --git a/src/components/VideoPlayer.js b/src/components/VideoPlayer.js index 3b83b2a..0e49f85 100644 --- a/src/components/VideoPlayer.js +++ b/src/components/VideoPlayer.js @@ -1,27 +1,70 @@ import React from 'react'; -import PropTypes from 'prop-types'; import {getVideo} from '../utils/video'; -import { Player } from 'video-react'; +import {Player} from 'video-react'; +import RelatedVideos from "./RelatedVideos"; +import {getAllTopics, getRandomTopicVideos} from "../actions/topics"; +import connect from "react-redux/es/connect/connect"; + class VideoPlayer extends React.Component { + componentDidMount() { + if (this.props.allTopics && this.props.allTopics.length > 0 && !this.props.randomTopic) { + this.props.getRandomTopicVideos(this.props.allTopics); + } else { + this.props.getAllTopics(); + } + } + + componentWillReceiveProps(nextProps) { + // This is slightly awkward - we need to check that we have all topics, + // But don't have a random topic yet (or at not already loading a random topic) + if ((this.props.allTopics || nextProps.allTopics) && !this.props.loadingRandomTopic && !nextProps.loadingRandomTopic && !this.props.randomTopic) { + this.props.getRandomTopicVideos(nextProps.allTopics); + } + } + render() { return (
- +

{this.props.title}

date {this.props.date}

{this.props.description}

+
) } } -VideoPlayer.propTypes = { - title: PropTypes.string, - date: PropTypes.string, - description: PropTypes.string -}; +// +// VideoPlayer.propTypes = { +// title: PropTypes.string, +// date: PropTypes.string, +// description: PropTypes.string +// }; -export default VideoPlayer; \ No newline at end of file +const mapStateToProps = state => ({ + allTopics: state.topics.allTopics, + loadingAllTopics: state.topics.loadingAllTopics, + randomTopic: state.topics.randomTopic, + randomTopicCount: state.topics.randomTopicCount, + loadingRandomTopic: state.topics.loadingRandomTopic, + randomTopicVideos: state.topics.randomTopicVideos +}); + +const mapDispatchToProps = dispatch => ({ + getAllTopics: () => dispatch(getAllTopics()), + getRandomTopicVideos: allTopics => dispatch(getRandomTopicVideos(allTopics)) +}); + + +export default connect(mapStateToProps, mapDispatchToProps)(VideoPlayer); \ No newline at end of file diff --git a/src/stylesheets/globals.scss b/src/stylesheets/globals.scss index 13c0f17..abd074d 100644 --- a/src/stylesheets/globals.scss +++ b/src/stylesheets/globals.scss @@ -81,3 +81,4 @@ a { text-decoration: underline; color: $normal-link-color; } + diff --git a/src/stylesheets/random-item.scss b/src/stylesheets/random-item.scss index 52288fc..e127ce7 100644 --- a/src/stylesheets/random-item.scss +++ b/src/stylesheets/random-item.scss @@ -1,7 +1,8 @@ @import "variables"; @import "globals"; -.section-heading { +.section-heading, +.section-subheading { padding-top: 1em; } .section-title{