From b94927b75e5fc44cc5ac5807f58bee23e772a99c Mon Sep 17 00:00:00 2001 From: notnull Date: Mon, 1 Apr 2019 16:53:48 -0400 Subject: [PATCH] added CommentPopup and Comment - comments currently rendered from fake state data - next step is to update redux store to accept comments --- src/components/waveform/Comment.js | 15 +++ src/components/waveform/CommentPopup.js | 36 +++++++ src/components/waveform/index.js | 135 +++++++++++++++++------- 3 files changed, 147 insertions(+), 39 deletions(-) create mode 100644 src/components/waveform/Comment.js create mode 100644 src/components/waveform/CommentPopup.js diff --git a/src/components/waveform/Comment.js b/src/components/waveform/Comment.js new file mode 100644 index 0000000..21d8cff --- /dev/null +++ b/src/components/waveform/Comment.js @@ -0,0 +1,15 @@ +import React from 'react' +import {Card} from 'react-bootstrap' + +const Comment = props => { + console.log('comment props:', props) + return ( + + + {props.parseTime(props.commentSecs)} + + + + ) +} +export default Comment diff --git a/src/components/waveform/CommentPopup.js b/src/components/waveform/CommentPopup.js new file mode 100644 index 0000000..9cb6757 --- /dev/null +++ b/src/components/waveform/CommentPopup.js @@ -0,0 +1,36 @@ +import React from 'react' +import {Card, Form, Row, Col, Button} from 'react-bootstrap' + + +const Popup = props => { + console.log('POPUP PROPS!', props) + return ( +
+
+ + + Add Comment +
+ + + Time + + + + + + + + + + +
+
+
+
+
+ ) +} + + +export default Popup diff --git a/src/components/waveform/index.js b/src/components/waveform/index.js index 9b1eb3b..e8c5b61 100644 --- a/src/components/waveform/index.js +++ b/src/components/waveform/index.js @@ -1,69 +1,126 @@ -// import React from 'react' -// import Waveform from 'react-audio-waveform' -// -// -// const Audio = props => { -// return ( -// -// )} -// -// export default Audio - import React, { Component } from 'react' import Waveform from 'react-audio-waveform' +import {connect} from 'react-redux' const config = require('./audio/loneDigger.json') import ReactAudioPlayer from 'react-audio-player' +import CommentPopup from './CommentPopup' +import Comment from './Comment' + +const parseTime = secs => { + var hours = Math.floor(secs / 3600) + var minutes = Math.floor((secs - (hours * 3600)) / 60) + var seconds = secs - (hours * 3600) - (minutes * 60) + + if (hours < 10) {hours = '0'+hours} + if (minutes < 10) {minutes = '0'+minutes} + if (seconds < 10) {seconds = '0'+seconds} + return minutes+':'+seconds +} + class App extends Component { constructor(props) { super(props) this.state = { - pos: 0 + playerSize: {}, + duration: 3*60+49, + songSecs: 0, + commentSecs: 0, + commentLoc: 0, + commentText: '', + showPopup: false, + showComment: false, + comments: [{id: 1, commentSecs: 132}] } - this.handleClick = this.handleClick.bind(this) + this.getCommentSecs = this.getCommentSecs.bind(this) + this.getPlayerSize = this.getPlayerSize.bind(this) + this.submitComment = this.submitComment.bind(this) + this.togglePopup = this.togglePopup.bind(this) + this.openCommentPopup = this.openCommentPopup.bind(this) + this.updateCommentText = this.updateCommentText.bind(this) + //this.showComment = this.showComment.bind(this) } - handleClick (secs) { - this.setState({ - pos: secs - }) + getCommentSecs (commentSecs) { + this.setState({commentSecs}) } + getPlayerSize(e) { + if(e){ + this.setState({playerSize: e.getBoundingClientRect()}) + return e.getBoundingClientRect() + } + } + submitComment(e) { + e.preventDefault() + const commentLoc = (this.state.playerSize.width * this.state.commentSecs) / ( this.state.duration * 100) + this.setState({commentLoc}) + this.togglePopup() + this.showComment() + } + + openCommentPopup(commentSecs) { + this.togglePopup() + this.setState({commentSecs}) + this.rap.audioEl.pause() + } + togglePopup() { + this.setState({showPopup: !this.state.showPopup}) + } + + updateCommentText(e) { + e.preventDefault() + this.setState({commentText : e.target.value}) + } render() { + return (

Player

- +
+ {this.waveform = el}} + peaks={config.data} + height={200} + pos={this.state.songSecs} + duration={this.state.duration} + onClick={this.openCommentPopup} + color="#676767" + progressGradientColors={[[0, '#33cccc'], [1, '#aaa']]} + /> + {this.state.comments.map(comment => ) } +
+ { this.rap = element }} - onListen={()=>this.setState({pos:this.rap.audioEl.currentTime})} + onListen={()=>this.setState({songSecs:this.rap.audioEl.currentTime})} /> + + {this.state.showPopup ? + + : null + }
) } } -export default App +const mapState = state => state +export default connect(mapState)(App)