feat/FRO-31: Added ingame (#20)
Force push of Janis ingame changes Co-authored-by: Janis <janis.e.20@gmx.de> Reviewed-on: #20
This commit is contained in:
@@ -1,19 +1,40 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import {ref, type Ref} from 'vue'
|
||||
import axios from "axios";
|
||||
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
|
||||
export const useUserInfo = defineStore('userInfo', () => {
|
||||
const username: Ref<string | null> = ref(null);
|
||||
const userId: Ref<number | null> = ref(null);
|
||||
const gameId: Ref<string | null> = ref(null);
|
||||
|
||||
function setUserInfo(name: string, id: number) {
|
||||
username.value = name;
|
||||
userId.value = id;
|
||||
}
|
||||
|
||||
function setGameId(id: string) {
|
||||
gameId.value = id;
|
||||
}
|
||||
|
||||
function requestState() {
|
||||
axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
|
||||
username.value = response.data.username;
|
||||
if (response.data.ingame) {
|
||||
gameId.value = response.data.gameId;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function clearUserInfo() {
|
||||
username.value = null;
|
||||
userId.value = null;
|
||||
}
|
||||
|
||||
return { username, userId, setUserInfo, clearUserInfo };
|
||||
function clearGameId() {
|
||||
gameId.value = null;
|
||||
}
|
||||
|
||||
return { username, userId, gameId, setUserInfo, requestState, clearUserInfo, setGameId, clearGameId };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user