diff --git a/application/src/app.rs b/application/src/app.rs
index fae913d..b3b4429 100644
--- a/application/src/app.rs
+++ b/application/src/app.rs
@@ -5,11 +5,16 @@ use leptos_router::*;
use crate::components;
use crate::pages;
+use crate::util;
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
+ let once = create_resource(
+ || (),
+ |_| async move { util::surrealdb::init_participants().await },
+ );
view! {
// injects a stylesheet into the document
@@ -30,11 +35,16 @@ pub fn App() -> impl IntoView {
}>
-
-
-
-
-
+ {move || match once.get() {
+ None => view! { "Loading"
}.into_view(),
+ Some(_) => view! {
+
+
+
+
+
+ }.into_view()
+ }}
}
diff --git a/application/src/pages/index.rs b/application/src/pages/index.rs
index e68c818..fcd525d 100644
--- a/application/src/pages/index.rs
+++ b/application/src/pages/index.rs
@@ -1,13 +1,18 @@
use leptos::*;
use leptos_router::*;
+use crate::util::surrealdb::schemas;
+
/// Renders the home page of your application.
#[component]
pub fn HomePage() -> impl IntoView {
+ // let participants = use_context::>>().unwrap();
+
view! {
-
- }
+
+ }
}
diff --git a/application/src/util/surrealdb.rs b/application/src/util/surrealdb.rs
index b9aeac3..382b679 100644
--- a/application/src/util/surrealdb.rs
+++ b/application/src/util/surrealdb.rs
@@ -1,3 +1,5 @@
+use leptos::*;
+
pub mod schemas;
cfg_if::cfg_if! {
@@ -6,7 +8,6 @@ cfg_if::cfg_if! {
use surrealdb::engine::remote::ws::{Client, Ws};
use surrealdb::opt::auth::Root;
use surrealdb::Surreal;
- use leptos::{ServerFnError};
pub static DB: Lazy> = Lazy::new(Surreal::init);
}
@@ -26,3 +27,30 @@ pub async fn connect() -> Result<(), ServerFnError> {
Ok(())
}
+
+#[server]
+pub async fn get_participants() -> Result, ServerFnError> {
+ let participant_records: Vec = DB.select("participant").await?;
+
+ let mut participants: Vec = vec![];
+
+ participant_records.iter().for_each(|participant| {
+ participants.push(schemas::Participant {
+ id: participant.id.id.to_string(),
+ name: participant.name.clone(),
+ group: participant.group.clone(),
+ events: participant.events.clone(),
+ })
+ });
+
+ Ok(participants)
+}
+
+pub async fn init_participants() -> Result {
+ let participants = get_participants().await?;
+
+ let participants_signal = create_rw_signal(participants);
+ provide_context(participants_signal);
+
+ Ok(true)
+}