From e65d240113f68d5b842caefecdf5724ad4df7036 Mon Sep 17 00:00:00 2001 From: moshyfawn Date: Wed, 7 Jan 2026 15:43:07 -0500 Subject: [PATCH] appview: update followers count on follow/unfollow The follow button now returns the updated followers count alongside the button state, keeping them in sync Signed-off-by: moshyfawn --- appview/pages/pages.go | 7 +- .../templates/user/fragments/follow-oob.html | 6 + .../templates/user/fragments/followCard.html | 8 +- .../templates/user/fragments/profileCard.html | 196 +++++++++--------- appview/state/follow.go | 20 +- 5 files changed, 128 insertions(+), 109 deletions(-) create mode 100644 appview/pages/templates/user/fragments/follow-oob.html diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 7e806392..33c4252b 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -601,12 +601,13 @@ func (p *Pages) ProfileFollowing(w io.Writer, params ProfileFollowingParams) err } type FollowFragmentParams struct { - UserDid string - FollowStatus models.FollowStatus + UserDid string + FollowStatus models.FollowStatus + FollowersCount int64 } func (p *Pages) FollowFragment(w io.Writer, params FollowFragmentParams) error { - return p.executePlain("user/fragments/follow", w, params) + return p.executePlain("user/fragments/follow-oob", w, params) } type EditBioParams struct { diff --git a/appview/pages/templates/user/fragments/follow-oob.html b/appview/pages/templates/user/fragments/follow-oob.html new file mode 100644 index 00000000..5ded5c16 --- /dev/null +++ b/appview/pages/templates/user/fragments/follow-oob.html @@ -0,0 +1,6 @@ +{{ define "user/fragments/follow-oob" }} + {{ template "user/fragments/follow" . }} + + {{ .FollowersCount }} followers + +{{ end }} diff --git a/appview/pages/templates/user/fragments/followCard.html b/appview/pages/templates/user/fragments/followCard.html index 43b57fe3..95d19619 100644 --- a/appview/pages/templates/user/fragments/followCard.html +++ b/appview/pages/templates/user/fragments/followCard.html @@ -9,14 +9,16 @@ -{{ end }} +{{ end }} \ No newline at end of file diff --git a/appview/pages/templates/user/fragments/profileCard.html b/appview/pages/templates/user/fragments/profileCard.html index 59480f82..6c5d7925 100644 --- a/appview/pages/templates/user/fragments/profileCard.html +++ b/appview/pages/templates/user/fragments/profileCard.html @@ -1,114 +1,112 @@ {{ define "user/fragments/profileCard" }} - {{ $userIdent := resolve .UserDid }} -
-
-
- -
-
-
-
-

- {{ $userIdent }} -

- {{ with .Profile }} - {{ if .Pronouns }} -

{{ .Pronouns }}

- {{ end }} - {{ end }} -
+{{ $userIdent := resolve .UserDid }} +
+
+
+ +
+
+
+
+

+ {{ $userIdent }} +

+ {{ with .Profile }} + {{ if .Pronouns }} +

{{ .Pronouns }}

+ {{ end }} + {{ end }} +
-
- {{ block "followerFollowing" (list . $userIdent) }} {{ end }} -
-
-
-
- {{ $profile := .Profile }} - {{ with .Profile }} +
+ {{ block "followerFollowing" (list . $userIdent) }} {{ end }} +
+
+
+
+ {{ $profile := .Profile }} + {{ with .Profile }} - {{ if .Description }} -

{{ .Description }}

- {{ end }} + {{ if .Description }} +

{{ .Description }}

+ {{ end }} - + -
- {{ if .Location }} -
- {{ i "map-pin" "size-4" }} - {{ .Location }} -
- {{ end }} - {{ if .IncludeBluesky }} -
- {{ template "user/fragments/bluesky" "w-4 h-4 text-black dark:text-white" }} - {{ $userIdent }} -
- {{ end }} - {{ range $link := .Links }} - {{ if $link }} -
- {{ i "link" "size-4" }} - {{ $link }} -
- {{ end }} - {{ end }} - {{ if not $profile.IsStatsEmpty }} -
- {{ range $stat := .Stats }} - {{ if $stat.Kind }} -
- {{ $stat.Value }} - {{ $stat.Kind.String }} -
- {{ end }} - {{ end }} -
- {{ end }} +
+ {{ if .Location }} +
+ {{ i "map-pin" "size-4" }} + {{ .Location }} +
+ {{ end }} + {{ if .IncludeBluesky }} +
+ {{ template "user/fragments/bluesky" "w-4 h-4 text-black dark:text-white" + }} + {{ $userIdent }} +
+ {{ end }} + {{ range $link := .Links }} + {{ if $link }} +
+ {{ i "link" "size-4" }} + {{ $link }} +
+ {{ end }} + {{ end }} + {{ if not $profile.IsStatsEmpty }} +
+ {{ range $stat := .Stats }} + {{ if $stat.Kind }} +
+ {{ $stat.Value }} + {{ $stat.Kind.String }}
{{ end }} + {{ end }} +
+ {{ end }} +
+ {{ end }} -
- {{ if ne .FollowStatus.String "IsSelf" }} - {{ template "user/fragments/follow" . }} - {{ else }} - - {{ end }} - - - {{ i "rss" "size-4" }} - -
+
+ {{ if ne .FollowStatus.String "IsSelf" }} + {{ template "user/fragments/follow" . }} + {{ else }} + + {{ end }} -
-
+ + {{ i "rss" "size-4" }} +
+
+
+
+
{{ end }} {{ define "followerFollowing" }} - {{ $root := index . 0 }} - {{ $userIdent := index . 1 }} - {{ with $root }} - - {{ end }} +{{ $root := index . 0 }} +{{ $userIdent := index . 1 }} +{{ with $root }} + {{ end }} - +{{ end }} \ No newline at end of file diff --git a/appview/state/follow.go b/appview/state/follow.go index 9e218cac..48ac92ea 100644 --- a/appview/state/follow.go +++ b/appview/state/follow.go @@ -75,9 +75,15 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { s.notifier.NewFollow(r.Context(), follow) + followStats, err := db.GetFollowerFollowingCount(s.db, subjectIdent.DID.String()) + if err != nil { + log.Println("failed to get follow stats", err) + } + s.pages.FollowFragment(w, pages.FollowFragmentParams{ - UserDid: subjectIdent.DID.String(), - FollowStatus: models.IsFollowing, + UserDid: subjectIdent.DID.String(), + FollowStatus: models.IsFollowing, + FollowersCount: followStats.Followers, }) return @@ -106,9 +112,15 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { // this is not an issue, the firehose event might have already done this } + followStats, err := db.GetFollowerFollowingCount(s.db, subjectIdent.DID.String()) + if err != nil { + log.Println("failed to get follow stats", err) + } + s.pages.FollowFragment(w, pages.FollowFragmentParams{ - UserDid: subjectIdent.DID.String(), - FollowStatus: models.IsNotFollowing, + UserDid: subjectIdent.DID.String(), + FollowStatus: models.IsNotFollowing, + FollowersCount: followStats.Followers, }) s.notifier.DeleteFollow(r.Context(), follow) -- 2.43.0