This commit is contained in:
2025-02-06 21:34:30 +01:00
parent 9451980b25
commit 6597d61905
3 changed files with 31 additions and 21 deletions

View File

@@ -1,3 +1,4 @@
use crate::codec::ron::Ron;
use crate::pages;
use leptos::prelude::*;
use leptos_router::components::*;
@@ -55,29 +56,34 @@ pub fn Home() -> impl leptos::IntoView {
tracing::debug!("Rendering home component");
let action = Action::new(|()| async move {
tracing::debug!("running action");
let walls = crate::server_functions::get_walls()
.await
.inspect_err(|e| {
dbg!(e);
})
.expect("failed to get walls")
.into_inner();
let wall = walls.first();
// dbg!(leptos::prelude::Owner::current().map(|o| o.ancestry()));
if let Some(wall) = wall {
let wall_uid = OnceResource::<_, Ron>::new_with_options(
async move {
// dbg!(leptos::prelude::Owner::current().map(|o| o.ancestry()));
let walls = crate::server_functions::get_walls()
.await
.inspect_err(|e| {
dbg!(e);
})
.expect("failed to get walls")
.into_inner();
walls.first().map(|wall| wall.uid)
},
false,
);
Effect::new(move || {
tracing::debug!("running effect");
if let Some(wall_uid) = wall_uid.get().flatten() {
tracing::debug!("navigating");
let navigate = leptos_router::hooks::use_navigate();
let url = format!("/wall/{}", wall.uid);
let url = format!("/wall/{}", wall_uid);
navigate(&url, Default::default());
tracing::debug!("navigated");
}
});
tracing::debug!("dispatching action...");
action.dispatch(());
tracing::debug!("dispatched action");
leptos::view! {}
}

View File

@@ -63,6 +63,7 @@ async fn serve(cli: Cli) -> Result<(), Error> {
let leptos_options = leptos_conf_file.leptos_options;
let addr = leptos_options.site_addr;
let routes = generate_route_list(App);
dbg!(&routes);
let config = load_config(cli)?;

View File

@@ -4,19 +4,20 @@ use crate::models;
use leptos::prelude::expect_context;
use leptos::server;
use server_fn::ServerFnError;
use server_fn::error::ServerFnErrorErr;
#[server(
input = Ron,
output = Ron,
custom = RonEncoded
)]
#[tracing::instrument(skip_all, err(Debug))]
pub(crate) async fn get_walls() -> Result<RonEncoded<Vec<models::Wall>>, ServerFnError> {
// #[tracing::instrument(skip_all, err(Debug))]
pub async fn get_walls() -> Result<RonEncoded<Vec<models::Wall>>, ServerFnError> {
use crate::server::db::Database;
use redb::ReadableTable;
tracing::debug!("Enter");
// dbg!(leptos::prelude::Owner::current().map(|o| o.ancestry()));
let db = expect_context::<Database>();
let walls = db
@@ -27,6 +28,8 @@ pub(crate) async fn get_walls() -> Result<RonEncoded<Vec<models::Wall>>, ServerF
})
.await?;
tracing::debug!("Exit");
Ok(RonEncoded::new(walls))
}