From 5dc1e8322bd5c4a08fe4b8cffede30a257e3c777 Mon Sep 17 00:00:00 2001 From: Cameron Smith Date: Mon, 6 Oct 2025 02:36:45 -0400 Subject: [PATCH] appview/{db,pages,models}: show tooltips for user handles when hovering on reactions Signed-off-by: Cameron Smith --- appview/db/reaction.go | 43 ++++++++++++++++--- appview/issues/issues.go | 4 +- appview/models/reaction.go | 5 +++ appview/pages/pages.go | 4 +- .../templates/repo/fragments/reaction.html | 8 +++- .../pages/templates/repo/issues/issue.html | 6 ++- .../repo/pulls/fragments/pullHeader.html | 6 ++- appview/pulls/pulls.go | 4 +- 8 files changed, 62 insertions(+), 18 deletions(-) diff --git a/appview/db/reaction.go b/appview/db/reaction.go index 50831528..daae9d5c 100644 --- a/appview/db/reaction.go +++ b/appview/db/reaction.go @@ -62,16 +62,45 @@ func GetReactionCount(e Execer, threadAt syntax.ATURI, kind models.ReactionKind) return count, nil } -func GetReactionCountMap(e Execer, threadAt syntax.ATURI) (map[models.ReactionKind]int, error) { - countMap := map[models.ReactionKind]int{} +func GetReactionMap(e Execer, threadAt syntax.ATURI) (map[models.ReactionKind]models.ReactionDisplayData, error) { + const maxUsersPerKind = 20 + + query := ` + select kind, reacted_by_did, + row_number() over (partition by kind order by created asc) as rn, + count(*) over (partition by kind) as total + from reactions + where thread_at = ? + order by kind, created asc` + + rows, err := e.Query(query, threadAt) + if err != nil { + return nil, err + } + defer rows.Close() + + reactionMap := map[models.ReactionKind]models.ReactionDisplayData{} for _, kind := range models.OrderedReactionKinds { - count, err := GetReactionCount(e, threadAt, kind) - if err != nil { - return map[models.ReactionKind]int{}, nil + reactionMap[kind] = models.ReactionDisplayData{Count: 0, Users: []string{}} + } + + for rows.Next() { + var kind models.ReactionKind + var did string + var rn, total int + if err := rows.Scan(&kind, &did, &rn, &total); err != nil { + return nil, err } - countMap[kind] = count + + data := reactionMap[kind] + data.Count = total + if rn <= maxUsersPerKind { + data.Users = append(data.Users, did) + } + reactionMap[kind] = data } - return countMap, nil + + return reactionMap, rows.Err() } func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind models.ReactionKind) bool { diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 8e4ed732..58098b83 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -83,7 +83,7 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { return } - reactionCountMap, err := db.GetReactionCountMap(rp.db, issue.AtUri()) + reactionMap, err := db.GetReactionMap(rp.db, issue.AtUri()) if err != nil { l.Error("failed to get issue reactions", "err", err) } @@ -115,7 +115,7 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { Issue: issue, CommentList: issue.CommentList(), OrderedReactionKinds: models.OrderedReactionKinds, - Reactions: reactionCountMap, + Reactions: reactionMap, UserReacted: userReactions, LabelDefs: defs, }) diff --git a/appview/models/reaction.go b/appview/models/reaction.go index c1898076..3cb21acf 100644 --- a/appview/models/reaction.go +++ b/appview/models/reaction.go @@ -55,3 +55,8 @@ type Reaction struct { Rkey string Kind ReactionKind } + +type ReactionDisplayData struct { + Count int + Users []string +} diff --git a/appview/pages/pages.go b/appview/pages/pages.go index c0d4a036..340a268c 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -985,7 +985,7 @@ type RepoSingleIssueParams struct { LabelDefs map[string]*models.LabelDefinition OrderedReactionKinds []models.ReactionKind - Reactions map[models.ReactionKind]int + Reactions map[models.ReactionKind]models.ReactionDisplayData UserReacted map[models.ReactionKind]bool } @@ -1138,7 +1138,7 @@ type RepoSinglePullParams struct { Pipelines map[string]models.Pipeline OrderedReactionKinds []models.ReactionKind - Reactions map[models.ReactionKind]int + Reactions map[models.ReactionKind]models.ReactionDisplayData UserReacted map[models.ReactionKind]bool LabelDefs map[string]*models.LabelDefinition diff --git a/appview/pages/templates/repo/fragments/reaction.html b/appview/pages/templates/repo/fragments/reaction.html index c9d032fd..19068aa4 100644 --- a/appview/pages/templates/repo/fragments/reaction.html +++ b/appview/pages/templates/repo/fragments/reaction.html @@ -2,7 +2,7 @@ {{ end }} diff --git a/appview/pages/templates/repo/issues/issue.html b/appview/pages/templates/repo/issues/issue.html index 7fa50d46..8c971bd7 100644 --- a/appview/pages/templates/repo/issues/issue.html +++ b/appview/pages/templates/repo/issues/issue.html @@ -110,13 +110,15 @@
{{ template "repo/fragments/reactionsPopUp" .OrderedReactionKinds }} {{ range $kind := .OrderedReactionKinds }} + {{ $reactionData := index $.Reactions $kind }} {{ template "repo/fragments/reaction" (dict "Kind" $kind - "Count" (index $.Reactions $kind) + "Count" $reactionData.Count "IsReacted" (index $.UserReacted $kind) - "ThreadAt" $.Issue.AtUri) + "ThreadAt" $.Issue.AtUri + "Users" $reactionData.Users) }} {{ end }}
diff --git a/appview/pages/templates/repo/pulls/fragments/pullHeader.html b/appview/pages/templates/repo/pulls/fragments/pullHeader.html index 74ddc9af..93c1c77b 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullHeader.html +++ b/appview/pages/templates/repo/pulls/fragments/pullHeader.html @@ -66,13 +66,15 @@
{{ template "repo/fragments/reactionsPopUp" . }} {{ range $kind := . }} + {{ $reactionData := index $.Reactions $kind }} {{ template "repo/fragments/reaction" (dict "Kind" $kind - "Count" (index $.Reactions $kind) + "Count" $reactionData.Count "IsReacted" (index $.UserReacted $kind) - "ThreadAt" $.Pull.PullAt) + "ThreadAt" $.Pull.PullAt + "Users" $reactionData.Users) }} {{ end }}
diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 0f5e70f9..5fb6fc3d 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -189,7 +189,7 @@ func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { m[p.Sha] = p } - reactionCountMap, err := db.GetReactionCountMap(s.db, pull.PullAt()) + reactionMap, err := db.GetReactionMap(s.db, pull.PullAt()) if err != nil { log.Println("failed to get pull reactions") s.pages.Notice(w, "pulls", "Failed to load pull. Try again later.") @@ -227,7 +227,7 @@ func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { Pipelines: m, OrderedReactionKinds: models.OrderedReactionKinds, - Reactions: reactionCountMap, + Reactions: reactionMap, UserReacted: userReactions, LabelDefs: defs, -- 2.43.0