Commit 5ee521d2 authored by quentin.vrel's avatar quentin.vrel

lobby handles actual data

parent c45159f1
<template>
<div class="lobby">
<user-ribbon class="lobby-ribbon" username="Josie Péritel"/>
<user-ribbon class="lobby-ribbon" :username="this.user.login" :pathToImage="this.user.avatar"/>
<div class="lobby-content">
<div class="lobby-column">
<page-title pagetitle="Parties"/>
......@@ -33,7 +33,7 @@ import UserRibbon from '@/components/UserRibbon.vue'
import PageTitle from '@/components/PageTitle.vue'
import ButtonText from '@/components/ButtonText.vue'
import TextInput from '@/components/form/TextInput.vue'
import User from '@/model/user.js'
export default {
name: 'lobby',
......@@ -44,12 +44,24 @@ export default {
TextInput
},
methods: {
getUserInfo: async function(){
let userJson = JSON.parse(localStorage.getItem('user'));
let user = new User(userJson.id_user, userJson.id_role, userJson.login, userJson.avatar, userJson.lastname, userJson.firstname, userJson.mail);
let token = userJson.jwt_token;
this.user = user;
this.token = token;
},
updateGames: async function(){
let response = await fetch(this.$apiRoot+'/game/public', {method: 'GET'});
if (response.ok){
let json = await response.json();
this.games=json;
}
const head = new Headers();
head.append('Authorization', 'bearer '+this.token);
await fetch(this.$apiRoot+'/game/public', {method: 'GET', headers: head})
.then(response => response.json())
.then(json => this.games = json)
.catch(() => {
alert("Votre session a expiré");
this.$router.push("/");
});
},
/*
* using the id of the hovered button, highlight (id>0) or set back to default style (id=0) the relevant button
......@@ -75,7 +87,7 @@ export default {
onSubmitMenu: function(){
if (event.submitter.id=='profile') {
this.$router.push('profile');
this.$router.push('profile/'+this.user.id_user);
}
if (event.submitter.id=='new') {
this.$router.push('new');
......@@ -92,19 +104,28 @@ export default {
},
data () {
return {
games: [
{
"ID_GAME": "2",
"NB_PLAYER": "1",
"LOGIN": "admin"
}
]
user: [],
token: '',
games: []
}
},
mounted () {
beforeCreate () {
if (localStorage.getItem('user') == null) {
alert('Vous devez être connecté');
this.$router.push('/');
}
},
created () {
this.getUserInfo();
this.handle = setInterval(this.updateGames, 1000)
},
destroyed () {
clearInterval(this.handle);
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment