add friends, follows and blocks route handlers and templates
This commit is contained in:
parent
4e8d93c388
commit
0353586705
|
@ -94,6 +94,18 @@ pub fn mount_peachpub_routes(request: &Request) -> Response {
|
|||
routes::settings::admin::delete::handle_form(request)
|
||||
},
|
||||
|
||||
(GET) (/scuttlebutt/blocks) => {
|
||||
Response::html(routes::scuttlebutt::blocks::build_template())
|
||||
},
|
||||
|
||||
(GET) (/scuttlebutt/follows) => {
|
||||
Response::html(routes::scuttlebutt::follows::build_template())
|
||||
},
|
||||
|
||||
(GET) (/scuttlebutt/friends) => {
|
||||
Response::html(routes::scuttlebutt::friends::build_template())
|
||||
},
|
||||
|
||||
(GET) (/scuttlebutt/peers) => {
|
||||
Response::html(routes::scuttlebutt::peers::build_template())
|
||||
},
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
use maud::PreEscaped;
|
||||
|
||||
use crate::{templates, utils::sbot};
|
||||
|
||||
/// Scuttlebutt blocks list template builder.
|
||||
pub fn build_template() -> PreEscaped<String> {
|
||||
// retrieve the list of blocked peers
|
||||
match sbot::get_blocks_list() {
|
||||
// populate the peers_list template with blocks and render it
|
||||
Ok(blocks) => templates::peers_list::build_template(blocks, "Blocks"),
|
||||
Err(e) => {
|
||||
// render the sbot error template with the error message
|
||||
let error_template = templates::error::build_template(e.to_string());
|
||||
// wrap the nav bars around the error template content
|
||||
let body = templates::nav::build_template(error_template, "Blocks", Some("/"));
|
||||
|
||||
// render the base template with the provided body
|
||||
templates::base::build_template(body)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
use maud::PreEscaped;
|
||||
|
||||
use crate::{templates, utils::sbot};
|
||||
|
||||
/// Scuttlebutt follows list template builder.
|
||||
pub fn build_template() -> PreEscaped<String> {
|
||||
// retrieve the list of follows
|
||||
match sbot::get_follows_list() {
|
||||
// populate the peers_list template with follows
|
||||
Ok(follows) => templates::peers_list::build_template(follows, "Follows"),
|
||||
Err(e) => {
|
||||
// render the sbot error template with the error message
|
||||
let error_template = templates::error::build_template(e.to_string());
|
||||
// wrap the nav bars around the error template content
|
||||
let body = templates::nav::build_template(error_template, "Follows", Some("/"));
|
||||
|
||||
// render the base template with the provided body
|
||||
templates::base::build_template(body)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
use maud::PreEscaped;
|
||||
|
||||
use crate::{templates, utils::sbot};
|
||||
|
||||
/// Scuttlebutt friends list template builder.
|
||||
pub fn build_template() -> PreEscaped<String> {
|
||||
// retrieve the list of friends
|
||||
match sbot::get_friends_list() {
|
||||
// populate the peers_list template with friends and render it
|
||||
Ok(friends) => templates::peers_list::build_template(friends, "Friends"),
|
||||
Err(e) => {
|
||||
// render the sbot error template with the error message
|
||||
let error_template = templates::error::build_template(e.to_string());
|
||||
// wrap the nav bars around the error template content
|
||||
let body = templates::nav::build_template(error_template, "Friends", Some("/"));
|
||||
|
||||
// render the base template with the provided body
|
||||
templates::base::build_template(body)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +1,4 @@
|
|||
pub mod blocks;
|
||||
pub mod follows;
|
||||
pub mod friends;
|
||||
pub mod peers;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
pub mod base;
|
||||
pub mod error;
|
||||
pub mod flash;
|
||||
pub mod inactive;
|
||||
pub mod nav;
|
||||
pub mod peers_list;
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use maud::{html, Markup, PreEscaped};
|
||||
use peach_lib::sbot::SbotStatus;
|
||||
|
||||
use crate::templates;
|
||||
|
||||
/// Render an unordered list of peers with one list element for each peer.
|
||||
fn peers_template(peers: Vec<HashMap<String, String>>) -> Markup {
|
||||
html! {
|
||||
ul class="center list" {
|
||||
@for peer in peers {
|
||||
@let (name, name_alt) = match peer.get("name") {
|
||||
Some(name) => (
|
||||
name.to_owned(),
|
||||
format!("{}'s profile image", name)
|
||||
),
|
||||
None => (
|
||||
// set a fall-back value for name in case the data is unavailable
|
||||
"name unavailable".to_string(),
|
||||
"Profile image".to_string()
|
||||
)
|
||||
};
|
||||
@let profile_link = format!("/scuttlebutt/profile?public_key={}", peer["id"]);
|
||||
li {
|
||||
a class="list-item link" href=(profile_link) {
|
||||
@if peer.get("blob_path").is_some() && peer["blob_exists"] == "true" {
|
||||
@let blob_path = format!("/blob/{}", peer["blob_path"]);
|
||||
img id="peerImage" class="icon list-icon" src=(blob_path) alt=(name_alt);
|
||||
} @else {
|
||||
// use a placeholder image if we don't have the blob
|
||||
img id="peerImage" class="icon icon-active list-icon" src="/icons/user.svg" alt="Placeholder profile image";
|
||||
}
|
||||
p id="peerName" class="font-normal list-text" { (name) };
|
||||
@let name_title = format!("{}'s public key", name);
|
||||
label class="label-small label-ellipsis list-label font-gray" for="peerName" title=(name_title) {
|
||||
(peer["id"])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Scuttlebutt peers list template builder.
|
||||
///
|
||||
/// A list of peers. Currently used to render lists of friends, follows and
|
||||
/// blocks. The title of the page is set according to the provided parameter.
|
||||
pub fn build_template(peers: Vec<HashMap<String, String>>, title: &str) -> PreEscaped<String> {
|
||||
let peer_list_template = match SbotStatus::read() {
|
||||
// only render the complete peers list if the sbot is active
|
||||
Ok(status) if status.state == Some("active".to_string()) => {
|
||||
html! {
|
||||
div class="card center" {
|
||||
@if !peers.is_empty() {
|
||||
// render the peers list template
|
||||
(peers_template(peers))
|
||||
} @else {
|
||||
p { "No follows found" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// the sbot is not active; render a message instead of the menu
|
||||
templates::inactive::build_template("Social lists and interactions are unavailable.")
|
||||
}
|
||||
};
|
||||
|
||||
// wrap the nav bars around the settings menu template content
|
||||
// parameters are template, title and back url
|
||||
let body =
|
||||
templates::nav::build_template(peer_list_template, title, Some("/scuttlebutt/peers"));
|
||||
|
||||
// render the base template with the provided body
|
||||
templates::base::build_template(body)
|
||||
}
|
Loading…
Reference in New Issue