Implemented SurrealDB
This commit is contained in:
parent
362e73acff
commit
1ceb513228
@ -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",
|
||||
|
@ -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 <head>
|
||||
// id=leptos means cargo-leptos will hot-reload this stylesheet
|
||||
<Stylesheet id="leptos" href="/pkg/application.css"/>
|
||||
@ -27,24 +28,12 @@ pub fn App() -> impl IntoView {
|
||||
}
|
||||
.into_view()
|
||||
}>
|
||||
<components::header::Header />
|
||||
<main>
|
||||
<Routes>
|
||||
<Route path="" view=HomePage/>
|
||||
<Route path="" view=pages::index::HomePage/>
|
||||
</Routes>
|
||||
</main>
|
||||
</Router>
|
||||
}
|
||||
}
|
||||
|
||||
/// 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! {
|
||||
<h1>"Welcome to Leptos!"</h1>
|
||||
<button on:click=on_click>"Click Me: " {count}</button>
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
pub mod header;
|
15
application/src/components/header.rs
Normal file
15
application/src/components/header.rs
Normal file
@ -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! {
|
||||
<header>
|
||||
<div class="header-container">
|
||||
<h3>"WRB Timings"</h3>
|
||||
<div>Connection: <span>???</span></div>
|
||||
</div>
|
||||
</header>
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -0,0 +1 @@
|
||||
pub mod index;
|
14
application/src/pages/index.rs
Normal file
14
application/src/pages/index.rs
Normal file
@ -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! {
|
||||
<h1>"Welcome to Leptos!"</h1>
|
||||
<button on:click=on_click>"Click Me: " {count}</button>
|
||||
}
|
||||
}
|
@ -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<Surreal<Client>> = Lazy::new(Surreal::init);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
pub async fn connect() -> Result<(), ServerFnError> {
|
||||
DB.connect::<Ws>("localhost:80").await?;
|
||||
|
||||
DB.signin(Root {
|
||||
username: "root",
|
||||
password: "root",
|
||||
})
|
||||
.await?;
|
||||
|
||||
DB.use_ns("wrb").use_db("timings").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
1
application/src/util/surrealdb/schemes.rs
Normal file
1
application/src/util/surrealdb/schemes.rs
Normal file
@ -0,0 +1 @@
|
||||
|
19
application/style/header.scss
Normal file
19
application/style/header.scss
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user