add scuttlebutt peers menu and inactive template

This commit is contained in:
glyph 2022-03-18 11:32:51 +02:00
parent 59739cf6e5
commit 729580729c
7 changed files with 86 additions and 2 deletions

View File

@ -13,9 +13,17 @@ we do not need to be super fast or feature-rich.
[ tasks ]
- write the settings route(s)
- scuttlebutt
- peers
x menu
- peers list
- invites
- profile
- private
x menu
x guide
- status
x status
x scuttlebutt
x scuttlebutt menu
- configure_sbot
x template

View File

@ -188,6 +188,10 @@ fn main() {
routes::settings::admin::delete::handle_form(request)
},
(GET) (/scuttlebutt/peers) => {
Response::html(routes::scuttlebutt::peers::build_template())
},
(GET) (/status/scuttlebutt) => {
Response::html(routes::status::scuttlebutt::build_template())
},

View File

@ -3,6 +3,6 @@ pub mod authentication;
//pub mod index;
pub mod guide;
pub mod home;
//pub mod scuttlebutt;
pub mod scuttlebutt;
pub mod settings;
pub mod status;

View File

@ -0,0 +1 @@
pub mod peers;

View File

@ -0,0 +1,42 @@
use maud::{html, PreEscaped};
use peach_lib::sbot::SbotStatus;
use crate::templates;
/// Scuttlebutt peer menu template builder.
///
/// A peer menu which allows navigating to lists of friends, follows, followers
/// and blocks, as well as accessing the invite creation form.
pub fn build_template() -> PreEscaped<String> {
let menu_template = match SbotStatus::read() {
Ok(status) if status.state == Some("active".to_string()) => {
// render the scuttlebutt peers menu
html! {
(PreEscaped("<!-- SCUTTLEBUTT PEERS -->"))
div class="card center" {
div class="card-container" {
(PreEscaped("<!-- BUTTONS -->"))
div id="buttons" {
a id="search" class="button button-primary center" href="/scuttlebutt/search" title="Search for a peer" { "Search" }
a id="friends" class="button button-primary center" href="/scuttlebutt/friends" title="List friends" { "Friends" }
a id="follows" class="button button-primary center" href="/scuttlebutt/follows" title="List follows" { "Follows" }
a id="blocks" class="button button-primary center" href="/scuttlebutt/blocks" title="List blocks" { "Blocks" }
a id="invites" class="button button-primary center" href="/scuttlebutt/invites" title="Create invites" { "Invites" }
}
}
}
}
}
_ => {
// 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(menu_template, "Scuttlebutt Peers", Some("/"));
// render the base template with the provided body
templates::base::build_template(body)
}

View File

@ -0,0 +1,28 @@
use maud::{html, Markup, PreEscaped};
/// Sbot inactive template builder.
///
/// Display a message to the operator when the sbot is inactive and
/// therefore some functionality is not available.
pub fn build_template(unavailable_msg: &str) -> Markup {
html! {
(PreEscaped("<!-- SBOT INACTIVE -->"))
div class="card center" {
div class="capsule capsule-container border-warning center-text" {
p class="card-text" style="font-size: var(--font-size-4);" {
"Sbot Inactive"
}
p class="card-text" { (unavailable_msg) }
p class="card-text" {
"Visit the "
strong {
a href="/settings/scuttlebutt" class="link" {
"Scuttlebutt settings menu"
}
}
" to start the Sbot and then try again."
}
}
}
}
}

View File

@ -1,3 +1,4 @@
pub mod base;
pub mod flash;
pub mod inactive;
pub mod nav;