Browse Source

Split user card in a macro, use it for search and followings/ers

Dashie der otter 1 month ago
parent
commit
2332f23652

+ 3
- 3
controllers/api/v1/activitypub.py View File

@@ -83,9 +83,9 @@ def followers(name):
83 83
         flash(gettext("User not found"), "error")
84 84
         return redirect(url_for("bp_main.home"))
85 85
 
86
-    return render_template(
87
-        "users/followers.jinja2", pcfg=pcfg, user=user, actor=user.actor[0], followers=user.actor[0].followers
88
-    )
86
+    followers = user.actor[0].followers
87
+
88
+    return render_template("users/followers.jinja2", pcfg=pcfg, user=user, actor=user.actor[0], followers=followers)
89 89
 
90 90
 
91 91
 @bp_ap.route("/user/<string:name>/followers", methods=["GET", "POST"])

+ 30
- 0
templates/macros.jinja2 View File

@@ -0,0 +1,30 @@
1
+{% macro user_card(username, name, url, instance, summary, follow, remote, current_user) -%}
2
+    <div class="card text-center">
3
+        <div class="card-header">{{ username or name }}</div>
4
+        <div class="card-body">
5
+            {% if remote %}
6
+                <h6 class="card-title"><a href="{{ url }}">{{ name }}@{{ instance }}</a></h6>
7
+            {% else %}
8
+                <h6 class="card-title"><a href="{{ url }}">{{ name }}</a></h6>
9
+            {% endif %}
10
+            <p class="card-text">{{ summary or "" }}</p>
11
+        </div>
12
+        {% if current_user.is_authenticated %}
13
+            {% if follow != None %}
14
+                <div class="card-footer">
15
+                    {% if follow %}
16
+                        following
17
+                        <a href="{{ url_for("bp_users.unfollow", user=url) }}">
18
+                            <i class="fa fa-user-times" aria-hidden="true" title="unfollow" ></i>
19
+                        </a>
20
+                    {% else %}
21
+                        not following
22
+                        <a href="{{ url_for("bp_users.follow", user=url) }}">
23
+                            <i class="fa fa-user-plus" aria-hidden="true" title="follow" ></i>
24
+                        </a>
25
+                    {% endif %}
26
+                </div>
27
+            {% endif %}
28
+        {% endif %}
29
+    </div>
30
+{%- endmacro %}

+ 2
- 49
templates/search/results.jinja2 View File

@@ -1,4 +1,5 @@
1 1
 {% extends "layout.jinja2" %}
2
+{% from "macros.jinja2" import user_card %}
2 3
 
3 4
 {% block content %}
4 5
     <div class="row">
@@ -20,55 +21,7 @@
20 21
         <div class="col-lg-10">
21 22
             <div class="card-columns">
22 23
                 {% for account in results['accounts'] %}
23
-                    {% if account['remote'] %}
24
-                        <div class="card text-center">
25
-                            <div class="card-header">{{ account['username'] or account['name'] }}</div>
26
-                            <div class="card-body">
27
-                                <h6 class="card-title"><a
28
-                                        href="{{ account['url'] }}">{{ account['name'] }}@{{ account['instance'] }}</a>
29
-                                </h6>
30
-                                <p class="card-text">{{ account['summary'] or "" }}</p>
31
-                            </div>
32
-                            {% if current_user.is_authenticated %}
33
-                                <div class="card-footer">
34
-                                    {% if account['follow'] %}
35
-                                        following
36
-                                        <a href="{{ url_for("bp_users.unfollow", user=account['url']) }}">
37
-                                            <i class="fa fa-user-times" aria-hidden="true" title="unfollow" ></i>
38
-                                        </a>
39
-                                    {% else %}
40
-                                        not following
41
-                                        <a href="{{ url_for("bp_users.follow", user=account['url']) }}">
42
-                                            <i class="fa fa-user-plus" aria-hidden="true" title="follow" ></i>
43
-                                        </a>
44
-                                    {% endif %}
45
-                                </div>
46
-                            {% endif %}
47
-                        </div>
48
-                    {% else %}
49
-                        <div class="card text-center">
50
-                            <div class="card-header">{{ account['username'] or account['name'] }}</div>
51
-                            <div class="card-body">
52
-                                <h6 class="card-title"><a href="{{ account['url'] }}">{{ account['name'] }}</a></h6>
53
-                                <p class="card-text">{{ account['summary'] or "" }}</p>
54
-                            </div>
55
-                            {% if current_user.is_authenticated %}
56
-                                <div class="card-footer">
57
-                                    {% if account['follow'] %}
58
-                                        following
59
-                                        <a href="{{ url_for("bp_users.unfollow", user=account['url']) }}">
60
-                                            <i class="fa fa-user-times" aria-hidden="true" title="unfollow" ></i>
61
-                                        </a>
62
-                                    {% else %}
63
-                                        not following
64
-                                        <a href="{{ url_for("bp_users.follow", user=account['url']) }}">
65
-                                            <i class="fa fa-user-plus" aria-hidden="true" title="follow" ></i>
66
-                                        </a>
67
-                                    {% endif %}
68
-                                </div>
69
-                            {% endif %}
70
-                        </div>
71
-                    {% endif %}
24
+                    {{ user_card(account['username'], account['name'], account['url'], account['instance'], account['summary'], account['follow'], account['remote'], current_user) }}
72 25
                 {% endfor %}
73 26
             </div>
74 27
         </div>

+ 6
- 14
templates/users/followers.jinja2 View File

@@ -1,8 +1,10 @@
1 1
 {% extends "layout.jinja2" %}
2
+{% from "macros.jinja2" import user_card %}
2 3
 
3 4
 {% block content %}
4 5
     <div class="row">
5
-        <div class="col-lg-10"><h3>{{ gettext("Followers of") }} <a href="{{ url_for("bp_users.profile", name=user.name) }}">{{ user.username() }}</a></h3></div>
6
+        <div class="col-lg-10"><h3>{{ gettext("Followers of") }} <a
7
+                href="{{ url_for("bp_users.profile", name=user.name) }}">{{ user.username() }}</a></h3></div>
6 8
     </div>
7 9
 
8 10
     <br/>
@@ -11,20 +13,10 @@
11 13
         <div class="col-lg-10">
12 14
             <div class="card-columns">
13 15
                 {% for f in followers %}
14
-                    {% if not f.actor.is_local() %}
15
-                        <div class="card" style="width: 18rem;">
16
-                          <div class="card-body">
17
-                            <h6 class="card-title"><a href="{{ f.actor.url }}">{{ f.actor.name }}@{{ f.actor.domain }}</a></h6>
18
-                            <p class="card-text">{{ f.actor.summary or "" }}</p>
19
-                          </div>
20
-                        </div>
16
+                    {% if current_user.is_authenticated and current_user == user %}
17
+                        {{ user_card(f.actor.username, f.actor.name, f.actor.url, f.actor.domain, f.actor.summary, f.target_id == user.actor[0].id, not f.actor.is_local(), current_user) }}
21 18
                     {% else %}
22
-                        <div class="card" style="width: 18rem;">
23
-                          <div class="card-body">
24
-                            <h6 class="card-title"><a href="{{ f.target.url }}">{{ f.target.name }}</a></h6>
25
-                            <p class="card-text">{{ f.target.summary or "" }}</p>
26
-                          </div>
27
-                        </div>
19
+                        {{ user_card(f.actor.username, f.actor.name, f.actor.url, f.actor.domain, f.actor.summary, None, not f.actor.is_local(), current_user) }}
28 20
                     {% endif %}
29 21
                 {% endfor %}
30 22
             </div>

+ 4
- 13
templates/users/followings.jinja2 View File

@@ -1,4 +1,5 @@
1 1
 {% extends "layout.jinja2" %}
2
+{% from "macros.jinja2" import user_card %}
2 3
 
3 4
 {% block content %}
4 5
     <div class="row">
@@ -11,20 +12,10 @@
11 12
         <div class="col-lg-10">
12 13
             <div class="card-columns">
13 14
                 {% for f in followings %}
14
-                    {% if not f.target.is_local() %}
15
-                        <div class="card" style="width: 18rem;">
16
-                          <div class="card-body">
17
-                            <h6 class="card-title"><a href="{{ f.target.url }}">{{ f.target.name }}@{{ f.target.domain }}</a></h6>
18
-                            <p class="card-text">{{ f.target.summary or "" }}</p>
19
-                          </div>
20
-                        </div>
15
+                    {% if current_user.is_authenticated and current_user == user %}
16
+                        {{ user_card(f.target.username, f.target.name, f.target.url, f.target.domain, f.target.summary, f.actor_id == user.actor[0].id, not f.target.is_local(), current_user) }}
21 17
                     {% else %}
22
-                        <div class="card" style="width: 18rem;">
23
-                          <div class="card-body">
24
-                            <h6 class="card-title"><a href="{{ f.target.url }}">{{ f.target.name }}</a></h6>
25
-                            <p class="card-text">{{ f.target.summary or "" }}</p>
26
-                          </div>
27
-                        </div>
18
+                        {{ user_card(f.target.username, f.target.name, f.target.url, f.target.domain, f.target.summary, None, not f.target.is_local(), current_user) }}
28 19
                     {% endif %}
29 20
                 {% endfor %}
30 21
             </div>

Loading…
Cancel
Save