Compare commits
No commits in common. "master" and "comments" have entirely different histories.
24
package-lock.json
generated
24
package-lock.json
generated
@ -3297,14 +3297,12 @@
|
|||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@ -3319,20 +3317,17 @@
|
|||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@ -3449,8 +3444,7 @@
|
|||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
@ -3462,7 +3456,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
@ -3477,7 +3470,6 @@
|
|||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
@ -3491,7 +3483,6 @@
|
|||||||
"version": "2.3.5",
|
"version": "2.3.5",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "^5.1.2",
|
"safe-buffer": "^5.1.2",
|
||||||
"yallist": "^3.0.0"
|
"yallist": "^3.0.0"
|
||||||
@ -3590,8 +3581,7 @@
|
|||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
@ -3603,7 +3593,6 @@
|
|||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1"
|
"wrappy": "1"
|
||||||
}
|
}
|
||||||
@ -3725,7 +3714,6 @@
|
|||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
const router = require('express').Router()
|
const router = require('express').Router()
|
||||||
const { Comment } = require('../db/models')
|
const { Vote, Comment } = require('../db/models')
|
||||||
|
const Sequelize = require('sequelize')
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
||||||
|
|
||||||
router.get('/', async (req, res, next) => {
|
router.get('/', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const comments = await Comment.findAll({
|
const comments = await Comment.findAll({
|
||||||
attributes: ['id', 'secs', 'text']})
|
attributes: ['id', 'secs', 'text'],
|
||||||
|
})
|
||||||
res.send(comments)
|
res.send(comments)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err)
|
next(err)
|
||||||
@ -17,7 +17,8 @@ router.get('/', async (req, res, next) => {
|
|||||||
router.get('/:id', async (req, res, next) => {
|
router.get('/:id', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const comment = await Comment.findByPk(req.params.id, {
|
const comment = await Comment.findByPk(req.params.id, {
|
||||||
attributes: ['id', 'secs', 'text']})
|
attributes: ['id', 'secs', 'text'],
|
||||||
|
})
|
||||||
res.json(comment)
|
res.json(comment)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err)
|
next(err)
|
||||||
|
@ -2,9 +2,7 @@ const router = require('express').Router()
|
|||||||
module.exports = router
|
module.exports = router
|
||||||
const ascii = require('../ascii')
|
const ascii = require('../ascii')
|
||||||
|
|
||||||
router.use('/users', require('./users'))
|
|
||||||
router.use('/comments', require('./comments'))
|
router.use('/comments', require('./comments'))
|
||||||
router.use('/votes', require('./votes'))
|
|
||||||
|
|
||||||
router.get('/', async (req, res, next) => {
|
router.get('/', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
const router = require('express').Router()
|
|
||||||
const { User, Vote } = require('../db/models')
|
|
||||||
module.exports = router
|
|
||||||
|
|
||||||
router.get('/', async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
const users = await User.findAll({
|
|
||||||
attributes: ['id', 'name']
|
|
||||||
})
|
|
||||||
res.send(users)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/:id', async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
const user = await User.findByPk(req.params.id,
|
|
||||||
{attributes: ['id', 'name'],
|
|
||||||
include: {model: Vote,
|
|
||||||
attributes: ['id', 'userId','commentId', 'upvote', 'downvote']}})
|
|
||||||
res.json(user)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/:id/votes', async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
const user = await User.findByPk(req.params.id,
|
|
||||||
{attributes: ['id', 'name'],
|
|
||||||
include: {model: Vote,
|
|
||||||
attributes: ['id', 'userId','commentId', 'upvote', 'downvote']}})
|
|
||||||
res.json(user.votes)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
@ -1,53 +0,0 @@
|
|||||||
const router = require('express').Router()
|
|
||||||
const { Vote } = require('../db/models')
|
|
||||||
module.exports = router
|
|
||||||
|
|
||||||
router.get('/', async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
const votes = await Vote.findAll()
|
|
||||||
res.send(votes)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.post('/', async (req, res, next) => {
|
|
||||||
const {userId, commentId, upvote, downvote} = req.body
|
|
||||||
try {
|
|
||||||
const votes = await Vote.create({userId, commentId, upvote, downvote})
|
|
||||||
res.send(votes)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/:id', async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
const vote = await Vote.findByPk(+req.params.id)
|
|
||||||
res.json(vote)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.post('/:id/delete', async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
const vote = await Vote.findByPk(+req.params.id)
|
|
||||||
await vote.destroy()
|
|
||||||
res.json(vote)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.put('/:id/update', async (req, res, next) => {
|
|
||||||
const upvote = req.body.downvote
|
|
||||||
const downvote = req.body.upvote
|
|
||||||
try {
|
|
||||||
const vote = await Vote.findByPk(+req.params.id)
|
|
||||||
await vote.update({upvote, downvote})
|
|
||||||
res.json(vote)
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
@ -1,13 +1,3 @@
|
|||||||
const Comment = require('./comment')
|
const Comment = require('./comment')
|
||||||
const Vote = require('./vote')
|
|
||||||
const User = require('./user')
|
|
||||||
|
|
||||||
Vote.belongsTo(Comment)
|
module.exports = { Comment }
|
||||||
Comment.hasMany(Vote)
|
|
||||||
|
|
||||||
Vote.belongsTo(User)
|
|
||||||
User.hasMany(Vote)
|
|
||||||
|
|
||||||
Comment.belongsTo(User)
|
|
||||||
User.hasMany(Comment)
|
|
||||||
module.exports = { Comment, Vote, User }
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
const Sequelize = require('sequelize')
|
|
||||||
const db = require('../db')
|
|
||||||
|
|
||||||
const User = db.define('users', {
|
|
||||||
name: Sequelize.STRING,
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = User
|
|
@ -1,9 +0,0 @@
|
|||||||
const Sequelize = require('sequelize')
|
|
||||||
const db = require('../db')
|
|
||||||
|
|
||||||
const Vote = db.define('votes', {
|
|
||||||
upvote: Sequelize.INTEGER,
|
|
||||||
downvote: Sequelize.INTEGER,
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = Vote
|
|
@ -1,10 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux'
|
||||||
import { Navbar, Nav, NavDropdown, FormControl, Form, Button } from 'react-bootstrap'
|
import { Navbar, Nav, NavDropdown, FormControl, Form, Button } from 'react-bootstrap'
|
||||||
|
import {LinkContainer} from 'react-router-bootstrap'
|
||||||
import {NavLink} from 'react-router-dom'
|
import {NavLink} from 'react-router-dom'
|
||||||
|
|
||||||
const MainNav = (props) => {
|
const MainNav = (props) => {
|
||||||
const { episodes } = props
|
const {episodes, captions} = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Navbar bg="dark" variant="dark" expand="lg">
|
<Navbar bg="dark" variant="dark" expand="lg">
|
||||||
<Navbar.Brand href="/">Anarchy Planet</Navbar.Brand>
|
<Navbar.Brand href="/">Anarchy Planet</Navbar.Brand>
|
||||||
@ -18,7 +20,7 @@ const MainNav = (props) => {
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
)}
|
)}
|
||||||
</NavDropdown>
|
</NavDropdown>
|
||||||
<NavLink className="navbar-nav" to="/audio">Player</NavLink>
|
<Nav.Link href="/audio">Player</Nav.Link>
|
||||||
</Nav>
|
</Nav>
|
||||||
|
|
||||||
<Form inline>
|
<Form inline>
|
||||||
|
@ -2,29 +2,12 @@ import React from 'react'
|
|||||||
import CommentRow from './CommentRow'
|
import CommentRow from './CommentRow'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { ListGroup } from 'react-bootstrap'
|
import { ListGroup } from 'react-bootstrap'
|
||||||
const sum = (a,b) => a + b
|
|
||||||
|
|
||||||
const sumVotes = voteArray => {
|
|
||||||
if(voteArray.length===0) return 0
|
|
||||||
if(voteArray.length===1) return voteArray[0].upvote===1 ? 1 : -1
|
|
||||||
const upvotes = voteArray.map(vote=>+vote.upvote).reduce(sum)
|
|
||||||
const downvotes = voteArray.map(vote=>+vote.downvote).reduce(sum)
|
|
||||||
return upvotes - downvotes
|
|
||||||
}
|
|
||||||
|
|
||||||
const CommentList = props => {
|
const CommentList = props => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListGroup>
|
<ListGroup>
|
||||||
{props.comments.map(comment => (
|
{props.comments.map(comment => (
|
||||||
<CommentRow
|
<CommentRow key={comment.id} updateSongPos={props.updateSongPos} comment={comment} />
|
||||||
key={comment.id}
|
|
||||||
userId={props.user.id}
|
|
||||||
userVote={props.votes.find(vote=>vote.commentId===comment.id && vote.userId===props.user.id)}
|
|
||||||
voteSum={sumVotes(props.votes.filter(vote=>vote.commentId===comment.id))}
|
|
||||||
updateSongPos={props.updateSongPos}
|
|
||||||
comment={comment}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</ListGroup>
|
</ListGroup>
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,23 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Row, Col, Media } from 'react-bootstrap'
|
import { Row, Col, Media } from 'react-bootstrap'
|
||||||
import CommentVotes from './CommentVotes'
|
|
||||||
import parseTime from './parseTime'
|
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
|
||||||
|
}
|
||||||
|
|
||||||
const CommentRow = props => {
|
const CommentRow = props => {
|
||||||
console.log(props)
|
console.log(props)
|
||||||
|
|
||||||
@ -15,21 +31,13 @@ const CommentRow = props => {
|
|||||||
<a href="#" onClick={() => props.updateSongPos(props.comment.secs)}>
|
<a href="#" onClick={() => props.updateSongPos(props.comment.secs)}>
|
||||||
{parseTime(props.comment.secs)}
|
{parseTime(props.comment.secs)}
|
||||||
</a>
|
</a>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
<Col>{props.comment.text}</Col>
|
<Col>{props.comment.text}</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
|
||||||
<CommentVotes
|
|
||||||
commentId={props.comment.id}
|
|
||||||
userId={props.userId}
|
|
||||||
userVote={props.userVote}
|
|
||||||
voteSum={props.voteSum}
|
|
||||||
/>
|
|
||||||
</Row>
|
|
||||||
|
|
||||||
</Media.Body>
|
</Media.Body>
|
||||||
</Media>
|
</Media>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CommentRow
|
export default CommentRow
|
||||||
|
58
src/components/waveform/CommentRowClass.js
Normal file
58
src/components/waveform/CommentRowClass.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Row, Col, Media } from 'react-bootstrap'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
import { addVote } from '../../store'
|
||||||
|
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 CommentRow extends React.Component {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Media style={{ borderStyle: 'solid' }}>
|
||||||
|
<img width={36} height={36} className="mr-1" src="/img/anarchybang.jpg" />
|
||||||
|
<Media.Body>
|
||||||
|
<Row>
|
||||||
|
<Col>
|
||||||
|
Anon at{' '}
|
||||||
|
<a href="#" onClick={() => this.props.updateSongPos(this.props.secs)}>
|
||||||
|
{parseTime(this.props.secs)}
|
||||||
|
</a>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row>
|
||||||
|
<Col>{this.props.text}</Col>
|
||||||
|
</Row>
|
||||||
|
</Media.Body>
|
||||||
|
</Media>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapState = state => ({ user: { id: 1 }, ...state })
|
||||||
|
// const mapDispatch = dispatch => {
|
||||||
|
// return {
|
||||||
|
// saveVote: vote => dispatch(addVote(vote)),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
export default connect(
|
||||||
|
mapState,
|
||||||
|
mapDispatch,
|
||||||
|
)(CommentRow)
|
@ -1,74 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { Row, Col } from 'react-bootstrap'
|
|
||||||
import { connect } from 'react-redux'
|
|
||||||
import { destroyVote, updateVote, addUpvote, addDownvote } from '../../store'
|
|
||||||
|
|
||||||
const CommentVotes = props => {
|
|
||||||
const {commentId, userId, voteSum, userVote} = props
|
|
||||||
console.log('COMMENT VOTES!!!!!', props)
|
|
||||||
const upvote = () => {
|
|
||||||
console.log('userVote',userVote)
|
|
||||||
userVote
|
|
||||||
? userVote.upvote===1
|
|
||||||
? props.deleteVote(userVote.id)
|
|
||||||
: props.editVote(userVote)
|
|
||||||
: props.upvote(userId, commentId)
|
|
||||||
}
|
|
||||||
|
|
||||||
const downvote = () => {
|
|
||||||
userVote
|
|
||||||
? userVote.downvote===1
|
|
||||||
? props.deleteVote(userVote.id)
|
|
||||||
: props.editVote(userVote)
|
|
||||||
: props.downvote(userId, commentId)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Col className="mr-3 float-right text-right">
|
|
||||||
<Row>
|
|
||||||
<Col>
|
|
||||||
<a
|
|
||||||
className={
|
|
||||||
userVote && userVote.upvote === 1
|
|
||||||
? 'text-danger' : 'text-muted'
|
|
||||||
}
|
|
||||||
href="#"
|
|
||||||
onClick={upvote}
|
|
||||||
>
|
|
||||||
⏶
|
|
||||||
</a>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row>
|
|
||||||
<Col>
|
|
||||||
{voteSum}
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row>
|
|
||||||
<Col>
|
|
||||||
<a
|
|
||||||
className={
|
|
||||||
userVote && userVote.downvote === 1
|
|
||||||
? 'text-primary' : 'text-muted'
|
|
||||||
}
|
|
||||||
href="#"
|
|
||||||
onClick={downvote}
|
|
||||||
>
|
|
||||||
⏷
|
|
||||||
</a>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
|
|
||||||
</Col>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapDispatch = dispatch => {
|
|
||||||
return {
|
|
||||||
deleteVote: userVote => dispatch(destroyVote(userVote)),
|
|
||||||
editVote: userVote => dispatch(updateVote(userVote)),
|
|
||||||
upvote: (userId, commentId) => dispatch(addUpvote(userId, commentId)),
|
|
||||||
downvote: (userId, commentId) => dispatch(addDownvote(userId, commentId)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default connect(null, mapDispatch)(CommentVotes)
|
|
@ -2,10 +2,11 @@ import React, { Component } from 'react'
|
|||||||
import Waveform from 'react-audio-waveform'
|
import Waveform from 'react-audio-waveform'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import ReactAudioPlayer from 'react-audio-player'
|
import ReactAudioPlayer from 'react-audio-player'
|
||||||
|
import CommentPopup from './CommentPopup'
|
||||||
import Comment from './Comment'
|
import Comment from './Comment'
|
||||||
import CommentList from './CommentList'
|
import CommentList from './CommentList'
|
||||||
import { getUser, fetchAllComments, addComment, getAllVotes } from '../../store'
|
import { fetchAllComments, addComment } from '../../store'
|
||||||
import { Media, Form, Container, Row, Col } from 'react-bootstrap'
|
import { Media, Form, Button, Container, Row, Col } from 'react-bootstrap'
|
||||||
const config = require('./audio/loneDigger.json')
|
const config = require('./audio/loneDigger.json')
|
||||||
|
|
||||||
const parseTime = secs => {
|
const parseTime = secs => {
|
||||||
@ -47,9 +48,7 @@ class Player extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchData() {
|
async fetchData() {
|
||||||
await this.props.fetchUser()
|
|
||||||
await this.props.fetchComments()
|
await this.props.fetchComments()
|
||||||
await this.props.fetchAllVotes()
|
|
||||||
await this.setState({ loading: false })
|
await this.setState({ loading: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +81,7 @@ class Player extends Component {
|
|||||||
updateSongPos(secs) {
|
updateSongPos(secs) {
|
||||||
this.setState({ songPos: secs })
|
this.setState({ songPos: secs })
|
||||||
this.rap.audioEl.currentTime = secs
|
this.rap.audioEl.currentTime = secs
|
||||||
|
this.rap.audioEl.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -158,8 +158,6 @@ const mapState = state => ({ ...state })
|
|||||||
const mapDispatch = dispatch => {
|
const mapDispatch = dispatch => {
|
||||||
return {
|
return {
|
||||||
fetchComments: () => dispatch(fetchAllComments()),
|
fetchComments: () => dispatch(fetchAllComments()),
|
||||||
fetchUser: () => dispatch(getUser()),
|
|
||||||
fetchAllVotes: userId => dispatch(getAllVotes(userId)),
|
|
||||||
postComment: comment => dispatch(addComment(comment)),
|
postComment: comment => dispatch(addComment(comment)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
export default 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
|
|
||||||
}
|
|
@ -2,8 +2,6 @@ const createHistory = require('history').createBrowserHistory
|
|||||||
const createMemoryHistory = require('history').createMemoryHistory
|
const createMemoryHistory = require('history').createMemoryHistory
|
||||||
|
|
||||||
const history =
|
const history =
|
||||||
process.env.NODE_ENV === 'test'
|
process.env.NODE_ENV === 'test' ? createMemoryHistory() : createHistory()
|
||||||
? createMemoryHistory()
|
|
||||||
: createHistory()
|
|
||||||
|
|
||||||
export default history
|
export default history
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import {Provider} from 'react-redux'
|
import {Provider} from 'react-redux'
|
||||||
import { BrowserRouter as Router } from 'react-router-dom'
|
import {Router} from 'react-router-dom'
|
||||||
import history from './history'
|
import history from './history'
|
||||||
import store from './store'
|
import store from './store'
|
||||||
import App from './app'
|
import App from './app'
|
||||||
|
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<Router basename="/waveform" history={history}>
|
<Router history={history}>
|
||||||
<App />
|
<App />
|
||||||
</Router>
|
</Router>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
|
@ -4,28 +4,26 @@ import { connect } from 'react-redux'
|
|||||||
import {Episodes} from './components/episodes'
|
import {Episodes} from './components/episodes'
|
||||||
import {Captions} from './components/captions'
|
import {Captions} from './components/captions'
|
||||||
import Audio from './components/waveform'
|
import Audio from './components/waveform'
|
||||||
import { Main, Navbar } from './components'
|
import Main from './components'
|
||||||
import { Login, Signup } from './components/auth-form'
|
class Routes extends Component {
|
||||||
|
componentDidMount() {
|
||||||
const Routes = () => {
|
}
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Route path="/login" component={Login} />
|
<Route exact path="/" component = {Main} />
|
||||||
<Route path="/signup" component={Signup} />
|
<Route path="/episodes" component={Episodes} />
|
||||||
<Route path='/navbar' component={Navbar} />
|
<Route path="/captions/:slug" component={Captions} />
|
||||||
<Route exact path='/' component={Main} />
|
<Route path="/audio" component={Audio} />
|
||||||
<Route path='/episodes' component={Episodes} />
|
|
||||||
<Route path='/captions/:slug' component={Captions} />
|
|
||||||
<Route path='/audio' component={Audio} />
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapState = state => {
|
const mapState = state => {
|
||||||
return {
|
return {
|
||||||
episodes: state.episodes,
|
episodes: state.episodes,
|
||||||
captions: state.captions,
|
captions: state.captions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,11 +5,8 @@ import { composeWithDevTools } from 'redux-devtools-extension'
|
|||||||
import episodes from './reducers/episodes'
|
import episodes from './reducers/episodes'
|
||||||
import captions from './reducers/captions'
|
import captions from './reducers/captions'
|
||||||
import comments from './reducers/comments'
|
import comments from './reducers/comments'
|
||||||
import user from './reducers/users'
|
|
||||||
import votes from './reducers/votes'
|
|
||||||
|
|
||||||
|
const reducer = combineReducers({ episodes, captions, comments })
|
||||||
const reducer = combineReducers({episodes, captions, comments, user, votes})
|
|
||||||
const middleware = composeWithDevTools(
|
const middleware = composeWithDevTools(
|
||||||
applyMiddleware(thunkMiddleware, createLogger({ collapsed: true })),
|
applyMiddleware(thunkMiddleware, createLogger({ collapsed: true })),
|
||||||
)
|
)
|
||||||
@ -19,5 +16,3 @@ export default store
|
|||||||
export * from './reducers/episodes'
|
export * from './reducers/episodes'
|
||||||
export * from './reducers/captions'
|
export * from './reducers/captions'
|
||||||
export * from './reducers/comments'
|
export * from './reducers/comments'
|
||||||
export * from './reducers/users'
|
|
||||||
export * from './reducers/votes'
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import {addedVote} from './votes'
|
|
||||||
|
|
||||||
// ACTION TYPES
|
// ACTION TYPES
|
||||||
const GOT_ALL_COMMENTS = 'GOT_ALL_COMMENTS'
|
const GOT_ALL_COMMENTS = 'GOT_ALL_COMMENTS'
|
||||||
const ADD_COMMENT = 'ADD_COMMENT'
|
const ADD_COMMENT = 'ADD_COMMENT'
|
||||||
const UPVOTED_COMMENT = 'UPVOTED_COMMENT'
|
|
||||||
const DOWNVOTED_COMMENT = 'DOWNVOTED_COMMENT'
|
|
||||||
const initialComments = []
|
const initialComments = []
|
||||||
|
|
||||||
// ACTION CREATORS
|
// ACTION CREATORS
|
||||||
@ -19,15 +16,6 @@ export const addedComment = comment => ({
|
|||||||
comment,
|
comment,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const upvotedComment = comment => ({
|
|
||||||
type: UPVOTED_COMMENT,
|
|
||||||
comment,
|
|
||||||
})
|
|
||||||
|
|
||||||
export const downvotedComment = comment => ({
|
|
||||||
type: DOWNVOTED_COMMENT,
|
|
||||||
comment,
|
|
||||||
})
|
|
||||||
// THUNK CREATORS
|
// THUNK CREATORS
|
||||||
export const fetchAllComments = () => async dispatch => {
|
export const fetchAllComments = () => async dispatch => {
|
||||||
try {
|
try {
|
||||||
@ -48,28 +36,6 @@ export const addComment = comment => async dispatch => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const upvoteComment = (userId, commentId) => async dispatch => {
|
|
||||||
console.log('REDUCER UPVOTECOMMENT', userId, commentId)
|
|
||||||
try {
|
|
||||||
const {data} = await axios.post(`/api/comments/${commentId}/upvote`, {userId})
|
|
||||||
console.log('the votesum should have changed', data)
|
|
||||||
dispatch(upvotedComment(data.comment))
|
|
||||||
dispatch(addedVote(data.vote))
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const downvoteComment = (userId, commentId) => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.post(`/api/comments/${commentId}/downvote`, {userId})
|
|
||||||
console.log('the votesum should have changed', data)
|
|
||||||
dispatch(downvotedComment(data.comment))
|
|
||||||
dispatch(addedVote(data.vote))
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// export const addVote = vote => async dispatch => {
|
// export const addVote = vote => async dispatch => {
|
||||||
//
|
//
|
||||||
// try {
|
// try {
|
||||||
@ -87,10 +53,6 @@ const commentReducer = (comments = initialComments, action) => {
|
|||||||
return action.comments
|
return action.comments
|
||||||
case ADD_COMMENT:
|
case ADD_COMMENT:
|
||||||
return comments.concat(action.comment)
|
return comments.concat(action.comment)
|
||||||
case UPVOTED_COMMENT: {
|
|
||||||
const oldComments = comments.filter(comment=>comment.id !== action.comment.id)
|
|
||||||
return oldComments.concat(action.comment)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return comments
|
return comments
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
import axios from 'axios'
|
|
||||||
|
|
||||||
const initialUser = {}
|
|
||||||
|
|
||||||
// ACTION TYPES
|
|
||||||
const GOT_USER = 'GOT_USER'
|
|
||||||
|
|
||||||
export const gotUser = user => ({
|
|
||||||
type: GOT_USER,
|
|
||||||
user,
|
|
||||||
})
|
|
||||||
|
|
||||||
export const getUser = () => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.get(`/api/users/${1}`)
|
|
||||||
const user = {id: data.id, name: data.name}
|
|
||||||
dispatch(gotUser(user))
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// REDUCER
|
|
||||||
const userReducer = (user = initialUser, action) => {
|
|
||||||
switch (action.type) {
|
|
||||||
case GOT_USER:
|
|
||||||
return action.user
|
|
||||||
default:
|
|
||||||
return user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default userReducer
|
|
@ -1,102 +0,0 @@
|
|||||||
import axios from 'axios'
|
|
||||||
|
|
||||||
const initialUserVotes = []
|
|
||||||
|
|
||||||
// ACTION TYPES
|
|
||||||
const GOT_ALL_VOTES = 'GOT_ALL_VOTES'
|
|
||||||
const DELETED_VOTE = 'DELETED_VOTE'
|
|
||||||
const UPVOTED = 'UPVOTED'
|
|
||||||
const DOWNVOTED = 'DOWNVOTED'
|
|
||||||
const UPDATED_VOTE = 'UPDATED_VOTE'
|
|
||||||
|
|
||||||
export const gotAllVotes = votes => ({
|
|
||||||
type: GOT_ALL_VOTES,
|
|
||||||
votes
|
|
||||||
})
|
|
||||||
|
|
||||||
export const deletedVote = oldVote => ({
|
|
||||||
type: DELETED_VOTE,
|
|
||||||
oldVote
|
|
||||||
})
|
|
||||||
|
|
||||||
export const upvoted = newVote => ({
|
|
||||||
type: UPVOTED,
|
|
||||||
newVote
|
|
||||||
})
|
|
||||||
export const downvoted = newVote => ({
|
|
||||||
type: DOWNVOTED,
|
|
||||||
newVote
|
|
||||||
})
|
|
||||||
export const updatedVote = newVote => ({
|
|
||||||
type: UPDATED_VOTE,
|
|
||||||
newVote
|
|
||||||
})
|
|
||||||
|
|
||||||
export const addUpvote = (userId, commentId) => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.post('/api/votes', {upvote: 1, downvote: 0, userId, commentId})
|
|
||||||
dispatch(upvoted(data))
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const addDownvote = (userId, commentId) => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.post('/api/votes', {upvote: 0, downvote: 1, userId, commentId})
|
|
||||||
dispatch(downvoted(data))
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export const destroyVote = id => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.post(`/api/votes/${id}/delete`)
|
|
||||||
dispatch(deletedVote(data))
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const updateVote = userVote => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.put(`/api/votes/${userVote.id}/update`, userVote)
|
|
||||||
dispatch(updatedVote(data))
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getAllVotes = () => async dispatch => {
|
|
||||||
try {
|
|
||||||
const {data} = await axios.get('/api/votes')
|
|
||||||
dispatch(gotAllVotes(data))
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// REDUCER
|
|
||||||
const voteReducer = (votes = initialUserVotes, action) => {
|
|
||||||
switch (action.type) {
|
|
||||||
case GOT_ALL_VOTES:
|
|
||||||
return action.votes
|
|
||||||
case DELETED_VOTE: {
|
|
||||||
const newVotes = votes.filter(vote => vote.id !== action.oldVote.id)
|
|
||||||
return newVotes
|
|
||||||
}
|
|
||||||
case UPDATED_VOTE: {
|
|
||||||
const newVotes = votes.filter(vote => vote.id !== action.newVote.id)
|
|
||||||
return newVotes.concat(action.newVote)
|
|
||||||
}
|
|
||||||
case UPVOTED: {
|
|
||||||
return votes.concat(action.newVote)
|
|
||||||
}
|
|
||||||
case DOWNVOTED: {
|
|
||||||
return votes.concat(action.newVote)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return votes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default voteReducer
|
|
@ -3,10 +3,6 @@ const path = require('path')
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: ['@babel/polyfill', './src/index.js'],
|
entry: ['@babel/polyfill', './src/index.js'],
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, '/dist'),
|
|
||||||
filename: 'bundle.js',
|
|
||||||
},
|
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
@ -19,6 +15,10 @@ module.exports = {
|
|||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['*', '.js', '.jsx'],
|
extensions: ['*', '.js', '.jsx'],
|
||||||
},
|
},
|
||||||
|
output: {
|
||||||
|
path: __dirname + '/dist',
|
||||||
|
filename: 'bundle.js',
|
||||||
|
},
|
||||||
plugins: [new webpack.HotModuleReplacementPlugin()],
|
plugins: [new webpack.HotModuleReplacementPlugin()],
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: path.join(__dirname, 'dist'),
|
contentBase: path.join(__dirname, 'dist'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user