Skip to content

Commit

Permalink
Merge pull request #58 from fac-13/buttonHandler
Browse files Browse the repository at this point in the history
add button and handleClick
  • Loading branch information
jennah2121 authored Jun 5, 2018
2 parents ad94b19 + 6655767 commit 58c5709
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/components/options/options.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from 'react';

const Button = ({ answer, goto }) => {
return <button data-goto={goto}>{answer}</button>;
const Button = ({ answer, goto, clickHandler }) => {
return (
<button onClick={clickHandler} data-goto={goto}>
{answer}
</button>
);
};

function Options({ options }) {
function Options({ options, clickHandler }) {
const optionList = () => {
let i = 0;

return options.map(option => {
return <Button {...option} key={i++} />;
return <Button clickHandler={clickHandler} {...option} key={i++} />;
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/qacontainer/qacontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function QAContainer(props) {
) : (
<React.Fragment>
<Question question={question} />
<Options options={options} />
<Options options={options} clickHandler={props.clickHandler} />
</React.Fragment>
)}
</li>
Expand Down
18 changes: 17 additions & 1 deletion src/components/wayfinder/wayfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@ export default class Wayfinder extends React.Component {
};
}

// TODO need to clear out and restart usersPath if user changes one of their answers
clickHandler = event => {
const goto = event.target.dataset.goto;
this.setState(prevState => {
return {
usersPath: prevState.usersPath.concat(goto)
};
});
};

questionList = () => {
const { content, usersPath } = this.state;

return usersPath.map(item => {
return <QAContainer qablock={content[item]} key={item} />;
return (
<QAContainer
qablock={content[item]}
clickHandler={this.clickHandler}
key={item}
/>
);
});
};

Expand Down

0 comments on commit 58c5709

Please sign in to comment.