Done V1
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
import { page } from "$app/state";
|
||||
import { error } from "@sveltejs/kit";
|
||||
import SimpleQuestionComponent from "$lib/SimpleQuestionComponent.svelte";
|
||||
import { isSimpleQuestion } from "$lib/games/games";
|
||||
import { isMultipleChoiceQuestion, isSimpleQuestion } from "$lib/games/games";
|
||||
import ws from "$lib/websocket.svelte";
|
||||
import { MessageType } from "$lib/MessageType";
|
||||
import { untrack } from "svelte";
|
||||
import MultipleChoiceQuestionComponent from "$lib/MultipleChoiceQuestionComponent.svelte";
|
||||
|
||||
console.log("wall:", page.params.wall);
|
||||
|
||||
@@ -58,6 +59,7 @@
|
||||
}
|
||||
|
||||
let showAnswer = $state(false);
|
||||
let showQuestion = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (ws.messageNum <= 0) return;
|
||||
@@ -67,6 +69,7 @@
|
||||
if (json.type == MessageType.SHOW_ANSWER) {
|
||||
ws.nextMessage();
|
||||
untrack(() => {
|
||||
showQuestion = true;
|
||||
showAnswer = true;
|
||||
});
|
||||
}
|
||||
@@ -76,6 +79,19 @@
|
||||
showAnswer = false;
|
||||
});
|
||||
}
|
||||
if (json.type == MessageType.SHOW_QUESTION) {
|
||||
ws.nextMessage();
|
||||
untrack(() => {
|
||||
showQuestion = true;
|
||||
});
|
||||
}
|
||||
if (json.type == MessageType.HIDE_QUESTION) {
|
||||
ws.nextMessage();
|
||||
untrack(() => {
|
||||
showQuestion = false;
|
||||
showAnswer = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
</script>
|
||||
@@ -91,9 +107,11 @@
|
||||
{#if question === undefined}
|
||||
<p>Question is undefined</p>
|
||||
{:else if isSimpleQuestion(question)}
|
||||
<SimpleQuestionComponent {question} {showAnswer} />
|
||||
<SimpleQuestionComponent {question} {showAnswer} {showQuestion} />
|
||||
{:else if isMultipleChoiceQuestion(question)}
|
||||
<MultipleChoiceQuestionComponent {question} {showAnswer} {showQuestion} />
|
||||
{:else}
|
||||
<p>Type of question unknown: {question.type}</p>
|
||||
<p>Type of question unknown</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user