Added user context and router fixes

This commit is contained in:
xeovalyte 2024-06-05 14:56:36 +02:00
parent 5f31e4bf22
commit d6a102bf29
No known key found for this signature in database
3 changed files with 16 additions and 6 deletions

View File

@ -1,3 +1,4 @@
use crate::Route;
use dioxus::prelude::*;
#[component]
@ -7,15 +8,16 @@ pub fn Navbar() -> Element {
class: "navbar bg-base-200",
div {
class: "flex-1",
a { class: "btn btn-ghost text-xl", href: "/", "XVMCMM" },
Link { class: "btn btn-ghost text-xl", to: Route::Home {}, "XVMCMM" },
}
div {
class: "flex-none",
ul {
class: "px-1 py-1",
li { a { class: "btn btn-primary", href: "/auth", "Sign In" } },
li { Link { class: "btn btn-primary", to: Route::Auth {}, "Sign In" } },
}
}
}
Outlet::<Route> {}
}
}

View File

@ -9,11 +9,16 @@ use tracing::{info, Level};
use components::auth::Auth;
use components::home::Home;
use components::layout::navbar::Navbar;
use server::auth;
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
enum Route {
pub type UserState = Resource<Result<auth::User, ServerFnError>>;
#[derive(Clone, Routable)]
pub enum Route {
#[layout(Navbar)]
#[route("/")]
Home {},
#[route("/auth")]
Auth {},
}
@ -57,8 +62,11 @@ fn main() {
}
fn app() -> Element {
let user = use_resource(auth::get_current_user);
use_context_provider(|| user);
rsx! {
Navbar {},
Router::<Route> {},
}
}

View File

@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "server")]
use surrealdb::sql::Thing;
#[derive(Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct User {
pub id: String,
pub email: String,