Skip to content
Snippets Groups Projects
Commit 49a686ac authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Tracking should work, need to implement endtoend

parent 52076b6a
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,7 @@ import Login from "./components/Login"; ...@@ -6,8 +6,7 @@ import Login from "./components/Login";
export default class App extends React.Component { export default class App extends React.Component {
state = { state = {
userLocation: null, userLocation: null
usersHistory: []
}; };
userTrackingHandler = () => { userTrackingHandler = () => {
......
import React, { Component, Fragment } from "react"; import React, { Component, Fragment } from "react";
import { FlatList, Button } from "react-native"; import { FlatList, Button, Picker, Text, StyleSheet } from "react-native";
import LocationTracker from "./LocationTracker";
class GameList extends Component { class GameList extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
games: [], games: [],
tracking: false,
selectedGame: null, selectedGame: null,
editForm: false editForm: false
}; };
intervalID = 0;
} }
componentDidMount() { componentDidMount() {
...@@ -28,17 +33,69 @@ class GameList extends Component { ...@@ -28,17 +33,69 @@ class GameList extends Component {
}); });
} }
handleTrackingChange() {
this.setState({ tracking: !this.state.tracking });
}
startTracking() {
this.intervalID = setInterval(() => {
console.log("Nyt träkätää nim birusti.");
}, 3000);
}
stopTracking() {
clearInterval(this.intervalID);
console.log("Nyt lopetetaa seuranta.");
}
componentDidUpdate() {
if (this.state.tracking) {
this.startTracking();
} else if (!this.state.tracking) {
this.stopTracking();
}
}
componentWillUnmount() {
clearInterval(this.intervalID);
}
render() { render() {
return ( if (this.state.games.length > 0) {
<Fragment> const items = (
{this.state.games.length > 0 && ( <Fragment>
<FlatList <Picker
data={this.state.games} style={styles.picker}
renderItem={({ item }) => <Button title={item.name} />} selectedValue={this.state.selectedGame}
onValueChange={(selectedGame, itemIndex) =>
this.setState({ selectedGame })
}
>
{this.state.games.map(game => (
<Picker.Item label={game.name} value={game.id} />
))}
</Picker>
<LocationTracker
tracking={this.state.tracking}
handleTrackingChange={this.handleTrackingChange.bind(this)}
/> />
)} </Fragment>
</Fragment> );
); return <Fragment>{items}</Fragment>;
} else return null;
} }
} }
const styles = StyleSheet.create({
picker: {
width: 200,
height: 100
}
});
export default GameList; export default GameList;
// {this.state.games.length > 0 && (
// <FlatList
// data={this.state.games}
// renderItem={({ item }) => <Button title={item.name} />}
// />
// )}
import React, { Fragment } from "react";
import { Switch, Text, StyleSheet } from "react-native";
const LocationTracker = props => {
return (
<Fragment>
<Text style={styles.titleText}>Tracking:</Text>
<Switch
style={styles.switch}
value={props.tracking}
onValueChange={props.handleTrackingChange}
/>
</Fragment>
);
};
const styles = StyleSheet.create({
switch: {},
titleText: {
fontSize: 40,
fontWeight: "bold",
textAlign: "center",
textAlignVertical: "center"
}
});
export default LocationTracker;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment