diff --git a/src/main.rs b/src/main.rs index f80ae8c..513a555 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,7 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; mod cache; mod nyazoom_headers; +pub mod ssr; mod state; mod util; mod views; @@ -135,12 +136,11 @@ async fn remaining( async fn welcome() -> impl IntoResponse { let cat_fact = views::get_cat_fact().await; - Html( - leptos::ssr::render_to_string(move || { - leptos::view! { } - }) - .to_string(), - ) + Html(ssr::render(move || { + leptos::view! { + + } + })) } async fn records(State(state): State) -> impl IntoResponse { @@ -151,31 +151,28 @@ async fn records(State(state): State) -> impl IntoResponse { // this behind some kind of authentication async fn records_links(State(state): State) -> impl IntoResponse { let records = state.records.lock().await.clone(); - Html( - leptos::ssr::render_to_string(move || { - leptos::view! { - -
-
-
    - {records.keys().map(|key| leptos::view! { - - }) - .collect::>()} -
-
+ Html(ssr::render(move || { + leptos::view! { + +
+
+
    + {records.keys().map(|key| leptos::view! { + + }) + .collect::>()} +
- - } - }) - .to_string(), - ) +
+
+ } + })) } async fn link( @@ -190,15 +187,12 @@ async fn link( .filter(|record| record.can_be_downloaded()) { if record.can_be_downloaded() { - return Ok(Html( - leptos::ssr::render_to_string({ - let record = record.clone(); - || { - leptos::view! { } - } - }) - .into(), - )); + return Ok(Html(ssr::render({ + let record = record.clone(); + || { + leptos::view! { } + } + }))); } } } @@ -294,12 +288,9 @@ async fn upload_to_zip( .status(200) .header("Content-Type", "text/html") .header("HX-Push-Url", format!("/link/{}", &id)) - .body( - leptos::ssr::render_to_string(|| { - leptos::view! { } - }) - .into(), - ) + .body(ssr::render(|| { + leptos::view! { } + })) .unwrap(); Ok(response) diff --git a/src/ssr.rs b/src/ssr.rs new file mode 100644 index 0000000..5943967 --- /dev/null +++ b/src/ssr.rs @@ -0,0 +1,7 @@ +pub fn render(f: F) -> String +where + F: FnOnce() -> N + 'static, + N: leptos::IntoView, +{ + leptos::ssr::render_to_string(f).to_string() +}