mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
feat: top languages by user
This commit is contained in:
parent
a27fe04919
commit
7a07c9d4fc
@ -3,14 +3,15 @@ package view
|
||||
import "github.com/muety/wakapi/models"
|
||||
|
||||
type LeaderboardViewModel struct {
|
||||
User *models.User
|
||||
By string
|
||||
Key string
|
||||
Items []*models.LeaderboardItem
|
||||
TopKeys []string
|
||||
ApiKey string
|
||||
Success string
|
||||
Error string
|
||||
User *models.User
|
||||
By string
|
||||
Key string
|
||||
Items []*models.LeaderboardItem
|
||||
TopKeys []string
|
||||
UserLanguages map[string][]string
|
||||
ApiKey string
|
||||
Success string
|
||||
Error string
|
||||
}
|
||||
|
||||
func (s *LeaderboardViewModel) WithSuccess(m string) *LeaderboardViewModel {
|
||||
|
@ -2,6 +2,7 @@ package routes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
"github.com/emvi/logbuch"
|
||||
"github.com/gorilla/mux"
|
||||
conf "github.com/muety/wakapi/config"
|
||||
@ -58,6 +59,7 @@ func (h *LeaderboardHandler) buildViewModel(r *http.Request) *view.LeaderboardVi
|
||||
|
||||
var err error
|
||||
var leaderboard models.Leaderboard
|
||||
var userLanguages map[string][]string
|
||||
var topKeys []string
|
||||
|
||||
if byParam == "" {
|
||||
@ -74,6 +76,14 @@ func (h *LeaderboardHandler) buildViewModel(r *http.Request) *view.LeaderboardVi
|
||||
return &view.LeaderboardViewModel{Error: criticalError}
|
||||
}
|
||||
|
||||
userLeaderboards := slice.GroupWith[*models.LeaderboardItem, string](leaderboard, func(item *models.LeaderboardItem) string {
|
||||
return item.UserID
|
||||
})
|
||||
userLanguages = map[string][]string{}
|
||||
for u, items := range userLeaderboards {
|
||||
userLanguages[u] = models.Leaderboard(items).TopKeysByUser(models.SummaryLanguage, u)
|
||||
}
|
||||
|
||||
topKeys = leaderboard.TopKeys(by)
|
||||
if len(topKeys) > 0 {
|
||||
if keyParam == "" {
|
||||
@ -92,13 +102,14 @@ func (h *LeaderboardHandler) buildViewModel(r *http.Request) *view.LeaderboardVi
|
||||
}
|
||||
|
||||
return &view.LeaderboardViewModel{
|
||||
User: user,
|
||||
By: byParam,
|
||||
Key: keyParam,
|
||||
Items: leaderboard,
|
||||
TopKeys: topKeys,
|
||||
ApiKey: apiKey,
|
||||
Success: r.URL.Query().Get("success"),
|
||||
Error: r.URL.Query().Get("error"),
|
||||
User: user,
|
||||
By: byParam,
|
||||
Key: keyParam,
|
||||
Items: leaderboard,
|
||||
UserLanguages: userLanguages,
|
||||
TopKeys: topKeys,
|
||||
ApiKey: apiKey,
|
||||
Success: r.URL.Query().Get("success"),
|
||||
Error: r.URL.Query().Get("error"),
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -47,8 +47,8 @@
|
||||
<ol>
|
||||
{{ range $i, $item := .Items }}
|
||||
<li class="px-4 py-2 my-2 rounded-md border-2 leaderboard-{{ ($.ColorModifier $item $.User) }} flex justify-between">
|
||||
<div class="w-2/12"><strong># {{ $item.Rank }}</strong></div>
|
||||
<div class="flex w-1/2 items-center space-x-4">
|
||||
<div class="w-1/12"><strong># {{ $item.Rank }}</strong></div>
|
||||
<div class="flex w-4/12 justify-start items-center space-x-4 text-ellipsis overflow-hidden whitespace-nowrap align-middle">
|
||||
{{ if avatarUrlTemplate }}
|
||||
<img src="{{ $item.User.AvatarURL avatarUrlTemplate }}" width="24px" class="rounded-full border-green-700" alt="User Profile Avatar"/>
|
||||
{{ else }}
|
||||
@ -56,7 +56,10 @@
|
||||
{{ end }}
|
||||
<strong>@{{ $item.UserID }}</strong>
|
||||
</div>
|
||||
<div class="w-4/12 text-right"><span>{{ $item.Total | duration }}</span></div>
|
||||
<span class="w-4/12 text-sm text-ellipsis overflow-hidden whitespace-nowrap leading-6 align-middle">
|
||||
{{ join (index $.UserLanguages $item.UserID) ", " }}
|
||||
</span>
|
||||
<div class="w-3/12 text-right"><span>{{ $item.Total | duration }}</span></div>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ol>
|
||||
|
Loading…
Reference in New Issue
Block a user