feat: Enhance user state management with polling and WebSocket connection handling
This commit is contained in:
@@ -3,6 +3,7 @@ import { ref } from 'vue';
|
||||
import { useQuasar } from 'quasar';
|
||||
import { useRouter } from 'vue-router';
|
||||
import axios from "axios";
|
||||
import {useUserInfo} from "@/composables/useUserInfo";
|
||||
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
const lobbyName = ref('');
|
||||
@@ -11,13 +12,14 @@ const playerAmount = ref(2);
|
||||
const $q = useQuasar();
|
||||
const isLoading = ref(false);
|
||||
const router = useRouter();
|
||||
const info = useUserInfo();
|
||||
const createGameQuasar = async () => {
|
||||
if (!lobbyName.value) {
|
||||
$q.notify({ message: 'Lobby-Name wird benötigt', color: 'red', position: 'top', icon: 'cancel' });
|
||||
return;
|
||||
}
|
||||
isLoading.value = true;
|
||||
axios.post(`${api}/createGame`, {lobbyname: lobbyName.value, playeramount: playerAmount.value.toString()}, {withCredentials: true}).then((response) => {
|
||||
axios.post(`${api}/createGame`, {lobbyname: lobbyName.value, playeramount: playerAmount.value.toString()}, {withCredentials: true}).then(async (response) => {
|
||||
const responseData = response.data
|
||||
console.log("Response" + responseData.status)
|
||||
$q.notify({
|
||||
@@ -26,12 +28,12 @@ const createGameQuasar = async () => {
|
||||
icon: 'check_circle',
|
||||
position: 'top'
|
||||
});
|
||||
await info.requestState();
|
||||
router.replace("/game")
|
||||
}).catch((err) => {
|
||||
console.log("ERROR:" + err)
|
||||
}).finally(() =>
|
||||
isLoading.value = false
|
||||
)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user