rustybeans/src/web.rs

51 lines
1.1 KiB
Rust

use yew::prelude::*;
use crate::config::Config;
use crate::database::Database;
use crate::plot::database_plot_selected;
use crate::plot::database_plot_selected_tui;
use std::process::Command;
#[function_component(App)]
pub fn plot_component() -> Html {
let config = Config::from_default();
let database = Database::from_config(&config);
let plots = database_plot_selected(
database
.brews
.iter()
.map(|brew| brew.config.uuid.clone())
.collect(),
true,
);
let plot_names: Vec<String> = plots.clone().into_iter().map(|plot| plot.0.clone()).collect();
let p = yew_hooks::use_async::<_, _, ()>({
async move {
for plot in &plots {
plotly::bindings::new_plot(&plot.0, &plot.1).await;
}
Ok(())
}
});
use_effect_with_deps(
move |_| {
p.run();
|| ()
},
(),
);
html! {
{
for plot_names.into_iter().map(|name| {
html!{<div id={name}></div>}
})
}
}
}