From 0b9515645c714f90da0494130e37410cdd8b3626 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 17 Jun 2018 18:48:22 +0100 Subject: [PATCH] De-duplicate some parts of the users templates --- src/routes/user.rs | 3 ++- templates/users/details.html.tera | 33 +---------------------------- templates/users/followers.html.tera | 25 +--------------------- templates/users/header.tera | 32 ++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 57 deletions(-) create mode 100644 templates/users/header.tera diff --git a/src/routes/user.rs b/src/routes/user.rs index 8e6e5cd3..2bc25ec6 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -129,7 +129,8 @@ fn followers(name: String, conn: DbConn, account: Option) -> Template { json }).collect::>(), "account": account, - "is_self": account.map(|a| a.id == user_id).unwrap_or(false) + "is_self": account.map(|a| a.id == user_id).unwrap_or(false), + "n_followers": user.get_followers(&*conn).len() })) } diff --git a/templates/users/details.html.tera b/templates/users/details.html.tera index e34f8a76..f129135e 100644 --- a/templates/users/details.html.tera +++ b/templates/users/details.html.tera @@ -12,38 +12,7 @@ {% endblock title %} {% block content %} -
-

- {{ name }} - {% if user.is_admin %} - {{ "Admin" | _ }} - {% endif %} - - {% if is_self %} - {{ "It is you" | _ }} - {% endif %} -

- - {% if is_self %} - {{ "Edit your profile" | _ }} - {% endif %} - - {% if is_remote %} - {{ "Open on {{ instance_url }}" | _(instance_url=instance_url) }} - {% endif %} - - {% if not is_self and account %} - {% if follows %} - {{ "Follow" | _ }} - {% else %} - {{ "Unfollow" | _ }} - {% endif %} - {% endif %} -
- -
- {{ "{{ count }} followers" | _n(singular="One follower", count=n_followers) }} -
+ {% include "users/header" %}
{{ user.summary | safe }} diff --git a/templates/users/followers.html.tera b/templates/users/followers.html.tera index 6ce08eb5..2b025b38 100644 --- a/templates/users/followers.html.tera +++ b/templates/users/followers.html.tera @@ -11,30 +11,7 @@ {% endblock title %} {% block content %} -
-

- {{ name }} - {% if user.is_admin %} - {{ "Admin" | _ }} - {% endif %} - - {% if is_self %} - {{ "It is you" | _ }} - {% endif %} -

- - {% if is_remote %} - {{ "Open on {{ instance_url }}" | _(instance_url=instance_url) }} - {% endif %} - - {% if (not is_self) and account %} - {% if follows %} - {{ "Follow" | _ }} - {% else %} - {{ "Unfollow" | _ }} - {% endif %} - {% endif %} -
+ {% include "users/header" %}

{{ "Followers" | _ }}

diff --git a/templates/users/header.tera b/templates/users/header.tera new file mode 100644 index 00000000..dc69599a --- /dev/null +++ b/templates/users/header.tera @@ -0,0 +1,32 @@ +
+

+ {{ name }} + {% if user.is_admin %} + {{ "Admin" | _ }} + {% endif %} + + {% if is_self %} + {{ "It is you" | _ }} + {% endif %} +

+ + {% if is_self %} + {{ "Edit your profile" | _ }} + {% endif %} + + {% if is_remote %} + {{ "Open on {{ instance_url }}" | _(instance_url=instance_url) }} + {% endif %} + + {% if not is_self and account %} + {% if follows %} + {{ "Follow" | _ }} + {% else %} + {{ "Unfollow" | _ }} + {% endif %} + {% endif %} +
+ +