Can ask questions during live sessions

This commit is contained in:
nemunaire 2022-03-01 15:26:30 +01:00
commit fe79033d51
5 changed files with 264 additions and 2 deletions

View file

@ -91,6 +91,36 @@
});
}
}
let myQuestion = "";
let submitQuestionInProgress = false;
function askQuestion() {
if (!myQuestion) {
ToastsStore.addErrorToast({
msg: "Quel est ta question ?",
});
return;
}
submitQuestionInProgress = true;
fetch(`api/surveys/${survey.id}/ask`, {
method: 'POST',
headers: {'Accept': 'application/json'},
body: JSON.stringify({"content": myQuestion}),
}).then((r) => {
submitQuestionInProgress = false;
myQuestion = "";
ToastsStore.addToast({
msg: "Ta question a bien été envoyée.",
title: survey.title,
color: "success",
});
}, (error) => {
ToastsStore.addErrorToast({
msg: "Un problème est survenu : " + error.errmsg,
});
});
}
</script>
{#await surveyP then survey}
@ -139,9 +169,36 @@
{/if}
{/await}
{:else if ws_up}
<h2 class="text-center">
Pas de question actuellement
<h2 class="text-center mb-4">
Pas de question actuellement.
</h2>
<form on:submit|preventDefault={askQuestion}>
<h3 class="text-center text-muted mb-3"><label for="askquestion">Vous avez une question&nbsp;?</label></h3>
<div class="row">
<div class="offset-md-1 col-md-10 offset-lg-2 col-lg-8 offset-xl-3 col-xl-6">
<textarea
id="askquestion"
class="form-control"
bind:value={myQuestion}
autofocus
placeholder="Remarques, soucis, choses pas claire ? Demandez !"
></textarea>
</div>
</div>
{#if myQuestion}
<div class="text-center mt-2">
<button
class="btn btn-primary"
disabled={submitQuestionInProgress}
>
{#if submitQuestionInProgress}
<div class="spinner-border spinner-border-sm me-1" role="status"></div>
{/if}
Poser cette question
</button>
</div>
{/if}
</form>
{:else}
<h2 class="text-center">
La session est terminée. <small class="text-muted">On se retrouve une prochaine fois&hellip;</small>