feat: initial commit

This commit is contained in:
2025-06-16 00:07:03 +02:00
parent d93ed20869
commit a6d5cb50f2
26 changed files with 10870 additions and 156 deletions

View File

@ -0,0 +1,43 @@
package component
import (
"fmt"
common "forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/common/component"
"forge.cadoles.com/wpetit/kouiz/internal/store"
)
type HistoryPageVModel struct {
History []*store.QuizTurn
}
templ HistoryPage(vmodel HistoryPageVModel) {
@common.AppPage(common.WithPageOptions(
common.WithTitle("Historique"),
)) {
<h3 class="title">Historique</h3>
for _, turn := range vmodel.History {
<details>
<summary class="has-text-weight-bold is-clickable is-size-4">Tour #{ fmt.Sprintf("%d", turn.ID) }</summary>
<div class="pl-5">
for _, entry := range turn.Entries {
<details class="mt-3">
<summary class="has-text-weight-bold is-clickable is-size-5"><span>{ entry.Question }</span><span class="is-italic has-text-grey is-size-6">( { entry.Category.Theme } / { entry.Category.Name } / { store.DifficultyLevel(entry.Level) } )</span></summary>
<div class="content">
<ol class="mt-3">
for _, proposition := range entry.Propositions {
<li class={ templ.KV("has-text-success has-text-weight-bold", proposition == entry.Answer) }>{ proposition }</li>
}
</ol>
</div>
<div class="message is-small">
<div class="message-header">Le saviez vous ?</div>
<div class="message-body">{ entry.Anecdote }</div>
</div>
</details>
}
</div>
</details>
<hr/>
}
}
}

View File

@ -0,0 +1,205 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.819
package component
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
import (
"fmt"
common "forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/common/component"
"forge.cadoles.com/wpetit/kouiz/internal/store"
)
type HistoryPageVModel struct {
History []*store.QuizTurn
}
func HistoryPage(vmodel HistoryPageVModel) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<h3 class=\"title\">Historique</h3>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, turn := range vmodel.History {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<details><summary class=\"has-text-weight-bold is-clickable is-size-4\">Tour #")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", turn.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 20, Col: 99}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</summary><div class=\"pl-5\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, entry := range turn.Entries {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<details class=\"mt-3\"><summary class=\"has-text-weight-bold is-clickable is-size-5\"><span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Question)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 24, Col: 90}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span><span class=\"is-italic has-text-grey is-size-6\">( ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Category.Theme)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 24, Col: 172}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " / ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Category.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 24, Col: 198}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " / ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(store.DifficultyLevel(entry.Level))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 24, Col: 239}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " )</span></summary><div class=\"content\"><ol class=\"mt-3\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, proposition := range entry.Propositions {
var templ_7745c5c3_Var8 = []any{templ.KV("has-text-success has-text-weight-bold", proposition == entry.Answer)}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var8...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<li class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var8).String())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 1, Col: 0}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(proposition)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 28, Col: 116}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</ol></div><div class=\"message is-small\"><div class=\"message-header\">Le saviez vous ?</div><div class=\"message-body\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Anecdote)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/history_page.templ`, Line: 34, Col: 50}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</div></div></details>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</div></details><hr>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
return nil
})
templ_7745c5c3_Err = common.AppPage(common.WithPageOptions(
common.WithTitle("Historique"),
)).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate

View File

@ -4,6 +4,7 @@ import (
"fmt"
common "forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/common/component"
"forge.cadoles.com/wpetit/kouiz/internal/store"
"math"
"strconv"
)
@ -18,37 +19,59 @@ templ LeaderboardPage(vmodel LeaderboardPageVModel) {
common.WithTitle("Tableau des scores"),
)) {
<h3 class="title">Podium</h3>
{{ podium := getPodium(vmodel.Players) }}
<div class="podium">
<div class="podium-position podium-second">
if len(vmodel.Players) > 1 {
<div class="podium-player">
<span class="has-text-weight-bold is-uppercase">{ vmodel.Players[1].Name }</span>
<br/>
<span class="has-text-grey is-size-7">{ strconv.FormatInt(int64(vmodel.Players[1].Score), 10) }pts</span>
</div>
}
<div class="podium-player">
<span class="has-text-weight-bold is-uppercase">
for i, p := range podium[1] {
if i > 0 {
<br/>
}
<span>{ p.Name }</span>
}
</span>
<br/>
if len(podium[1]) > 0 {
<span class="has-text-grey is-size-7">{ fmt.Sprintf("%d", podium[1][0].Score) }pts</span>
}
</div>
<div class="podium-step">2ème</div>
</div>
<div class="podium-position podium-first">
if len(vmodel.Players) > 0 {
<div class="podium-player">
<span class="icon is-size-4 has-text-warning"><i class="fas fa-trophy"></i></span>
<br/>
<span class="has-text-weight-bold is-uppercase">{ vmodel.Players[0].Name }</span>
<br/>
<span class="has-text-grey is-size-7">{ strconv.FormatInt(int64(vmodel.Players[0].Score), 10) }pts</span>
</div>
}
<div class="podium-player">
<span class="icon is-size-4 has-text-warning"><i class="fas fa-trophy"></i></span>
<br/>
<span class="has-text-weight-bold is-uppercase">
for i, p := range podium[0] {
if i > 0 {
<br/>
}
<span>{ p.Name }</span>
}
</span>
<br/>
if len(podium[0]) > 0 {
<span class="has-text-grey is-size-7">{ fmt.Sprintf("%d", podium[0][0].Score) }pts</span>
}
</div>
<div class="podium-step">1er</div>
</div>
<div class="podium-position podium-third">
if len(vmodel.Players) > 2 {
<div class="podium-player">
<span class="has-text-weight-bold is-uppercase">{ vmodel.Players[2].Name }</span>
<br/>
<span class="has-text-grey is-size-7">{ strconv.FormatInt(int64(vmodel.Players[2].Score), 10) }pts</span>
</div>
}
<div class="podium-player">
<span class="has-text-weight-bold is-uppercase">
for i, p := range podium[2] {
if i > 0 {
<br/>
}
<span>{ p.Name }</span>
}
</span>
<br/>
if len(podium[2]) > 0 {
<span class="has-text-grey is-size-7">{ fmt.Sprintf("%d", podium[2][0].Score) }pts</span>
}
</div>
<div class="podium-step">3ème</div>
</div>
</div>
@ -127,3 +150,28 @@ templ LeaderboardPage(vmodel LeaderboardPageVModel) {
</style>
}
}
func getPodium(players []*store.Player) [][]*store.Player {
score := math.MaxInt
podium := make([][]*store.Player, 3)
podiumIndex := -1
for _, p := range players {
if p.Score < score {
score = p.Score
podiumIndex++
if podiumIndex > 2 {
break
}
podium[podiumIndex] = append(podium[podiumIndex], p)
continue
}
if p.Score == score {
podium[podiumIndex] = append(podium[podiumIndex], p)
continue
}
}
return podium
}

View File

@ -12,6 +12,7 @@ import (
"fmt"
common "forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/common/component"
"forge.cadoles.com/wpetit/kouiz/internal/store"
"math"
"strconv"
)
@ -54,187 +55,240 @@ func LeaderboardPage(vmodel LeaderboardPageVModel) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<h3 class=\"title\">Podium</h3><div class=\"podium\"><div class=\"podium-position podium-second\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<h3 class=\"title\">Podium</h3>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(vmodel.Players) > 1 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<div class=\"podium-player\"><span class=\"has-text-weight-bold is-uppercase\">")
podium := getPodium(vmodel.Players)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<div class=\"podium\"><div class=\"podium-position podium-second\"><div class=\"podium-player\"><span class=\"has-text-weight-bold is-uppercase\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for i, p := range podium[1] {
if i > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<br>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(vmodel.Players[1].Name)
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 25, Col: 78}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 31, Col: 21}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</span><br><span class=\"has-text-grey is-size-7\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</span><br>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(podium[1]) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<span class=\"has-text-grey is-size-7\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(vmodel.Players[1].Score), 10))
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", podium[1][0].Score))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 27, Col: 99}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 36, Col: 83}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "pts</span></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "pts</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<div class=\"podium-step\">2ème</div></div><div class=\"podium-position podium-first\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</div><div class=\"podium-step\">2ème</div></div><div class=\"podium-position podium-first\"><div class=\"podium-player\"><span class=\"icon is-size-4 has-text-warning\"><i class=\"fas fa-trophy\"></i></span><br><span class=\"has-text-weight-bold is-uppercase\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(vmodel.Players) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<div class=\"podium-player\"><span class=\"icon is-size-4 has-text-warning\"><i class=\"fas fa-trophy\"></i></span><br><span class=\"has-text-weight-bold is-uppercase\">")
for i, p := range podium[0] {
if i > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<br>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(vmodel.Players[0].Name)
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 37, Col: 78}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 50, Col: 21}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</span><br><span class=\"has-text-grey is-size-7\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</span><br>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(podium[0]) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<span class=\"has-text-grey is-size-7\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(vmodel.Players[0].Score), 10))
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", podium[0][0].Score))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 39, Col: 99}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 55, Col: 83}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "pts</span></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "pts</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<div class=\"podium-step\">1er</div></div><div class=\"podium-position podium-third\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</div><div class=\"podium-step\">1er</div></div><div class=\"podium-position podium-third\"><div class=\"podium-player\"><span class=\"has-text-weight-bold is-uppercase\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(vmodel.Players) > 2 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<div class=\"podium-player\"><span class=\"has-text-weight-bold is-uppercase\">")
for i, p := range podium[2] {
if i > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<br>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, " <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(vmodel.Players[2].Name)
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 47, Col: 78}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 67, Col: 21}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</span><br><span class=\"has-text-grey is-size-7\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</span><br>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(podium[2]) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<span class=\"has-text-grey is-size-7\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(vmodel.Players[2].Score), 10))
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", podium[2][0].Score))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 49, Col: 99}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 72, Col: 83}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "pts</span></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "pts</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<div class=\"podium-step\">3ème</div></div></div><h3 class=\"title mt-5\">Tableau des scores</h3><div class=\"table-container\"><table class=\"table is-fullwidth\"><thead><tr><th>Position</th><th>Pseudonyme</th><th>Score</th></tr></thead> <tbody>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</div><div class=\"podium-step\">3ème</div></div></div><h3 class=\"title mt-5\">Tableau des scores</h3><div class=\"table-container\"><table class=\"table is-fullwidth\"><thead><tr><th>Position</th><th>Pseudonyme</th><th>Score</th></tr></thead> <tbody>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for i, p := range vmodel.Players {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<tr")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<tr")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if p.ID == vmodel.Player.ID {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " class=\"has-text-weight-bold is-info\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, " class=\"has-text-weight-bold is-info\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, " id=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, " id=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("player-%d", p.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 71, Col: 42}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 94, Col: 42}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\"><td>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\"><td>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(i+1), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 73, Col: 46}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 96, Col: 46}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</td><td>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</td><td>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(p.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 74, Col: 19}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 97, Col: 19}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</td><td>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</td><td>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(p.Score), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 75, Col: 50}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/leaderboard_page.templ`, Line: 98, Col: 50}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</td></tr>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</td></tr>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</tbody></table></div><style>\n .podium {\n display: flex;\n flex-direction: row;\n align-items: flex-end;\n justify-content: center;\n gap: 10px;\n }\n\n .podium .podium-step {\n width: 100px;\n justify-content: center;\n align-items: center;\n display: flex;\n font-weight: bold;\n color: white;\n text-shadow: 1px 1px #333;\n }\n\n .podium .podium-position {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n }\n\n .podium .podium-player {\n text-shadow: none;\n color: #333;\n text-align: center;\n }\n\n .podium .podium-first .podium-step {\n height: 70px;\n background-color: hsl(141, 71%, 48%)\t;\n }\n\n .podium .podium-second .podium-step {\n height: 50px;\n background-color: hsl(204, 86%, 53%);\n }\n\n .podium .podium-third .podium-step {\n height: 30px;\n background-color: #66d1ff;\n }\n </style>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</tbody></table></div><style>\n .podium {\n display: flex;\n flex-direction: row;\n align-items: flex-end;\n justify-content: center;\n gap: 10px;\n }\n\n .podium .podium-step {\n width: 100px;\n justify-content: center;\n align-items: center;\n display: flex;\n font-weight: bold;\n color: white;\n text-shadow: 1px 1px #333;\n }\n\n .podium .podium-position {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n }\n\n .podium .podium-player {\n text-shadow: none;\n color: #333;\n text-align: center;\n }\n\n .podium .podium-first .podium-step {\n height: 70px;\n background-color: hsl(141, 71%, 48%)\t;\n }\n\n .podium .podium-second .podium-step {\n height: 50px;\n background-color: hsl(204, 86%, 53%);\n }\n\n .podium .podium-third .podium-step {\n height: 30px;\n background-color: #66d1ff;\n }\n </style>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -250,4 +304,29 @@ func LeaderboardPage(vmodel LeaderboardPageVModel) templ.Component {
})
}
func getPodium(players []*store.Player) [][]*store.Player {
score := math.MaxInt
podium := make([][]*store.Player, 3)
podiumIndex := -1
for _, p := range players {
if p.Score < score {
score = p.Score
podiumIndex++
if podiumIndex > 2 {
break
}
podium[podiumIndex] = append(podium[podiumIndex], p)
continue
}
if p.Score == score {
podium[podiumIndex] = append(podium[podiumIndex], p)
continue
}
}
return podium
}
var _ = templruntime.GeneratedTemplate

View File

@ -19,6 +19,7 @@ type QuizPageVModel struct {
Player *store.Player
CurrentTurn *store.QuizTurn
PlayDelay time.Duration
IsOffDay bool
}
func NewSelectEntryForm() *form.Form {
@ -46,10 +47,28 @@ templ QuizPage(vmodel QuizPageVModel) {
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.Second).String() }.</p>
if vmodel.IsOffDay {
<div class="message is-warning">
<div class="message-header">
<p>Jeu désactivé aujourd'hui</p>
</div>
<div class="message-body">
<div class="content">
<p>Désolé, le jeu est désactivé pour la journée. Revenez prochainement pour le prochain tour !</p>
</div>
</div>
</div>
} else if vmodel.Player.PlayedAt.After(vmodel.CurrentTurn.StartedAt) {
<div class="content has-text-centered is-size-5"></div>
<div class="message is-info">
<div class="message-header">
<p>En attente du prochain tour</p>
</div>
<div class="message-body">
<div class="content">
<p>Il commencera dans { vmodel.CurrentTurn.EndedAt.Local().Sub(time.Now().Local()).Round(time.Second).String() }.</p>
</div>
</div>
</div>
} else if vmodel.Player.SelectedEntry == nil || vmodel.Player.SelectedTurn == nil || *vmodel.Player.SelectedTurn != vmodel.CurrentTurn.ID {
@QuizQuestionSelector(vmodel)
@ -89,7 +108,7 @@ templ QuizQuestionSelector(vmodel QuizPageVModel) {
<div class="level-item">
<div class="content">
<p class="is-size-4 is-family-secondary has-text-right" style="width:300px">
<span></span> <span class="has-text-weight-bold">{ difficultyLevel(entry.Level) }</span>
<span></span> <span class="has-text-weight-bold">{ store.DifficultyLevel(entry.Level) }</span>
<br/>
<span>+{ strconv.FormatInt(int64((entry.Level+1)*2), 10) } points</span>
</p>
@ -158,19 +177,6 @@ templ QuizQuestion(vmodel QuizPageVModel) {
</script>
}
func difficultyLevel(level uint) string {
switch level {
case 0:
return "Débutant"
case 1:
return "Confirmé"
case 2:
return "Expert"
default:
return fmt.Sprintf("Hors catégorie (%d)", level)
}
}
func markdownToHTML(ctx context.Context, text string) string {
var buff bytes.Buffer
if err := goldmark.Convert([]byte(text), &buff); err != nil {

View File

@ -27,6 +27,7 @@ type QuizPageVModel struct {
Player *store.Player
CurrentTurn *store.QuizTurn
PlayDelay time.Duration
IsOffDay bool
}
func NewSelectEntryForm() *form.Form {
@ -89,7 +90,7 @@ func QuizPage(vmodel QuizPageVModel) templ.Component {
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatUint(uint64(vmodel.CurrentTurn.ID), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 48, Col: 91}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 49, Col: 91}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
@ -99,21 +100,26 @@ func QuizPage(vmodel QuizPageVModel) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if vmodel.Player.PlayedAt.After(vmodel.CurrentTurn.StartedAt) {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<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 ")
if vmodel.IsOffDay {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<div class=\"message is-warning\"><div class=\"message-header\"><p>Jeu désactivé aujourd'hui</p></div><div class=\"message-body\"><div class=\"content\"><p>Désolé, le jeu est désactivé pour la journée. Revenez prochainement pour le prochain tour !</p></div></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else if vmodel.Player.PlayedAt.After(vmodel.CurrentTurn.StartedAt) {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<div class=\"content has-text-centered is-size-5\"></div><div class=\"message is-info\"><div class=\"message-header\"><p>En attente du prochain tour</p></div><div class=\"message-body\"><div class=\"content\"><p>Il commencera dans ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(vmodel.CurrentTurn.EndedAt.Sub(time.Now().UTC()).Round(time.Second).String())
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(vmodel.CurrentTurn.EndedAt.Local().Sub(time.Now().Local()).Round(time.Second).String())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 52, Col: 118}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 69, Col: 116}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, ".</p></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, ".</p></div></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -161,7 +167,7 @@ func QuizQuestionSelector(vmodel QuizPageVModel) templ.Component {
templ_7745c5c3_Var5 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<form action=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<form action=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -170,108 +176,108 @@ func QuizQuestionSelector(vmodel QuizPageVModel) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" method=\"post\"><h3 class=\"title is-size-3\">Choisissez votre prochaine question</h3><div class=\"message is-info\"><div class=\"message-body\"><p><strong>Attention</strong>, une fois la thématique sélectionnée vous aurez <strong>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\" method=\"post\"><h3 class=\"title is-size-3\">Choisissez votre prochaine question</h3><div class=\"message is-info\"><div class=\"message-body\"><p><strong>Attention</strong>, une fois la thématique sélectionnée vous aurez <strong>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(vmodel.PlayDelay.String())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 68, Col: 118}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 87, Col: 118}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " pour répondre</strong>. Faites le bon choix !</p></div></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " pour répondre</strong>. Faites le bon choix !</p></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, entry := range vmodel.CurrentTurn.Entries {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<div class=\"box\"><div class=\"level mx-5\"><div class=\"level-left\"><div class=\"level-item\"><div class=\"content\"><p class=\"title\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<div class=\"box\"><div class=\"level mx-5\"><div class=\"level-left\"><div class=\"level-item\"><div class=\"content\"><p class=\"title\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Category.Theme)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 79, Col: 31}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 98, Col: 31}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</p><p class=\"subtitle\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</p><p class=\"subtitle\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Category.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 81, Col: 49}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 100, Col: 49}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</p><div class=\"content is-italic\"><p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</p><div class=\"content is-italic\"><p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Category.Description)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 83, Col: 40}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 102, Col: 40}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</p></div></div></div></div><div class=\"level-right\"><div class=\"level-item\"><div class=\"content\"><p class=\"is-size-4 is-family-secondary has-text-right\" style=\"width:300px\"><span></span> <span class=\"has-text-weight-bold\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</p></div></div></div></div><div class=\"level-right\"><div class=\"level-item\"><div class=\"content\"><p class=\"is-size-4 is-family-secondary has-text-right\" style=\"width:300px\"><span></span> <span class=\"has-text-weight-bold\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(difficultyLevel(entry.Level))
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(store.DifficultyLevel(entry.Level))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 92, Col: 88}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 111, Col: 94}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</span><br><span>+")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</span><br><span>+")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64((entry.Level+1)*2), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 94, Col: 65}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 113, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " points</span></p></div></div><div class=\"level-item\"><button class=\"button is-large ml-5\" name=\"entry\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, " points</span></p></div></div><div class=\"level-item\"><button class=\"button is-large ml-5\" name=\"entry\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(entry.ID), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 99, Col: 103}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 118, Col: 103}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\"><span class=\"icon\"><i class=\"fas fa-chevron-right\"></i></span></button></div></div></div></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\"><span class=\"icon\"><i class=\"fas fa-chevron-right\"></i></span></button></div></div></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</form>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</form>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -305,46 +311,46 @@ func QuizQuestion(vmodel QuizPageVModel) templ.Component {
return vmodel.Player.SelectedEntry != nil && *vmodel.Player.SelectedEntry == e.ID
})
selectedEntry := vmodel.CurrentTurn.Entries[selectedEntryIndex]
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<div class=\"content\"><p class=\"title is-size-3\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<div class=\"content\"><p class=\"title is-size-3\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(selectedEntry.Question)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 119, Col: 27}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 138, Col: 27}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</p><p class=\"subtitle\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</p><p class=\"subtitle\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(selectedEntry.Category.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 121, Col: 51}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 140, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, " - ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " - ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(selectedEntry.Category.Theme)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 121, Col: 86}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 140, Col: 86}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</p></div><form action=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</p></div><form action=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -353,87 +359,87 @@ func QuizQuestion(vmodel QuizPageVModel) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\" method=\"post\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\" method=\"post\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for index, proposition := range selectedEntry.Propositions {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<div class=\"box\"><div class=\"level\"><div class=\"level-left\"><div class=\"level-item\"><div class=\"content\"><p class=\"has-font-weight-bold is-size-4\"><span class=\"has-text-grey\t\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "<div class=\"box\"><div class=\"level\"><div class=\"level-left\"><div class=\"level-item\"><div class=\"content\"><p class=\"has-font-weight-bold is-size-4\"><span class=\"has-text-grey\t\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var19 string
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(index), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 131, Col: 75}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 150, Col: 75}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, ".</span> <span class=\"is-family-secondary\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, ".</span> <span class=\"is-family-secondary\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var20 string
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(proposition)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 131, Col: 133}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 150, Col: 133}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</span></p></div></div></div><div class=\"level-right\"><div class=\"level-item\"><button class=\"button is-large ml-5\" name=\"answer\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</span></p></div></div></div><div class=\"level-right\"><div class=\"level-item\"><button class=\"button is-large ml-5\" name=\"answer\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var21 string
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(index), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 138, Col: 101}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 157, Col: 101}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "\"><span class=\"icon\"><i class=\"fas fa-chevron-right\"></i></span></button></div></div></div></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "\"><span class=\"icon\"><i class=\"fas fa-chevron-right\"></i></span></button></div></div></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</form>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</form>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
remainingSeconds := vmodel.Player.SelectedAt.Add(vmodel.PlayDelay).Sub(time.Now().UTC()).Seconds()
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<progress id=\"question-timer\" class=\"progress is-info is-small mt-5\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "<progress id=\"question-timer\" class=\"progress is-info is-small mt-5\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var22 string
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(remainingSeconds), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 148, Col: 124}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 167, Col: 124}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\" max=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\" max=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var23 string
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatInt(int64(remainingSeconds), 10))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 148, Col: 179}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/quiz/component/quiz_page.templ`, Line: 167, Col: 179}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\"></progress><script>\n\t\t(function(){\n\t\t\tconst element = document.getElementById(\"question-timer\")\n\t\t\tconst updateProgress = () => {\n\t\t\t\telement.value = parseInt(element.value)-1;\n\t\t\t\tsetTimeout(updateProgress, 1000);\n\t\t\t};\n\t\t\tsetTimeout(updateProgress, 1000);\n\t\t}());\n\t</script>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\"></progress><script>\n\t\t(function(){\n\t\t\tconst element = document.getElementById(\"question-timer\")\n\t\t\tconst updateProgress = () => {\n\t\t\t\telement.value = parseInt(element.value)-1;\n\t\t\t\tsetTimeout(updateProgress, 1000);\n\t\t\t};\n\t\t\tsetTimeout(updateProgress, 1000);\n\t\t}());\n\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -441,19 +447,6 @@ func QuizQuestion(vmodel QuizPageVModel) templ.Component {
})
}
func difficultyLevel(level uint) string {
switch level {
case 0:
return "Débutant"
case 1:
return "Confirmé"
case 2:
return "Expert"
default:
return fmt.Sprintf("Hors catégorie (%d)", level)
}
}
func markdownToHTML(ctx context.Context, text string) string {
var buff bytes.Buffer
if err := goldmark.Convert([]byte(text), &buff); err != nil {