From 02fca2475cd6f2ef9e5cbd527d12c3e3b440d4c8 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 | 41 +++++++++++++++---- appview/issues/issues.go | 4 +- appview/models/reaction.go | 5 +++ appview/pages/pages.go | 5 ++- .../templates/repo/fragments/reaction.html | 7 +++- .../pages/templates/repo/issues/issue.html | 6 ++- .../repo/pulls/fragments/pullHeader.html | 6 ++- appview/pulls/pulls.go | 4 +- appview/state/reaction.go | 14 ++++--- 9 files changed, 68 insertions(+), 24 deletions(-) diff --git a/appview/db/reaction.go b/appview/db/reaction.go index 50831528..fda13e5c 100644 --- a/appview/db/reaction.go +++ b/appview/db/reaction.go @@ -62,16 +62,43 @@ 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, userLimit int, threadAt syntax.ATURI) (map[models.ReactionKind]models.ReactionDisplayData, error) { + 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 userLimit > 0 && rn <= userLimit { + 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..70301a4b 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, 20, 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..f78f3856 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 } @@ -1010,6 +1010,7 @@ type ThreadReactionFragmentParams struct { ThreadAt syntax.ATURI Kind models.ReactionKind Count int + Users []string IsReacted bool } @@ -1138,7 +1139,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..5268b8de 100644 --- a/appview/pages/templates/repo/fragments/reaction.html +++ b/appview/pages/templates/repo/fragments/reaction.html @@ -2,7 +2,7 @@