1
0
forked from notnull/waveform

Compare commits

..

3 Commits

Author SHA1 Message Date
277251a91a Merge branch 'hosting' of notnull/waveform into master 2019-04-28 16:54:08 -07:00
a9a607efd1 added basename to router
- this enables the app to be hosted from a subdomain in production
2019-04-28 19:52:07 -04:00
09d3af688b sum upvotes and downvotes 2019-04-13 19:31:05 -04:00
9 changed files with 76 additions and 85 deletions

View File

@ -1,12 +1,10 @@
import React from 'react'
import { connect } from 'react-redux'
import { Navbar, Nav, NavDropdown, FormControl, Form, Button } from 'react-bootstrap'
import {LinkContainer} from 'react-router-bootstrap'
import { NavLink } from 'react-router-dom'
const MainNav = (props) => {
const {episodes, captions} = props
const { episodes } = props
return (
<Navbar bg="dark" variant="dark" expand="lg">
<Navbar.Brand href="/">Anarchy Planet</Navbar.Brand>
@ -20,7 +18,7 @@ const MainNav = (props) => {
</NavLink>
)}
</NavDropdown>
<Nav.Link href="/audio">Player</Nav.Link>
<NavLink className="navbar-nav" to="/audio">Player</NavLink>
</Nav>
<Form inline>

View File

@ -2,6 +2,15 @@ import React from 'react'
import CommentRow from './CommentRow'
import { connect } from 'react-redux'
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 => {
@ -12,6 +21,7 @@ const CommentList = props => {
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}
/>

View File

@ -1,40 +1,7 @@
import React from 'react'
import { Row, Col, Media } from 'react-bootstrap'
import CommentVotes from './CommentVotes'
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 toggleVote = (vote) => {
// const userVote = this.props.user.votes.find(vote=>vote.commentId===this.props.id)
// userVote.upvote = vote === 'up' ? (userVote.upvote === 1 ? 0 : 1) : 0
// userVote.downvote = vote === 'down' ? (userVote.downvote === 1 ? 0 : 1) : 0
// const sendThisToBackend = {
// userId: this.props.user.id,
// commentId: this.props.id,
// userUpvote: userVote.upvote,
// userDownvote: userVote.downvote,
// prevUpvote: userVote.upvote,
// prevDownvote: userVote.downvote
// }
//
// this.props.saveVote(sendThisToBackend)
// }
import parseTime from './parseTime'
const CommentRow = props => {
console.log(props)
@ -48,30 +15,21 @@ const CommentRow = props => {
<a href="#" onClick={() => props.updateSongPos(props.comment.secs)}>
{parseTime(props.comment.secs)}
</a>
<Row>
<Col>{props.comment.text}</Col>
</Row>
</Col>
<CommentVotes
commentId={props.comment.id}
userId={props.userId}
userVote={props.userVote}
voteSum={props.voteSum}
/>
</Row>
<Row>
<Col>{props.comment.text}</Col>
</Row>
</Media.Body>
</Media>
)
}
// const mapState = state => {
// return {
// user: state.user
// }
// }
// const mapDispatch = dispatch => {
// return {
// saveVote: vote => dispatch(addVote(vote))
// }
// }
//export default connect(mapState)(CommentRow)
export default CommentRow

View File

@ -4,8 +4,8 @@ import { connect } from 'react-redux'
import { destroyVote, updateVote, addUpvote, addDownvote } from '../../store'
const CommentVotes = props => {
const {commentId, userId, userVote} = props
const {commentId, userId, voteSum, userVote} = props
console.log('COMMENT VOTES!!!!!', props)
const upvote = () => {
console.log('userVote',userVote)
userVote
@ -39,6 +39,11 @@ const CommentVotes = props => {
</a>
</Col>
</Row>
<Row>
<Col>
{voteSum}
</Col>
</Row>
<Row>
<Col>
<a
@ -53,6 +58,7 @@ const CommentVotes = props => {
</a>
</Col>
</Row>
</Col>
)
}

View File

@ -0,0 +1,16 @@
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
}

View File

@ -2,6 +2,8 @@ const createHistory = require('history').createBrowserHistory
const createMemoryHistory = require('history').createMemoryHistory
const history =
process.env.NODE_ENV === 'test' ? createMemoryHistory() : createHistory()
process.env.NODE_ENV === 'test'
? createMemoryHistory()
: createHistory()
export default history

View File

@ -1,15 +1,14 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import {Router} from 'react-router-dom'
import { BrowserRouter as Router } from 'react-router-dom'
import history from './history'
import store from './store'
import App from './app'
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Router basename="/waveform" history={history}>
<App />
</Router>
</Provider>,

View File

@ -4,26 +4,28 @@ import {connect} from 'react-redux'
import { Episodes } from './components/episodes'
import { Captions } from './components/captions'
import Audio from './components/waveform'
import Main from './components'
class Routes extends Component {
componentDidMount() {
}
render() {
import { Main, Navbar } from './components'
import { Login, Signup } from './components/auth-form'
const Routes = () => {
return (
<div>
<Route exact path="/" component = {Main} />
<Route path="/episodes" component={Episodes} />
<Route path="/captions/:slug" component={Captions} />
<Route path="/audio" component={Audio} />
<Route path="/login" component={Login} />
<Route path="/signup" component={Signup} />
<Route path='/navbar' component={Navbar} />
<Route exact path='/' component={Main} />
<Route path='/episodes' component={Episodes} />
<Route path='/captions/:slug' component={Captions} />
<Route path='/audio' component={Audio} />
</div>
)
}
}
const mapState = state => {
return {
episodes: state.episodes,
captions: state.captions
captions: state.captions,
}
}

View File

@ -3,6 +3,10 @@ const path = require('path')
module.exports = {
entry: ['@babel/polyfill', './src/index.js'],
output: {
path: path.resolve(__dirname, '/dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
@ -15,10 +19,6 @@ module.exports = {
resolve: {
extensions: ['*', '.js', '.jsx'],
},
output: {
path: __dirname + '/dist',
filename: 'bundle.js',
},
plugins: [new webpack.HotModuleReplacementPlugin()],
devServer: {
contentBase: path.join(__dirname, 'dist'),