From 11037d80df459329fc3a11a78adf02275eaa727a Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Tue, 10 Oct 2023 15:38:53 -0700 Subject: [PATCH] user page redesign: implement followers, following pages includes subtabs on profile pages for #442 --- pages.py | 27 +++++++++++++++++---------- static/style.css | 1 + templates/feed.html | 2 -- templates/followers.html | 23 ++++++++++------------- templates/following.html | 21 ++++++++------------- templates/profile.html | 36 ++++++++++++++++-------------------- templates/user_base.html | 19 +++++++++++++++++-- 7 files changed, 69 insertions(+), 60 deletions(-) diff --git a/pages.py b/pages.py index 630209c..a6675c4 100644 --- a/pages.py +++ b/pages.py @@ -9,7 +9,7 @@ from flask import g, render_template, request from google.cloud.ndb import tasklets from google.cloud.ndb.query import AND, OR from google.cloud.ndb.stats import KindStat -from granary import as1, atom, microformats2, rss +from granary import as1, as2, atom, microformats2, rss import humanize from oauth_dropins.webutil import flask_util, logs, util from oauth_dropins.webutil.flask_util import error, flash, redirect @@ -105,15 +105,7 @@ def profile(protocol, id): Object.notify == g.user.key)) objects, before, after = fetch_objects(query, by=Object.updated) - followers = Follower.query(Follower.to == g.user.key, - Follower.status == 'active')\ - .count(limit=FOLLOWERS_UI_LIMIT) - followers = f'{followers}{"+" if followers == FOLLOWERS_UI_LIMIT else ""}' - - following = Follower.query(Follower.from_ == g.user.key, - Follower.status == 'active')\ - .count(limit=FOLLOWERS_UI_LIMIT) - following = f'{following}{"+" if following == FOLLOWERS_UI_LIMIT else ""}' + num_followers, num_following = count_followers() return render_template('profile.html', logs=logs, util=util, g=g, **locals()) @@ -143,9 +135,11 @@ def followers_or_following(protocol, id, collection): load_user(protocol, id) followers, before, after = Follower.fetch_page(collection) + num_followers, num_following = count_followers() return render_template( f'{collection}.html', address=request.args.get('address'), + as2=as2, follow_url=request.values.get('url'), g=g, util=util, @@ -153,6 +147,19 @@ def followers_or_following(protocol, id, collection): ) +def count_followers(): + followers = Follower.query(Follower.to == g.user.key, + Follower.status == 'active')\ + .count(limit=FOLLOWERS_UI_LIMIT) + num_followers = f'{followers}{"+" if followers == FOLLOWERS_UI_LIMIT else ""}' + + following = Follower.query(Follower.from_ == g.user.key, + Follower.status == 'active')\ + .count(limit=FOLLOWERS_UI_LIMIT) + num_following = f'{following}{"+" if following == FOLLOWERS_UI_LIMIT else ""}' + + return num_followers, num_following + @app.get(f'///feed') def feed(protocol, id): format = request.args.get('format', 'html') diff --git a/static/style.css b/static/style.css index bcb0a98..5f97af0 100644 --- a/static/style.css +++ b/static/style.css @@ -345,6 +345,7 @@ button[disabled]:hover { border-left: 1px solid; border-right: 1px solid; background: inherit; + color: inherit; } .disable-button, #bad-button { diff --git a/templates/feed.html b/templates/feed.html index fcf7cca..4a81f2d 100644 --- a/templates/feed.html +++ b/templates/feed.html @@ -4,8 +4,6 @@ {% block content %} -{% include "user_addresses.html" %} -
Feed
diff --git a/templates/followers.html b/templates/followers.html index 3c51052..e19612c 100644 --- a/templates/followers.html +++ b/templates/followers.html @@ -1,13 +1,8 @@ -{% extends "base.html" %} - -{% block title %}{{ g.user.handle_or_id() }}'s followers - Bridgy Fed{% endblock %} - -{% block content %} - -{% include "user_addresses.html" %} - -
Followers
+{% extends "profile.html" %} +{% set subtab = "followers" %} +{% block subsubtabs %} +{% if g.user.LABEL != 'activitypub' %}
@@ -21,9 +16,11 @@
+{% endif %} +{% endblock subsubtabs %} -{% with page_name="followers" %} - {% include "_followers.html" %} -{% endwith %} - +{% block feed %} + {% with page_name="followers" %} + {% include "_followers.html" %} + {% endwith %} {% endblock %} diff --git a/templates/following.html b/templates/following.html index 1ade760..4e12d3b 100644 --- a/templates/following.html +++ b/templates/following.html @@ -1,13 +1,7 @@ -{% extends "base.html" %} - -{% block title %}{{ g.user.handle_or_id() }}'s following - Bridgy Fed{% endblock %} - -{% block content %} - -{% include "user_addresses.html" %} - -
Following
+{% extends "profile.html" %} +{% set subtab = "following" %} +{% block subsubtabs %} {% if g.user.LABEL != 'activitypub' %}
@@ -22,9 +16,10 @@
{% endif %} +{% endblock subsubtabs %} -{% with page_name="following" %} - {% include "_followers.html" %} -{% endwith %} - +{% block feed %} + {% with page_name="following" %} + {% include "_followers.html" %} + {% endwith %} {% endblock %} diff --git a/templates/profile.html b/templates/profile.html index 9bc5bf2..f98d1af 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -2,25 +2,21 @@ {% set tab = "profile" %} {% block subtabs %} -
- {{ followers }} follower{% if followers != '1' %}s{% endif %} - · - following {{ following }} - · - - {% if g.user.LABEL != 'activitypub' %} - bridged to - - - {{ g.user.ap_address() }} - -
- -   - -
- {% endif %} + + +{% block subsubtabs %} +{% endblock subsubtabs %} + {% endblock subtabs %} diff --git a/templates/user_base.html b/templates/user_base.html index cb3acb6..c4d1d36 100644 --- a/templates/user_base.html +++ b/templates/user_base.html @@ -35,8 +35,23 @@ {% endif %} {% endif %} -
- {{ g.user.user_link()|safe }} +
+ {{ g.user.user_link()|safe }} + · + {% if g.user.LABEL != 'activitypub' %} + bridged to + + + {{ g.user.ap_address() }} + +
+ +   + +
+ {% endif %}