1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: case sensitivity with leaderboard languages (resolve #418)

This commit is contained in:
Ferdinand Mütsch 2022-10-07 08:58:51 +02:00
parent 1e9d3f9e80
commit bc99dc990a
4 changed files with 8 additions and 7 deletions

View File

@ -45,10 +45,11 @@ func (l Leaderboard) TopKeys(by uint8) []string {
if item.Key == nil || item.By == nil || *item.By != by { if item.Key == nil || item.By == nil || *item.By != by {
continue continue
} }
if _, ok := totalsMapped[*item.Key]; !ok { key := strings.ToLower(*item.Key)
totalsMapped[*item.Key] = &keyTotal{Key: *item.Key, Total: 0} if _, ok := totalsMapped[key]; !ok {
totalsMapped[key] = &keyTotal{Key: *item.Key, Total: 0}
} }
totalsMapped[*item.Key].Total += item.Total totalsMapped[key].Total += item.Total
} }
totals := slice.Map[*keyTotal, keyTotal](maputil.Values[string, *keyTotal](totalsMapped), func(i int, item *keyTotal) keyTotal { totals := slice.Map[*keyTotal, keyTotal](maputil.Values[string, *keyTotal](totalsMapped), func(i int, item *keyTotal) keyTotal {

View File

@ -47,7 +47,6 @@ func (s *LeaderboardViewModel) ColorModifier(item *models.LeaderboardItem, princ
func (s *LeaderboardViewModel) LangIcon(lang string) string { func (s *LeaderboardViewModel) LangIcon(lang string) string {
// https://icon-sets.iconify.design/mdi/ // https://icon-sets.iconify.design/mdi/
langs := map[string]string{ langs := map[string]string{
"c": "c",
"c++": "cpp", "c++": "cpp",
"cpp": "cpp", "cpp": "cpp",
"go": "go", "go": "go",

View File

@ -87,8 +87,9 @@ func (h *LeaderboardHandler) buildViewModel(r *http.Request) *view.LeaderboardVi
topKeys = leaderboard.TopKeys(by) topKeys = leaderboard.TopKeys(by)
if len(topKeys) > 0 { if len(topKeys) > 0 {
if keyParam == "" { if keyParam == "" {
keyParam = strings.ToLower(topKeys[0]) keyParam = topKeys[0]
} }
keyParam = strings.ToLower(keyParam)
leaderboard = leaderboard.TopByKey(by, keyParam) leaderboard = leaderboard.TopByKey(by, keyParam)
} }
} else { } else {

View File

@ -23,7 +23,7 @@
<h1 class="h1" style="margin-bottom: 0.5rem">Leaderboard</h1> <h1 class="h1" style="margin-bottom: 0.5rem">Leaderboard</h1>
<p class="block text-sm text-gray-300 w-full lg:w-3/4 mb-8"> <p class="block text-sm text-gray-300 w-full lg:w-3/4 mb-8">
Wakapi's leaderboard shows a ranking of the most active users on this servers, given they opted in to get listed on the public leaderboard. Statistics are updated at least every 12 hours and are based on the users' total coding time in the past seven days. Wakapi's leaderboard shows a ranking of the most active users on this server, given they opted in to get listed on the public leaderboard. Statistics are updated at least every 12 hours and are based on the users' total coding time in the past seven days.
To participate, log in, go to <a class="link" href="settings#permissions">Settings 🠒 Permissions</a> and enable leaderboards. To participate, log in, go to <a class="link" href="settings#permissions">Settings 🠒 Permissions</a> and enable leaderboards.
</p> </p>
@ -40,7 +40,7 @@
<div class="flex flex-wrap space-x-2 mb-4"> <div class="flex flex-wrap space-x-2 mb-4">
{{ range $i, $key := (strslice .TopKeys 0 10) }} {{ range $i, $key := (strslice .TopKeys 0 10) }}
<div class="inline-block mb-4"> <div class="inline-block mb-4">
<a href="leaderboard?by={{ $.By }}&key={{ $key }}" class="{{ if eq $.Key (lower $key) }} btn-primary {{ else }} btn-default {{ end }} btn-small cursor-pointer whitespace-nowrap"> <a href="leaderboard?by={{ $.By }}&key={{ lower $key }}" class="{{ if eq (lower $.Key) (lower $key) }} btn-primary {{ else }} btn-default {{ end }} btn-small cursor-pointer whitespace-nowrap">
{{ if and (eq (lower $.By) "language") ($.LangIcon $key) }} {{ if and (eq (lower $.By) "language") ($.LangIcon $key) }}
<span class="align-middle leading-none"><span class="iconify inline text-white text-base" data-icon="{{ ($.LangIcon $key) | urlSafe }}"></span>&nbsp;</span> <span class="align-middle leading-none"><span class="iconify inline text-white text-base" data-icon="{{ ($.LangIcon $key) | urlSafe }}"></span>&nbsp;</span>
{{ end }} {{ end }}