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

Ampers: Angela Poland #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Next Next commit
adds functionality to get a random story to show up instead of just t…
…he first one
  • Loading branch information
AngelaPoland committed May 31, 2018
commit e5cf17865d34ffafce5deddcd7f97c2924e9ed27
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
}
3 changes: 2 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import Story from './components/Story.js';
class App extends Component {
constructor() {
super();
let num = Math.floor(Math.random() * 3)

this.state = {
selectedMadLib: MadLibs[0]
selectedMadLib: MadLibs[num]
};
}

Expand Down
Empty file added src/components/StoryForm.css
Empty file.
108 changes: 108 additions & 0 deletions src/components/StoryForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import './NewStudentForm.css';


class StoryForm extends Component {
constructor() {
super();
this.state = {
adjective_1: '',
adjective_2: '',
noun_1: '',
noun_2: '',
};
}

static propTypes = {
addWords: PropTypes.func.isRequired,
}

onFieldChange = (key, value) => {
const updatedState = {}
updatedState[key] = value;
this.setState(updatedState);
console.log('updated = ${key}');
}

// onAgeChange = (event) => {
// const age = event.target.value;
// this.setState({
// age,
// });
// }
//
// see the email to see the other way to
// onEmailChange = (event) => {
// const email = event.target.value;
// this.setState({
// email,
// });
// }

// emailValid = () => {
// return this.state.email.match(/\S+@\S+/);
// }

onSubmit = (event) => {
event.preventDefault();
this.props.addStudent({
adjective_1: this.state.adjective_1,
adjective_2: this.state.adjective_2,
noun_1: this.state.noun_1,
noun_2: this.state.noun_2,
});
this.setState({
adjective_1: '',
adjective_2: '',
noun_1: '',
noun_2: '',
});
}

render() {
return (
<div>
<form
onSubmit={this.onSubmit}
className="new-word-form">
<p>Word Form:</p>
<div>
<label htmlFor="adjective_1">Adjective 1:</label>
<input
name="adjective_1"
onChange={(event) => {this.onFieldChange('adjective_1', event.target.value)}}
value={this.state.adjective_1}
/>
</div>
<div>
<label htmlFor="age">Age:</label>
<input
age="age"
onChange={(event) => {this.onFieldChange('age', event.target.value)}}
value={this.state.age}
/>
</div>
<div>
<label htmlFor="email">Email:</label>
<input
email="email"
// onChange={this.onEmailChange}
onChange={(event) => {this.onFieldChange('email', event.target.value)}}
value={this.state.email}
className={this.emailValid() ? "valid" : "invalid"}
/>
</div>
<input
className="button success"
type="submit"
value="Add Student"
/>
</form>
</div>
);
}
}


export default NewStudentForm;