Skip to content

Commit a5afb08

Browse files
committed
onclick to show video for each choice
relates to #9 and #8
1 parent 6533aea commit a5afb08

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

client/src/App.js

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import StartTrialCountdown from "./components/Binary/Start_trial_countdown";
66
import StartWebcam from "./components/Binary/StartWebcam";
77
import BinaryPlus from "./components/Binary/Binary_plus";
88
import ChoicesAppear from "./components/Binary/Choices_appear";
9+
import BinaryReward from "./components/Binary/Binary_reward";
910
import StaticForm from "./components/Static/Static_form";
1011
import StaticTest from "./components/Static/Static_container";
1112
import Reward from "./components/Static/Reward";
@@ -89,6 +90,13 @@ class App extends Component {
8990
/>
9091
)}
9192
/>
93+
<Route
94+
exact
95+
path="/binary_trial/:trialId/reward/:letter"
96+
render={props => (
97+
<BinaryReward displayedAssets={this.displayedAssets} {...props} />
98+
)}
99+
/>
92100
<Route exact path="/static_form" component={StaticForm} />
93101
<Route
94102
exact
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { Component } from "react";
2+
import { browserHistory } from "react-router";
3+
import axios from "axios";
4+
class BinaryReward extends Component {
5+
constructor(props) {
6+
super(props);
7+
}
8+
9+
videoEnd = () => {
10+
const id = this.props.match.params.trialId;
11+
this.props.history.push(`/choice_appear/${id}`);
12+
};
13+
14+
render() {
15+
const letter = this.props.match.params.letter;
16+
const letterChosen = this.props.displayedAssets.filter((data, i) => {
17+
if (this.props.displayedAssets[i].letter === letter) {
18+
return this.props.displayedAssets[i];
19+
}
20+
});
21+
return (
22+
<div>
23+
<video
24+
width="100%"
25+
height="100%"
26+
autoPlay
27+
onEnded={this.videoEnd}
28+
ref={vid => {
29+
this.rewardVideo = vid;
30+
}}
31+
>
32+
<source src={letterChosen[0].reward} type="video/mp4" />
33+
</video>
34+
</div>
35+
);
36+
}
37+
}
38+
39+
export default BinaryReward;

client/src/components/Binary/Each_choice.js

+38-9
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,60 @@ class EachChoice extends Component {
1515
this.timer = setInterval(() => {
1616
this.setState({ id: this.state.count, count: this.state.count + 1 });
1717
console.log("interval count: ", this.state.count);
18-
}, 5000);
18+
}, 20000);
1919
}
2020

2121
shouldComponentUpdate(nextProps, nextState) {
2222
console.log(nextProps, nextState);
2323
if (this.state.count === this.props.trial_choices.length) {
24-
console.log("wronggg SHOUDL STOP TIME");
24+
console.log("wronggg SHOULD STOP TIME");
2525
clearInterval(this.timer);
2626
}
2727
return true;
2828
}
29-
29+
letterChosen = letter =>
30+
this.props.displayedAssets.filter((data, i) => {
31+
if (this.props.displayedAssets[i].letter === letter) {
32+
return this.props.displayedAssets[i];
33+
}
34+
});
3035
render() {
31-
console.log(this.props.trial_choices.length);
36+
const id = this.props.match.params.trialId;
3237
if (this.props.trial_choices.length === 0) return <h3>Loading...</h3>;
3338
return (
3439
<div>
35-
{this.props.trial_choices.length > this.state.count ? (
40+
{this.props.trial_choices.length >= this.state.count ? (
3641
<div>
37-
<p>{this.props.trial_choices[this.state.id].Choices_left}</p>
38-
<p>{this.props.trial_choices[this.state.id].Choices_right}</p>
39-
hello
42+
<Link
43+
to={`/binary_trial/${id}/reward/${
44+
this.props.trial_choices[this.state.id].Choices_left
45+
}`}
46+
>
47+
<img
48+
src={
49+
this.letterChosen(
50+
this.props.trial_choices[this.state.id].Choices_left
51+
)[0].fractals
52+
}
53+
/>
54+
</Link>
55+
<span>+</span>
56+
<Link
57+
to={`/binary_trial/${id}/reward/${
58+
this.props.trial_choices[this.state.id].Choices_right
59+
}`}
60+
>
61+
<img
62+
src={
63+
this.letterChosen(
64+
this.props.trial_choices[this.state.id].Choices_right
65+
)[0].fractals
66+
}
67+
/>
68+
</Link>
4069
</div>
4170
) : (
42-
<div> Done! </div>
71+
<div>done</div>
4372
)}
4473
</div>
4574
);

0 commit comments

Comments
 (0)