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

Working on tracking, still WIP

parent 777185ac
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,18 @@ class GameList extends Component {
constructor(props) {
super(props);
this.state = {
factions: [],
games: [],
tracking: false,
selectedGame: null,
editForm: false
selectedFaction: null,
editForm: false,
userLocation: {
latitude: null,
longitude: null,
latitudeDelta: null,
longitudeDelta: null
}
};
intervalID = 0; // Used for starting and stopping the tracking ticks
......@@ -22,7 +30,7 @@ class GameList extends Component {
// Get all the games from the server and set the state to the first game
getGames() {
fetch("http://172.20.2.110:5000/game/listgames")
fetch("https://tacs-testing.cf:8443/game/listgames")
.then(response => response.json())
.then(games => {
this.setState({
......@@ -34,6 +42,28 @@ class GameList extends Component {
console.log(error);
});
}
getFactions() {
fetch(`https://tacs-testing.cf:8443/game/${this.state.selectedGame.id}`),
{
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
}
.then(response => response.json())
.then(factions => {
console.log(factions);
// this.setState({
// factions,
// selectedFaction: factions[0]
// });
})
.catch(error => {
console.log(error);
});
}
joinFaction() {}
// Toggles the tracking boolean
handleTrackingChange() {
this.setState({ tracking: !this.state.tracking });
......@@ -46,6 +76,28 @@ class GameList extends Component {
console.log(
"Nyt träkätää nim birusti peliä: " + this.state.selectedGame.name
);
fetch(
`https:/tacs-testing.cf:8443/tracking/location/${
this.state.selectedGame.id
}`,
{
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({})
}
)
.then(res => res.json())
.then(
result => {
console.log(result);
},
error => {
console.log(error);
}
);
console.log("Tracking: " + this.state.tracking);
}, interval);
}
......@@ -64,6 +116,40 @@ class GameList extends Component {
this.stopTracking();
}
}
// When you select a game with the picker, clears the tracking interval and gets the factions of the game
selectGame = (selectedGame, itemIndex) => {
this.getFactions();
clearInterval(this.intervalID);
this.setState({ selectedGame, tracking: false });
};
// When you select a faction, it asks you for a password, which is then sent to the server
selectFaction = (selectedFaction, itemIndex) => {
this.joinFaction();
clearInterval(this.intervalID);
this.setState({ selectedFaction, tracking: false });
};
//Getting the user location and storing it in the state
getCurrentLocation = () => {
const options = {
enableHighAccuracy: true,
timeout: 30000,
maximumAge: 0
};
navigator.geolocation.getCurrentPosition(
position => {
this.setState({
userLocation: {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: 0.0522,
longitudeDelta: 0.0421
}
});
},
err => console.log(err),
options
);
};
// Stop tracking on Unmount
componentWillUnmount() {
......@@ -76,15 +162,24 @@ class GameList extends Component {
<Picker
style={styles.picker}
selectedValue={this.state.selectedGame}
onValueChange={(selectedGame, itemIndex) => {
clearInterval(this.intervalID);
this.setState({ selectedGame, tracking: false });
}}
onValueChange={this.selectGame}
>
{this.state.games.map(game => (
<Picker.Item label={game.name} value={game} />
))}
</Picker>
{this.state.selectedGame && (
<Picker
style={styles.picker}
selectedValue={this.state.selectedFaction}
onValueChange={this.selectFaction}
>
{this.state.factions.map(faction => (
<Picker.Item label={faction.name} value={faction} />
))}
</Picker>
)}
<LocationTracker
tracking={this.state.tracking}
handleTrackingChange={this.handleTrackingChange.bind(this)}
......
......@@ -40,7 +40,7 @@ class Login extends Component {
componentDidMount() {
let token = this.loadToken();
if (token) {
fetch(`http://172.20.2.110:5000/user/verify`, {
fetch("https:/tacs-testing.cf:8443/user/verify", {
headers: {
Authorization: "Bearer " + token
}
......
......@@ -27,7 +27,7 @@ export class LoginForm extends React.Component {
e.preventDefault();
// Send login info to the server
fetch(`http://172.20.2.110:5000/user/login`, {
fetch("https:/tacs-testing.cf:8443/user/login", {
method: "POST",
headers: {
Accept: "application/json",
......
......@@ -13,7 +13,7 @@ export class RegisterForm extends React.Component {
registered: false
};
this.handleRegister = this.handleRegister.bind(this);
//this.handleRegister = this.handleRegister.bind(this);
}
// shows error messages associated with registering
......@@ -39,7 +39,7 @@ export class RegisterForm extends React.Component {
this.handleError("Passwords do not match");
} else {
// Send register info to the server
fetch(`http://172.20.2.110:5000/user/register`, {
fetch("https:/tacs-testing.cf:8443/user/register", {
method: "POST",
headers: {
Accept: "application/json",
......
......@@ -20,5 +20,10 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
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