Browse Source

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

pull/10/head
Dashie der otter 10 months ago
parent
commit
2332f23652

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

@@ -83,9 +83,9 @@ def followers(name):
flash(gettext("User not found"), "error")
return redirect(url_for("bp_main.home"))

return render_template(
"users/followers.jinja2", pcfg=pcfg, user=user, actor=user.actor[0], followers=user.actor[0].followers
)
followers = user.actor[0].followers
return render_template("users/followers.jinja2", pcfg=pcfg, user=user, actor=user.actor[0], followers=followers)


@bp_ap.route("/user/<string:name>/followers", methods=["GET", "POST"])

+ 30
- 0
templates/macros.jinja2 View File

@@ -0,0 +1,30 @@
{% macro user_card(username, name, url, instance, summary, follow, remote, current_user) -%}
<div class="card text-center">
<div class="card-header">{{ username or name }}</div>
<div class="card-body">
{% if remote %}
<h6 class="card-title"><a href="{{ url }}">{{ name }}@{{ instance }}</a></h6>
{% else %}
<h6 class="card-title"><a href="{{ url }}">{{ name }}</a></h6>
{% endif %}
<p class="card-text">{{ summary or "" }}</p>
</div>
{% if current_user.is_authenticated %}
{% if follow != None %}
<div class="card-footer">
{% if follow %}
following
<a href="{{ url_for("bp_users.unfollow", user=url) }}">
<i class="fa fa-user-times" aria-hidden="true" title="unfollow" ></i>
</a>
{% else %}
not following
<a href="{{ url_for("bp_users.follow", user=url) }}">
<i class="fa fa-user-plus" aria-hidden="true" title="follow" ></i>
</a>
{% endif %}
</div>
{% endif %}
{% endif %}
</div>
{%- endmacro %}

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

@@ -1,4 +1,5 @@
{% extends "layout.jinja2" %}
{% from "macros.jinja2" import user_card %}

{% block content %}
<div class="row">
@@ -20,55 +21,7 @@
<div class="col-lg-10">
<div class="card-columns">
{% for account in results['accounts'] %}
{% if account['remote'] %}
<div class="card text-center">
<div class="card-header">{{ account['username'] or account['name'] }}</div>
<div class="card-body">
<h6 class="card-title"><a
href="{{ account['url'] }}">{{ account['name'] }}@{{ account['instance'] }}</a>
</h6>
<p class="card-text">{{ account['summary'] or "" }}</p>
</div>
{% if current_user.is_authenticated %}
<div class="card-footer">
{% if account['follow'] %}
following
<a href="{{ url_for("bp_users.unfollow", user=account['url']) }}">
<i class="fa fa-user-times" aria-hidden="true" title="unfollow" ></i>
</a>
{% else %}
not following
<a href="{{ url_for("bp_users.follow", user=account['url']) }}">
<i class="fa fa-user-plus" aria-hidden="true" title="follow" ></i>
</a>
{% endif %}
</div>
{% endif %}
</div>
{% else %}
<div class="card text-center">
<div class="card-header">{{ account['username'] or account['name'] }}</div>
<div class="card-body">
<h6 class="card-title"><a href="{{ account['url'] }}">{{ account['name'] }}</a></h6>
<p class="card-text">{{ account['summary'] or "" }}</p>
</div>
{% if current_user.is_authenticated %}
<div class="card-footer">
{% if account['follow'] %}
following
<a href="{{ url_for("bp_users.unfollow", user=account['url']) }}">
<i class="fa fa-user-times" aria-hidden="true" title="unfollow" ></i>
</a>
{% else %}
not following
<a href="{{ url_for("bp_users.follow", user=account['url']) }}">
<i class="fa fa-user-plus" aria-hidden="true" title="follow" ></i>
</a>
{% endif %}
</div>
{% endif %}
</div>
{% endif %}
{{ user_card(account['username'], account['name'], account['url'], account['instance'], account['summary'], account['follow'], account['remote'], current_user) }}
{% endfor %}
</div>
</div>

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

@@ -1,8 +1,10 @@
{% extends "layout.jinja2" %}
{% from "macros.jinja2" import user_card %}

{% block content %}
<div class="row">
<div class="col-lg-10"><h3>{{ gettext("Followers of") }} <a href="{{ url_for("bp_users.profile", name=user.name) }}">{{ user.username() }}</a></h3></div>
<div class="col-lg-10"><h3>{{ gettext("Followers of") }} <a
href="{{ url_for("bp_users.profile", name=user.name) }}">{{ user.username() }}</a></h3></div>
</div>

<br/>
@@ -11,20 +13,10 @@
<div class="col-lg-10">
<div class="card-columns">
{% for f in followers %}
{% if not f.actor.is_local() %}
<div class="card" style="width: 18rem;">
<div class="card-body">
<h6 class="card-title"><a href="{{ f.actor.url }}">{{ f.actor.name }}@{{ f.actor.domain }}</a></h6>
<p class="card-text">{{ f.actor.summary or "" }}</p>
</div>
</div>
{% if current_user.is_authenticated and current_user == user %}
{{ 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) }}
{% else %}
<div class="card" style="width: 18rem;">
<div class="card-body">
<h6 class="card-title"><a href="{{ f.target.url }}">{{ f.target.name }}</a></h6>
<p class="card-text">{{ f.target.summary or "" }}</p>
</div>
</div>
{{ 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) }}
{% endif %}
{% endfor %}
</div>

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

@@ -1,4 +1,5 @@
{% extends "layout.jinja2" %}
{% from "macros.jinja2" import user_card %}

{% block content %}
<div class="row">
@@ -11,20 +12,10 @@
<div class="col-lg-10">
<div class="card-columns">
{% for f in followings %}
{% if not f.target.is_local() %}
<div class="card" style="width: 18rem;">
<div class="card-body">
<h6 class="card-title"><a href="{{ f.target.url }}">{{ f.target.name }}@{{ f.target.domain }}</a></h6>
<p class="card-text">{{ f.target.summary or "" }}</p>
</div>
</div>
{% if current_user.is_authenticated and current_user == user %}
{{ 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) }}
{% else %}
<div class="card" style="width: 18rem;">
<div class="card-body">
<h6 class="card-title"><a href="{{ f.target.url }}">{{ f.target.name }}</a></h6>
<p class="card-text">{{ f.target.summary or "" }}</p>
</div>
</div>
{{ 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) }}
{% endif %}
{% endfor %}
</div>

Loading…
Cancel
Save