package component import ( "fmt" common "forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/common/component" "forge.cadoles.com/wpetit/kouiz/internal/store" "math" "strconv" ) type LeaderboardPageVModel struct { Player *store.Player Players []*store.Player PlayerRank int } templ LeaderboardPage(vmodel LeaderboardPageVModel) { @common.AppPage(common.WithPageOptions( common.WithTitle("Tableau des scores"), )) {

Podium

{{ podium := getPodium(vmodel.Players) }}
for i, p := range podium[1] { if i > 0 {
} { p.Name } }

if len(podium[1]) > 0 { { fmt.Sprintf("%d", podium[1][0].Score) }pts }
2ème

for i, p := range podium[0] { if i > 0 {
} { p.Name } }

if len(podium[0]) > 0 { { fmt.Sprintf("%d", podium[0][0].Score) }pts }
1er
for i, p := range podium[2] { if i > 0 {
} { p.Name } }

if len(podium[2]) > 0 { { fmt.Sprintf("%d", podium[2][0].Score) }pts }
3ème

Tableau des scores

for i, p := range vmodel.Players { }
Position Pseudonyme Score
{ strconv.FormatInt(int64(i+1), 10) } { p.Name } { strconv.FormatInt(int64(p.Score), 10) }
} } 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 }