use class splices to reduce code repetition

This commit is contained in:
glyph 2022-03-21 15:17:16 +02:00
parent 34b4cbff32
commit 602c6a90f1
1 changed files with 7 additions and 23 deletions

View File

@ -13,36 +13,20 @@ fn render_status_elements<'a>() -> (&'a str, &'a str, &'a str) {
// status circle class color based on the go-sbot process state
if let Ok(status) = sbot_status {
if status.state == Some("active".to_string()) {
(
"circle circle-large circle-success",
"^_^",
"circle circle-small border-circle-small border-success",
)
("circle-success", "^_^", "border-success")
} else if status.state == Some("inactive".to_string()) {
(
"circle circle-large circle-warning",
"z_z",
"circle circle-small border-circle-small border-warning",
)
("circle-warning", "z_z", "border-warning")
} else {
(
"circle circle-large circle-error",
"x_x",
"circle circle-small border-circle-small border-danger",
)
("circle-error", "x_x", "border-danger")
}
} else {
(
"circle circle-large circle-error",
"x_x",
"circle circle-small border-circle-small border-danger",
)
("circle-error", "x_x", "border-danger")
}
}
/// Home template builder.
pub fn build_template() -> PreEscaped<String> {
let (center_circle_class, center_circle_text, status_circle_class) = render_status_elements();
let (circle_color, center_circle_text, circle_border) = render_status_elements();
// render the home template html
let home_template = html! {
@ -71,7 +55,7 @@ pub fn build_template() -> PreEscaped<String> {
}
(PreEscaped("<!-- middle -->"))
a class="middle" {
div class=(center_circle_class) {
div class={ "circle circle-large" (circle_color) } {
p style="font-size: 4rem; color: var(--near-black);" {
(center_circle_text)
}
@ -80,7 +64,7 @@ pub fn build_template() -> PreEscaped<String> {
(PreEscaped("<!-- bottom-left -->"))
(PreEscaped("<!-- SYSTEM STATUS LINK AND ICON -->"))
a class="bottom-left" href="/status/scuttlebutt" title="Status" {
div class=(status_circle_class) {
div class={ "circle circle-small border-circle-small" (circle_border) } {
img class="icon-medium" src="/icons/heart-pulse.svg";
}
}