50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use crate::util::surrealdb::schemas;
|
|
use leptos::*;
|
|
use leptos_router::ActionForm;
|
|
|
|
cfg_if::cfg_if! {
|
|
if #[cfg(feature = "ssr")] {
|
|
use crate::util::surrealdb::{DB};
|
|
use leptos::logging;
|
|
}
|
|
}
|
|
|
|
#[server(AddTime)]
|
|
async fn add_time(name: String, group: String) -> Result<(), ServerFnError> {
|
|
let created: Vec<schemas::Participant> = DB
|
|
.create("participant")
|
|
.content(schemas::NewParticipant { name, group })
|
|
.await?;
|
|
|
|
match created.first() {
|
|
Some(participant) => {
|
|
logging::log!(
|
|
"Created participant: {} ({})",
|
|
participant.name,
|
|
participant.group
|
|
);
|
|
Ok(())
|
|
}
|
|
None => Err(ServerFnError::ServerError(String::from(
|
|
"Could not create participant",
|
|
))),
|
|
}
|
|
}
|
|
|
|
/// Renders the home page of your application.
|
|
#[component]
|
|
pub fn AddTime() -> impl IntoView {
|
|
let participants = use_context::<RwSignal<Vec<schemas::Participant>>>();
|
|
|
|
let form_submit = create_server_action::<AddTime>();
|
|
|
|
view! {
|
|
<h2>"Tijd toevoegen"</h2>
|
|
<ActionForm action=form_submit>
|
|
<label>Naam</label>
|
|
<input type="text" name="name" autocomplete="off" />
|
|
<input type="submit" value="Tijd toevoegen" />
|
|
</ActionForm>
|
|
}
|
|
}
|