feat: initial commit

This commit is contained in:
2025-06-15 16:44:44 +02:00
parent c50d1858f2
commit 21b334bc70
27 changed files with 13550 additions and 122 deletions

View File

@ -18,6 +18,7 @@ import (
type QuizPageVModel struct {
Player *store.Player
CurrentTurn *store.QuizTurn
PlayDelay time.Duration
}
func NewSelectEntryForm() *form.Form {
@ -42,13 +43,13 @@ func NewAnswerForm() *form.Form {
templ QuizPage(vmodel QuizPageVModel) {
@common.AppPage(common.WithPageOptions(
common.WithTitle("Quiz"),
common.WithTitle(fmt.Sprintf("Tour #%d", vmodel.CurrentTurn.ID)),
)) {
<h2 class="title is-size-3">Tour #{ strconv.FormatUint(uint64(vmodel.CurrentTurn.ID), 10) }</h2>
if vmodel.Player.PlayedAt.After(vmodel.CurrentTurn.StartedAt) {
<div class="content has-text-centered is-size-5">
<p><strong>Vous avez déjà joué ce tour ci !</strong></p>
<p>Le prochain tour commencera dans { vmodel.CurrentTurn.EndedAt.Sub(time.Now().UTC()).Round(time.Minute).String() }.</p>
<p>Le prochain tour commencera dans { vmodel.CurrentTurn.EndedAt.Sub(time.Now().UTC()).Round(time.Second).String() }.</p>
</div>
} else if vmodel.Player.SelectedEntry == nil || vmodel.Player.SelectedTurn == nil || *vmodel.Player.SelectedTurn != vmodel.CurrentTurn.ID {
@QuizQuestionSelector(vmodel)
@ -64,7 +65,7 @@ templ QuizQuestionSelector(vmodel QuizPageVModel) {
<div class="message is-info">
<div class="message-body">
<p>
<strong>Attention</strong>, une fois la thématique sélectionnée vous aurez <strong>30 secondes pour répondre</strong>. Faites le bon choix !
<strong>Attention</strong>, une fois la thématique sélectionnée vous aurez <strong>{ vmodel.PlayDelay.String() } pour répondre</strong>. Faites le bon choix !
</p>
</div>
</div>
@ -143,6 +144,18 @@ templ QuizQuestion(vmodel QuizPageVModel) {
</div>
}
</form>
{{ remainingSeconds := vmodel.Player.SelectedAt.Add(vmodel.PlayDelay).Sub(time.Now().UTC()).Seconds() }}
<progress id="question-timer" class="progress is-info is-small mt-5" value={ strconv.FormatInt(int64(remainingSeconds), 10) } max={ strconv.FormatInt(int64(remainingSeconds), 10) }></progress>
<script>
(function(){
const element = document.getElementById("question-timer")
const updateProgress = () => {
element.value = parseInt(element.value)-1;
setTimeout(updateProgress, 1000);
};
setTimeout(updateProgress, 1000);
}());
</script>
}
func difficultyLevel(level uint) string {