Skip to content

Instantly share code, notes, and snippets.

@xavierartot
Created August 20, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavierartot/e402271c4881c26bfd713bbe3cfdb553 to your computer and use it in GitHub Desktop.
Save xavierartot/e402271c4881c26bfd713bbe3cfdb553 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom' // withRouter allow to connect the route as property with connect
class ViewPoll extends Component {
componentDidMount() {
const { id, question } = this.props
console.log('xav', question)
console.log(id)
// console.log(question.optionTwo.votes) // id : 6ni6ok3ym7mf1p33lnez
}
render() {
const { id, question } = this.props
// console.log('xav', question)
// console.log(id)
// console.log(question.optionTwo.votes) // id : 6ni6ok3ym7mf1p33lnez
return (
<div className="ViewPoll">
ViewPoll
</div>
)
}
}
function mapStateToProps({
authedUser, users, template, questions,
}, { match }) {
const id = match.params.id
console.log(questions)
const question = questions[id]
console.log(question)
// const allVotes = [...question.optionOne.votes, ...question.optionTwo.votes]
// console.log(allVotes)
// console.log(question.optionTwo.votes) //id : 6ni6ok3ym7mf1p33lnez
//
// '6ni6ok3ym7mf1p33lnez': {
// id: '6ni6ok3ym7mf1p33lnez',
// author: 'johndoe',
// timestamp: 1468479767190,
// optionOne: {
// votes: [],
// text: 'become a superhero',
// },
// optionTwo: {
// votes: ['johndoe', 'sarahedo'],
// text: 'become a supervillian',
// },
// },
const x = { ...question }
// console.log(x.optionOne)
console.log({ ...x.optionTwo })
const ot = { ...x.optionTwo }
// console.log(ot.votes)
const qOne = ot.votes
// console.log(qOne)
// console.log(x.otionTwo)
if (Array.isArray(x.otionTwo)) {
// console.log('xxx')
const test = qOne.filter(e => e === authedUser)
if (test.length > 0) {
// console.log('voted')
}
// console.log(test)
}
// console.log(qOne.length)
// const test = qOne.map(e => e)
// console.log(test)
// q1 = q1.votes.filter((o) => {
// question.optionOne[o] === authedUser
// })
// console.log(q1)
return {
authedUser,
color: template.color,
question,
}
}
export default connect(mapStateToProps)(ViewPoll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment