pacco/src/routes/ui/mod.rs
2025-01-26 10:52:02 +01:00

48 lines
1 KiB
Rust

use based::ui::prelude::*;
use maud::{PreEscaped, Render};
// TODO : API
pub mod pkg;
pub use pkg::pkg_ui;
pub mod repo;
pub use repo::repo_ui;
pub fn arch_card(a: &str, repo_name: &str, current: bool) -> PreEscaped<String> {
let url = if current {
&format!("/{repo_name}")
} else {
&format!("/{repo_name}?arch={a}")
};
let link = Link(&url, Text(&a).sm().medium().color(&Gray::_300)).use_htmx();
Rounded(
Padding(if current {
Background(link).color(Blue::_500)
} else {
Background(link).color(Gray::_700)
})
.x(ScreenValue::_3)
.y(ScreenValue::_1),
)
.size(Size::Full)
.render()
}
pub fn take_out<T>(v: &mut Vec<T>, f: impl Fn(&T) -> bool) -> (&mut Vec<T>, Option<T>) {
let mut index = -1;
for (i, e) in v.iter().enumerate() {
if f(e) {
index = i as i64;
}
}
if index != -1 {
let e = v.remove(index as usize);
return (v, Some(e));
}
(v, None)
}