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::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
@ -7,15 +8,16 @@ pub fn Navbar() -> Element {
|
|||||||
class: "navbar bg-base-200",
|
class: "navbar bg-base-200",
|
||||||
div {
|
div {
|
||||||
class: "flex-1",
|
class: "flex-1",
|
||||||
a { class: "btn btn-ghost text-xl", href: "/", "XVMCMM" },
|
Link { class: "btn btn-ghost text-xl", to: Route::Home {}, "XVMCMM" },
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
class: "flex-none",
|
class: "flex-none",
|
||||||
ul {
|
ul {
|
||||||
class: "px-1 py-1",
|
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::auth::Auth;
|
||||||
use components::home::Home;
|
use components::home::Home;
|
||||||
use components::layout::navbar::Navbar;
|
use components::layout::navbar::Navbar;
|
||||||
|
use server::auth;
|
||||||
|
|
||||||
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
pub type UserState = Resource<Result<auth::User, ServerFnError>>;
|
||||||
enum Route {
|
|
||||||
|
#[derive(Clone, Routable)]
|
||||||
|
pub enum Route {
|
||||||
|
#[layout(Navbar)]
|
||||||
#[route("/")]
|
#[route("/")]
|
||||||
Home {},
|
Home {},
|
||||||
|
|
||||||
#[route("/auth")]
|
#[route("/auth")]
|
||||||
Auth {},
|
Auth {},
|
||||||
}
|
}
|
||||||
@ -57,8 +62,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn app() -> Element {
|
fn app() -> Element {
|
||||||
|
let user = use_resource(auth::get_current_user);
|
||||||
|
|
||||||
|
use_context_provider(|| user);
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
Navbar {},
|
|
||||||
Router::<Route> {},
|
Router::<Route> {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
use surrealdb::sql::Thing;
|
use surrealdb::sql::Thing;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user