-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
89 lines (74 loc) · 1.79 KB
/
Copy pathApp.js
File metadata and controls
89 lines (74 loc) · 1.79 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, {Component} from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Alert,
StatusBar
} from 'react-native';
import axios from 'axios';
import SocketIOClient from 'socket.io-client';
import Vote from "./screens/Vote"
import SelectAnimation from "./screens/SelectAnimation"
const ip = "169.254.162.242";
const port = "80";
export default class App extends Component {
state = {
voting: false
}
static defaultProps = {}
constructor(props) {
super(props);
this.socket = SocketIOClient(`http://${ip}:${port}`)
this.initVote = this.initVote.bind(this);
this.registerVote = this.registerVote.bind(this);
this.resetVote = this.resetVote.bind(this);
}
initVote(name, type) {
var that = this;
this.socket.emit('initVote', {name, type});
this.socket.on('event-id', function(id) {
that.setState({eventID: id, voting: true});
});
}
registerVote(vote) {
const eventID = this.state.eventID;
this.socket.emit('vote', {vote, eventID})
}
resetVote() {
const eventID = this.state.eventID;
this.socket.emit('resetVote', {eventID});
}
componentDidMount() {
}
renderForm() {
return (
<View style={{flexDirection: 'row', justifyContent: 'center'}}>
<StatusBar hidden/>
<SelectAnimation initVote={this.initVote}/>
</View>
)
}
renderVote() {
return (
<View>
<StatusBar hidden/>
<Vote resetVote={this.resetVote} registerVote={this.registerVote}/>
</View>
)
}
render() {
const { voting } = this.state;
if (voting) return this.renderVote()
else return this.renderForm()
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});