diff --git a/application/Cargo.toml b/application/Cargo.toml index 18516d8..a4432b4 100644 --- a/application/Cargo.toml +++ b/application/Cargo.toml @@ -20,10 +20,16 @@ wasm-bindgen = "=0.2.92" thiserror = "1" tracing = { version = "0.1", optional = true } http = "1" +surrealdb = { version = "1.3.1", optional = true } +serde = "1.0.197" +serde_json = "1.0.115" +cfg-if = "1.0.0" +once_cell = "1.19.0" [features] hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"] ssr = [ + "dep:surrealdb", "dep:axum", "dep:tokio", "dep:tower", diff --git a/application/src/app.rs b/application/src/app.rs index 0ffd315..f865a21 100644 --- a/application/src/app.rs +++ b/application/src/app.rs @@ -3,14 +3,15 @@ use leptos::*; use leptos_meta::*; use leptos_router::*; +use crate::components; +use crate::pages; + #[component] pub fn App() -> impl IntoView { // Provides context that manages stylesheets, titles, meta tags, etc. provide_meta_context(); view! { - - // injects a stylesheet into the document // id=leptos means cargo-leptos will hot-reload this stylesheet @@ -27,24 +28,12 @@ pub fn App() -> impl IntoView { } .into_view() }> +
- +
} } - -/// Renders the home page of your application. -#[component] -fn HomePage() -> impl IntoView { - // Creates a reactive value to update the button - let (count, set_count) = create_signal(0); - let on_click = move |_| set_count.update(|count| *count += 1); - - view! { -

"Welcome to Leptos!"

- - } -} diff --git a/application/src/components.rs b/application/src/components.rs index e69de29..f505d68 100644 --- a/application/src/components.rs +++ b/application/src/components.rs @@ -0,0 +1 @@ +pub mod header; diff --git a/application/src/components/header.rs b/application/src/components/header.rs new file mode 100644 index 0000000..b91eaae --- /dev/null +++ b/application/src/components/header.rs @@ -0,0 +1,15 @@ +use leptos::*; + +/// Renders the home page of your application. +#[component] +pub fn Header() -> impl IntoView { + // Creates a reactive value to update the button + view! { +
+
+

"WRB Timings"

+
Connection: ???
+
+
+ } +} diff --git a/application/src/main.rs b/application/src/main.rs index a1d9284..9ec58fe 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -1,11 +1,11 @@ #[cfg(feature = "ssr")] #[tokio::main] async fn main() { + use application::app::*; + use application::fileserv::file_and_error_handler; use axum::Router; use leptos::*; use leptos_axum::{generate_route_list, LeptosRoutes}; - use application::app::*; - use application::fileserv::file_and_error_handler; // Setting get_configuration(None) means we'll be using cargo-leptos's env values // For deployment these variables are: @@ -25,6 +25,11 @@ async fn main() { let listener = tokio::net::TcpListener::bind(&addr).await.unwrap(); logging::log!("listening on http://{}", &addr); + + application::util::surrealdb::connect() + .await + .expect("Database connection failed"); + axum::serve(listener, app.into_make_service()) .await .unwrap(); diff --git a/application/src/pages.rs b/application/src/pages.rs index e69de29..33edc95 100644 --- a/application/src/pages.rs +++ b/application/src/pages.rs @@ -0,0 +1 @@ +pub mod index; diff --git a/application/src/pages/index.rs b/application/src/pages/index.rs new file mode 100644 index 0000000..9a7c754 --- /dev/null +++ b/application/src/pages/index.rs @@ -0,0 +1,14 @@ +use leptos::*; + +/// Renders the home page of your application. +#[component] +pub fn HomePage() -> impl IntoView { + // Creates a reactive value to update the button + let (count, set_count) = create_signal(0); + let on_click = move |_| set_count.update(|count| *count += 1); + + view! { +

"Welcome to Leptos!"

+ + } +} diff --git a/application/src/util/surrealdb.rs b/application/src/util/surrealdb.rs index 6add084..71e62c9 100644 --- a/application/src/util/surrealdb.rs +++ b/application/src/util/surrealdb.rs @@ -1 +1,32 @@ -pub mod tables; +use leptos::{logging, server, ServerFnError}; +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; +use serde_json::json; +use std::borrow::Cow; + +pub mod schemes; + +cfg_if::cfg_if! { + if #[cfg(feature = "ssr")] { + use surrealdb::engine::remote::ws::{Client, Ws}; + use surrealdb::opt::auth::Root; + use surrealdb::Surreal; + + pub static DB: Lazy> = Lazy::new(Surreal::init); + } +} + +#[cfg(feature = "ssr")] +pub async fn connect() -> Result<(), ServerFnError> { + DB.connect::("localhost:80").await?; + + DB.signin(Root { + username: "root", + password: "root", + }) + .await?; + + DB.use_ns("wrb").use_db("timings").await?; + + Ok(()) +} diff --git a/application/src/util/surrealdb/schemes.rs b/application/src/util/surrealdb/schemes.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/application/src/util/surrealdb/schemes.rs @@ -0,0 +1 @@ + diff --git a/application/src/util/surrealdb/tables.rs b/application/src/util/surrealdb/tables.rs deleted file mode 100644 index e69de29..0000000 diff --git a/application/style/header.scss b/application/style/header.scss new file mode 100644 index 0000000..6520302 --- /dev/null +++ b/application/style/header.scss @@ -0,0 +1,19 @@ +header { + width: 100%; + background-color: $secondary-bg-color; + display: flex; + justify-content: center; +} + +.header-container { + display: flex; + align-items: center; + width: 100%; + max-width: 1000px; + margin: 10px 20px; +} + +.header-container h3 { + margin: 0; + margin-right: auto; +} diff --git a/application/style/main.scss b/application/style/main.scss index 319a912..9a94bd3 100644 --- a/application/style/main.scss +++ b/application/style/main.scss @@ -1,4 +1,28 @@ +$primary-color: #eb6330; +$primary-color-light: hsl(16.36, 82.38%, 55.49%, 0.8); +$secondary-color: #465651; +$accent-color: #89969f; +$primary-bg-color: #0d0b0b; +$secondary-bg-color: #151719; +$secondary-bg-color-light: hsl(204, 11%, 12%, 1); +$secondary-bg-color-lighter: hsl(204, 11%, 15%, 1); +$accent-bg-color: #181a19; +$text-color: #f3efef; + +@import "header"; + +html, body { - font-family: sans-serif; - text-align: center; + height: 100vh; + max-width: 100vw; + display: flex; + flex-direction: column; + margin: 0; + font-family: Helvetica Neue, Helvetica, Arial, sans-serif; +} + +body { + background-color: $primary-bg-color; + color: $text-color; + align-items: center; }