Added user context and router fixes
This commit is contained in:
parent
5f31e4bf22
commit
d6a102bf29
@ -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> {}
|
||||
}
|
||||
}
|
||||
|
14
src/main.rs
14
src/main.rs
@ -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> {},
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user