Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wini Irarrazaval -Octos - Madlib #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added methods to pass in the new state from the form
  • Loading branch information
winirarrazaval committed Jun 2, 2018
commit 440a2f62d12cc7860f164e63dd183d8d871b71ee
30 changes: 20 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React, { Component } from 'react';
import './App.css';
import MadLibs from './madlibs/MadLibs.js';
import Story from './components/Story.js';
import GetWordsForm from "./components/GetWordsForm"

class App extends Component {
constructor() {
super();

this.state = {
selectedMadLib: MadLibs[0]
selectedMadLib: MadLibs[Math.floor(Math.random() * MadLibs.length)]
};
}

Expand All @@ -23,18 +24,27 @@ class App extends Component {
this.setState({selectedMadLib: updatedMadLib});
}

onFormSubmit = (formState) => {
Object.keys(formState).forEach((key) => {
const value = formState[key];
this.updateWord(key, value);
})
}


render() {
const wordsToFind = this.state.selectedMadLib.words;


return (
<section className="App">
<h1>Welcome to MadLibs!</h1>
<p>Fill in all of the choices to see your final story.</p>
{/*
Render your form with input values
*/}
<Story
title={ this.state.selectedMadLib.title }
text={ this.state.selectedMadLib.getText() }
/>
<h1>Welcome to MadLibs!</h1>
<p>Fill in all of the choices to see your final story.</p>
<GetWordsForm words={wordsToFind} updatewords={this.onFormSubmit}/>
<Story
title={ this.state.selectedMadLib.title }
text={ this.state.selectedMadLib.getText() }
/>
</section>
);
}
Expand Down