-
Notifications
You must be signed in to change notification settings - Fork 0
/
Welcome.jsx
62 lines (57 loc) · 1.67 KB
/
Welcome.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { nextGamePhase, userCreated, letSpeak } from '../store/actions';
import { say } from '../lib/dealer';
import { createUser } from '../lib/apiClient';
class Welcome extends Component {
constructor(props) {
super(props);
this.state = {
nameTries: 0,
}
}
async componentDidMount() {
await say('welcome-1');
await say('welcome-2');
await say('welcome-3');
await say('welcome-4');
await say('welcome-5');
await say('welcome-6');
this.props.letSpeak(true);
}
async componentWillReceiveProps(nextProps) {
if (nextProps.lastSpeakResult.text !== null) {
if (this.props.lastSpeakResult.text !== nextProps.lastSpeakResult.text) {
this.props.letSpeak(false);
if (this.state.nameTries === 0) {
await say('name-first-1');
await say('name-first-2');
this.setState({ nameTries: 1 });
this.props.letSpeak(true);
} else {
await say('name-second-1');
await say('name-second-2');
const newUser = await createUser("dumbhead1");
this.props.userCreated(newUser);
this.props.nextPhase();
}
}
}
}
render() {
return (
<div>
Say your name!
</div>
)
}
}
const mapStateToProps = state => ({
lastSpeakResult: state.lastSpeakResult,
});
const mapDispatchToProps = dispatch => ({
nextPhase: () => dispatch(nextGamePhase()),
userCreated: (user) => dispatch(userCreated(user)),
letSpeak: (_letSpeak) => dispatch(letSpeak(_letSpeak)),
});
export default connect(mapStateToProps, mapDispatchToProps)(Welcome);