package views import ( "strconv" "hearthforge/internal/db" g "maragu.dev/gomponents" . "maragu.dev/gomponents/html" ) // AllowedReactions are the emoji a user may react with, in picker order. var AllowedReactions = []string{"👍", "👎", "❤️", "🎉", "😕", "👀", "🚀"} // ReactionCount is one emoji with its total and whether the viewer reacted. type ReactionCount struct { Emoji string Count int UserReacted bool } // ReactionBar renders the reaction buttons and the picker. // commentID is 0 for the issue or patch body itself. func ReactionBar(reactions []ReactionCount, postURL string, commentID int64, user *db.SessionUser) g.Node { if user == nil && len(reactions) == 0 { return nil } existing := make(map[string]bool, len(reactions)) for _, r := range reactions { existing[r.Emoji] = true } commentInput := func() g.Node { return g.If(commentID != 0, Input(Type("hidden"), Name("comment_id"), Value(strconv.FormatInt(commentID, 10)))) } return Div(Class("reaction-bar"), g.Map(reactions, func(r ReactionCount) g.Node { class := "reaction-btn" if r.UserReacted { class += " reacted" } return Form(Method("POST"), Action(postURL), Class("reaction-form"), commentInput(), Input(Type("hidden"), Name("emoji"), Value(r.Emoji)), Button(Type("submit"), Class(class), g.If(user == nil, Disabled()), g.Text(r.Emoji+" "+strconv.Itoa(r.Count))), ) }), g.If(user != nil, Details(Class("reaction-picker"), Summary(Class("reaction-add-btn"), g.Text("+")), Div(Class("reaction-picker-dropdown"), g.Map(AllowedReactions, func(e string) g.Node { if existing[e] { return nil } return Form(Method("POST"), Action(postURL), Class("reaction-form"), commentInput(), Input(Type("hidden"), Name("emoji"), Value(e)), Button(Type("submit"), Class("reaction-picker-btn"), g.Text(e)), ) }), ), )), ) }