feat: Enhance user state management with polling and WebSocket connection handling
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {ref} from "vue";
|
||||
import {ref, onUnmounted} from "vue";
|
||||
import { useRouter } from 'vue-router';
|
||||
import {useQuasar} from "quasar";
|
||||
import axios from "axios";
|
||||
import {useUserInfo} from "@/composables/useUserInfo";
|
||||
const router = useRouter();
|
||||
const info = useUserInfo();
|
||||
const lobbyCode = ref('');
|
||||
const isLoading = ref(false);
|
||||
const $q = useQuasar();
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
|
||||
let pollInterval: number | null = null;
|
||||
|
||||
onUnmounted(() => {
|
||||
if (pollInterval) {
|
||||
clearInterval(pollInterval);
|
||||
}
|
||||
});
|
||||
|
||||
const startGameQuasar = async() => {
|
||||
if (!lobbyCode.value) {
|
||||
$q.notify({ message: 'Lobby-Name wird benötigt', color: 'red', position: 'top', icon: 'cancel' });
|
||||
@@ -21,7 +32,18 @@ const startGameQuasar = async() => {
|
||||
icon: 'check_circle',
|
||||
position: 'top'
|
||||
});
|
||||
router.replace("/game")
|
||||
|
||||
// Start polling until gameId is set
|
||||
pollInterval = window.setInterval(async () => {
|
||||
await info.requestState();
|
||||
if (info.gameId) {
|
||||
if (pollInterval) {
|
||||
clearInterval(pollInterval);
|
||||
pollInterval = null;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
|
||||
}).catch(() => {
|
||||
$q.notify({
|
||||
message: `Lobby "${lobbyCode.value}" nicht gefunden`,
|
||||
@@ -29,9 +51,8 @@ const startGameQuasar = async() => {
|
||||
icon: 'cancel',
|
||||
position: 'top'
|
||||
})
|
||||
}).finally(() =>
|
||||
isLoading.value = false
|
||||
)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user