{"size": 941, "ext": "js", "max_stars_repo_path": "src/context/VoteContext.js", "max_stars_repo_name": "joshpitzalis/ducksoup", "max_stars_repo_stars_event_min_datetime": "2019-02-19T22:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-19T22:37:00.000Z", "max_issues_repo_path": "src/context/VoteContext.js", "max_issues_repo_name": "joshpitzalis/tinyteams", "max_issues_repo_issues_event_min_datetime": "2019-02-19T06:55:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T06:43:24.000Z", "max_forks_repo_path": "src/context/VoteContext.js", "max_forks_repo_name": "joshpitzalis/tinyteams", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 104, "max_forks_count": null, "avg_line_length": 20.0212765957, "max_line_length": 51, "alphanum_fraction": 0.5324123273}
import React from 'react';
import { updater } from './helpers';
export const VoteContext = React.createContext({});

class VoteProvider extends React.Component {
  state = { polls: {
    1: {
      title: 'New Post',
      id: 1,
      createdBy: 'Josh',
      votes: 5,
      deadline: '3 days',
      fields: ['one', 'two']
    }
  }}

  createPoll = newPoll => this.setState({
      polls: updater(newPoll, this.state.polls)
    });

  // upVote = id => {
  //   const newPosts = { ...this.state.posts };
  //   newPosts[id] = {...newPosts[id],
  //       votes: newPosts[id].votes + 1}
    
  //   return this.setState({
  //       posts: newPosts
  //     });
  // };

  render() {
    return (
      <VoteContext.Provider
        value={{
          polls: this.state.polls,
          createPoll: this.createPoll,
        }}
      >
        {this.props.children}
      </VoteContext.Provider>
    );
  }
}

export default VoteProvider

