Template
feat : lobby
This commit is contained in:
+3
-15
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user