Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/state: add htmx handler for profile popups

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
1402ff5f 38311291

+69
+18
appview/pages/pages.go
··· 768 768 return p.executePlain("user/fragments/follow-oob", w, params) 769 769 } 770 770 771 + type ProfilePopoverParams struct { 772 + LoggedInUser *oauth.MultiAccountUser 773 + UserDid string 774 + Profile *models.Profile 775 + FollowStatus models.FollowStatus 776 + VouchRelationship *models.VouchRelationship 777 + Stats ProfilePopoverStats 778 + } 779 + 780 + type ProfilePopoverStats struct { 781 + FollowersCount int64 782 + FollowingCount int64 783 + } 784 + 785 + func (p *Pages) ProfilePopoverFragment(w io.Writer, params ProfilePopoverParams) error { 786 + return p.executePlain("user/fragments/profilePopover", w, params) 787 + } 788 + 771 789 type EditBioParams struct { 772 790 LoggedInUser *oauth.MultiAccountUser 773 791 Profile *models.Profile
+49
appview/state/profile.go
··· 905 905 s.pages.HxRedirect(w, "/"+user.Did) 906 906 } 907 907 908 + func (s *State) ProfilePopover(w http.ResponseWriter, r *http.Request) { 909 + l := s.logger.With("handler", "ProfilePopover") 910 + 911 + did := r.URL.Query().Get("did") 912 + if did == "" { 913 + l.Warn("missing did param") 914 + w.WriteHeader(http.StatusBadRequest) 915 + return 916 + } 917 + 918 + profile, err := db.GetProfile(s.db, did) 919 + if err != nil { 920 + l.Error("failed to get profile", "did", did, "err", err) 921 + w.WriteHeader(http.StatusInternalServerError) 922 + return 923 + } 924 + if profile == nil { 925 + profile = &models.Profile{Did: did} 926 + } 927 + 928 + followStats, err := db.GetFollowerFollowingCount(s.db, did) 929 + if err != nil { 930 + l.Error("failed to get follower stats", "did", did, "err", err) 931 + w.WriteHeader(http.StatusInternalServerError) 932 + return 933 + } 934 + 935 + loggedInUser := s.oauth.GetMultiAccountUser(r) 936 + followStatus := models.IsNotFollowing 937 + var vouchRelationship *models.VouchRelationship 938 + 939 + if loggedInUser != nil { 940 + followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did) 941 + vouchRelationship, _ = db.GetVouchRelationship(s.db, syntax.DID(loggedInUser.Did), syntax.DID(did)) 942 + } 943 + 944 + s.pages.ProfilePopoverFragment(w, pages.ProfilePopoverParams{ 945 + LoggedInUser: loggedInUser, 946 + UserDid: did, 947 + Profile: profile, 948 + FollowStatus: followStatus, 949 + VouchRelationship: vouchRelationship, 950 + Stats: pages.ProfilePopoverStats{ 951 + FollowersCount: followStats.Followers, 952 + FollowingCount: followStats.Following, 953 + }, 954 + }) 955 + } 956 + 908 957 func (s *State) EditBioFragment(w http.ResponseWriter, r *http.Request) { 909 958 l := s.logger.With("handler", "EditBioFragment") 910 959 user := s.oauth.GetMultiAccountUser(r)
+2
appview/state/router.go
··· 195 195 r.Delete("/", s.React) 196 196 }) 197 197 198 + r.Get("/profile/popover", s.ProfilePopover) 199 + 198 200 r.Route("/profile", func(r chi.Router) { 199 201 r.Use(middleware.AuthMiddleware(s.oauth)) 200 202 r.Get("/edit-bio", s.EditBioFragment)