Skip to content

Commit d428cab

Browse files
committed
add loading to laboratory
1 parent c61d436 commit d428cab

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

frontend/src/components/SinglePlayer.vue

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<div class="w-full">
3-
<div class="flex items-center justify-center h-full" v-if="!isMatchRunning">
3+
<div class="flex items-center justify-center h-128" style="height: 50%" v-if="starting">
4+
<Loading />
5+
</div>
6+
<div class="flex items-center justify-center h-full" v-else-if="!isMatchRunning">
47
<button class="button" @click="startTestGame()">
58
{{ $t("laboratory.start-test-game") }}
69
</button>
@@ -19,10 +22,12 @@ import currUser from '../lib/User';
1922
import Game from '../game/Game.vue';
2023
import RoomConnection from '../lib/RoomConnection';
2124
import StopStatsModal, { StopStatsInterface } from './StopStatsModal.vue';
25+
import Loading from './Loading.vue';
2226
2327
@Component({
2428
components: {
2529
Game,
30+
Loading,
2631
StopStatsModal,
2732
},
2833
props: {
@@ -33,6 +38,7 @@ import StopStatsModal, { StopStatsInterface } from './StopStatsModal.vue';
3338
const isMatchRunning = ref(false);
3439
const roomConn = new RoomConnection(currUserId as string);
3540
const stopStats = ref<StopStatsInterface | null>();
41+
const starting = ref(false);
3642
3743
const handleMessage = (type: WsMessageType, payload: any) => {
3844
switch (type) {
@@ -62,6 +68,8 @@ import StopStatsModal, { StopStatsInterface } from './StopStatsModal.vue';
6268
};
6369
}),
6470
};
71+
} else {
72+
starting.value = false;
6573
}
6674
break;
6775
}
@@ -76,26 +84,29 @@ import StopStatsModal, { StopStatsInterface } from './StopStatsModal.vue';
7684
onUnmounted(() => roomConn.disconnect());
7785
7886
const startTestGame = async () => {
87+
starting.value = true;
88+
7989
await props.onStart();
8090
if (!roomConn.ws) {
8191
await roomConn.connect();
82-
await new Promise((resolve) => setTimeout(resolve, 50));
92+
await new Promise((resolve) => setTimeout(resolve, 300));
8393
}
8494
await roomConn.send(WsMessageType.GAME_JOIN);
85-
await new Promise((resolve) => setTimeout(resolve, 50));
95+
await new Promise((resolve) => setTimeout(resolve, 300));
8696
await roomConn.send(WsMessageType.GAME_ACCEPT);
8797
};
8898
8999
return {
90100
currUserId,
91101
isMatchRunning,
92102
roomConn,
103+
starting,
93104
startTestGame,
94105
stopStats,
95106
};
96107
},
97108
})
98-
export default class SinglePlayer extends Vue {}
109+
export default class SinglePlayer extends Vue { }
99110
</script>
100111

101112
<style lang="postcss">

0 commit comments

Comments
 (0)