working proto

This commit is contained in:
Romulus21
2024-09-28 00:52:51 +02:00
parent 9bc48ff63d
commit 72b65063be
20 changed files with 1706 additions and 1569 deletions

51
src/routes/value.rs Normal file
View File

@@ -0,0 +1,51 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use crate::models::OPTIONS;
#[server(ValueAction, "/api")]
pub async fn add_value(device: String, value: String) -> Result<(), ServerFnError> {
crate::models::Value::insert(device, value)
.await
.map(|_| ())
.map_err(|x| {
let err = format!("Error while posting a comment: {x:?}");
tracing::error!("{err}");
ServerFnError::ServerError("Could not post a comment, try again later".into())
})
}
#[component]
pub fn FormValues() -> impl IntoView {
let value_action = create_server_action::<ValueAction>();
let result = value_action.version();
let reset_value = create_rw_signal("");
//let add_value = ServerAction::<AddValue>::new();
//let value = add_value.value();
//let has_error = move || value.with(|val| matches!(val, Some(Err(_))));
view! {
<div class="my-0 mx-auto max-w-3xl text-center">
<h2 class="p-6 text-4xl">"Formulaire"</h2>
<ActionForm action=value_action attr:class="border">
<div>
<label class="block">Capteur</label>
<select name="device" class="dark:bg-slate-800 px-2 py-1">
{OPTIONS.into_iter()
.map(|option| view! { <option value={option.value}>{option.name}</option>})
.collect::<Vec<_>>()}
</select>
</div>
<div>
<label class="block">Valeur</label>
<input type="text" name="value" prop:value=move || reset_value.get() class="text-center dark:bg-slate-800 dark:text-white px-2 py-1" />
</div>
<div>
<button type="submit" class="bg-slate-600 px-2 py-1 w-48 mt-3">Valider</button>
</div>
</ActionForm>
</div>
}
}