From ffeff8a51b7db8be0e33fea5684969271971b965 Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Thu, 14 Nov 2024 07:33:36 -0800 Subject: [PATCH] askama: link list view --- src/main.rs | 4 ++-- src/router/records.rs | 42 ++++------------------------------------- src/util/mod.rs | 1 - src/util/ssr.rs | 7 ------- src/views/askama.rs | 7 +++++++ src/views/base_page.rs | 26 ------------------------- src/views/mod.rs | 3 --- templates/linklist.html | 23 ++++++++++++++++++++++ 8 files changed, 36 insertions(+), 77 deletions(-) delete mode 100644 src/util/ssr.rs delete mode 100644 src/views/base_page.rs create mode 100644 templates/linklist.html diff --git a/src/main.rs b/src/main.rs index e6884f6..86e8570 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use axum::{ extract::{ConnectInfo, Request}, middleware::{self, Next}, - response::{Html, IntoResponse}, + response::IntoResponse, routing::get, Router, }; @@ -12,7 +12,7 @@ use std::{io, net::SocketAddr}; use nyazoom::*; -use util::{headers::ForwardedFor, logging, ssr, sweeper}; +use util::{headers::ForwardedFor, logging, sweeper}; #[tokio::main] async fn main() -> io::Result<()> { diff --git a/src/router/records.rs b/src/router/records.rs index 9d3338a..7a283d8 100644 --- a/src/router/records.rs +++ b/src/router/records.rs @@ -1,12 +1,6 @@ -use axum::{ - extract::State, - response::{Html, IntoResponse}, - routing::get, - Json, Router, -}; -use leptos::CollectView; +use axum::{extract::State, response::IntoResponse, routing::get, Json, Router}; -use crate::{util::ssr, AppState, HtmxPage}; +use crate::{askama::LinkListTemplate, AppState}; pub fn get_records_router() -> Router { // Records views @@ -24,34 +18,6 @@ pub(crate) async fn records(State(state): State) -> impl IntoResponse pub async fn records_links(State(state): State) -> impl IntoResponse { let records = state.records.lock().await.clone(); - let records_list_view = records - .keys() - .map(|key| { - leptos::view! { - - } - }) - .collect_view(); - - Html(ssr::render(move || { - leptos::view! { - -
-
-
    {records_list_view}
-
-
-
- } - })) + let record_keys: Vec = records.keys().cloned().collect(); + LinkListTemplate { record_keys } } diff --git a/src/util/mod.rs b/src/util/mod.rs index c1c9bcc..869d004 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,6 +1,5 @@ pub mod headers; pub mod logging; -pub mod ssr; pub mod sweeper; use rand::{ diff --git a/src/util/ssr.rs b/src/util/ssr.rs deleted file mode 100644 index 5943967..0000000 --- a/src/util/ssr.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub fn render(f: F) -> String -where - F: FnOnce() -> N + 'static, - N: leptos::IntoView, -{ - leptos::ssr::render_to_string(f).to_string() -} diff --git a/src/views/askama.rs b/src/views/askama.rs index 46322a8..3702baa 100644 --- a/src/views/askama.rs +++ b/src/views/askama.rs @@ -41,3 +41,10 @@ impl DownloadLinkFragment { get_remaining_text(downloads_remaining) } } + +#[derive(Template)] +#[template(path = "linklist.html")] +pub struct LinkListTemplate { + pub record_keys: Vec, +} + diff --git a/src/views/base_page.rs b/src/views/base_page.rs deleted file mode 100644 index fcab73d..0000000 --- a/src/views/base_page.rs +++ /dev/null @@ -1,26 +0,0 @@ -use leptos::{component, view, Children, IntoView}; - -#[component] -pub fn HtmxPage(children: Children) -> impl IntoView { - view! { - - "Nyazoom" - - - - - - - - -

"NyaZoom""2"

- {children()} - - } -} diff --git a/src/views/mod.rs b/src/views/mod.rs index de9b140..94897de 100644 --- a/src/views/mod.rs +++ b/src/views/mod.rs @@ -2,9 +2,6 @@ use futures::TryFutureExt; use serde::Deserialize; pub mod askama; -pub mod base_page; - -pub use base_page::*; #[derive(Debug, Deserialize)] pub struct CatFact { diff --git a/templates/linklist.html b/templates/linklist.html new file mode 100644 index 0000000..f40f6ff --- /dev/null +++ b/templates/linklist.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block content %} +
+
+
    + {% for key in record_keys %} + + {% endfor %} +
+
+
+{% endblock content %}