feat : lobby

This commit is contained in:
2024-12-29 23:39:15 +01:00
parent e0ece631d3
commit d92739bbd6
14 changed files with 313 additions and 203 deletions
+3 -15
View File
@@ -1,6 +1,4 @@
<script setup lang="ts">
import { subscribe } from "~/netcode";
import { handlers } from "~/netcode/handlers/word.handler";
import { useWordStore } from "~/store/word.store";
const newWord = ref("");
@@ -11,7 +9,7 @@ await wordStore.fetchWordList();
const loading = ref(false);
const wordInput = ref<HTMLInputElement | null>(null);
async function createWord(e: Event) {
async function createWord() {
if (loading.value) {
return;
}
@@ -29,22 +27,12 @@ async function createWord(e: Event) {
}
}
let eventSource: EventSource;
onBeforeMount(() => {
eventSource = subscribe(`/words/subscribe`);
eventSource.addEventListener("message", async (message) => {
const data = JSON.parse(message.data);
const type = data.type as string;
if (type in handlers) {
handlers[type as keyof typeof handlers](data);
}
});
wordStore.subscribe();
});
onUnmounted(() => {
if (eventSource) {
eventSource.close();
}
wordStore.close();
});
</script>