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

@ -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
}