askama: link list view
This commit is contained in:
parent
67be18f228
commit
ffeff8a51b
8 changed files with 36 additions and 77 deletions
|
@ -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<()> {
|
||||
|
|
|
@ -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<AppState> {
|
||||
// Records views
|
||||
|
@ -24,34 +18,6 @@ pub(crate) async fn records(State(state): State<AppState>) -> impl IntoResponse
|
|||
pub async fn records_links(State(state): State<AppState>) -> impl IntoResponse {
|
||||
let records = state.records.lock().await.clone();
|
||||
|
||||
let records_list_view = records
|
||||
.keys()
|
||||
.map(|key| {
|
||||
leptos::view! {
|
||||
<li class="link-wrapper">
|
||||
<a href="/link/{key}">{key}</a>
|
||||
<button
|
||||
style="margin-left: 1em;"
|
||||
hx-target="closest .link-wrapper"
|
||||
hx-swap="outerHTML"
|
||||
hx-delete="/link/{key}"
|
||||
>
|
||||
"X"
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
})
|
||||
.collect_view();
|
||||
|
||||
Html(ssr::render(move || {
|
||||
leptos::view! {
|
||||
<HtmxPage>
|
||||
<div class="form-wrapper">
|
||||
<div class="column-container">
|
||||
<ul>{records_list_view}</ul>
|
||||
</div>
|
||||
</div>
|
||||
</HtmxPage>
|
||||
}
|
||||
}))
|
||||
let record_keys: Vec<String> = records.keys().cloned().collect();
|
||||
LinkListTemplate { record_keys }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
pub mod headers;
|
||||
pub mod logging;
|
||||
pub mod ssr;
|
||||
pub mod sweeper;
|
||||
|
||||
use rand::{
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
pub fn render<F, N>(f: F) -> String
|
||||
where
|
||||
F: FnOnce() -> N + 'static,
|
||||
N: leptos::IntoView,
|
||||
{
|
||||
leptos::ssr::render_to_string(f).to_string()
|
||||
}
|
|
@ -41,3 +41,10 @@ impl DownloadLinkFragment {
|
|||
get_remaining_text(downloads_remaining)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "linklist.html")]
|
||||
pub struct LinkListTemplate {
|
||||
pub record_keys: Vec<String>,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
use leptos::{component, view, Children, IntoView};
|
||||
|
||||
#[component]
|
||||
pub fn HtmxPage(children: Children) -> impl IntoView {
|
||||
view! {
|
||||
<head>
|
||||
<title>"Nyazoom"</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link href="/css/main.css" rel="stylesheet" />
|
||||
<link href="/css/link.css" rel="stylesheet" />
|
||||
<script src="/scripts/file_label.js" />
|
||||
<script src="/scripts/link.js" />
|
||||
<script
|
||||
src="https://unpkg.com/htmx.org@2.0.2"
|
||||
integrity="sha384-Y7hw+L/jvKeWIRRkqWYfPcvVxHzVzn5REgzbawhxAuQGwX1XWe70vji+VSeHOThJ"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>"NyaZoom"<sup>"2"</sup></h1>
|
||||
{children()}
|
||||
</body>
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
23
templates/linklist.html
Normal file
23
templates/linklist.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="form-wrapper">
|
||||
<div class="column-container">
|
||||
<ul>
|
||||
{% for key in record_keys %}
|
||||
<li class="link-wrapper">
|
||||
<a href="/link/{{ key }}">{{ key }}</a>
|
||||
<button
|
||||
style="margin-left: 1em;"
|
||||
hx-target="closest .link-wrapper"
|
||||
hx-swap="outerHTML"
|
||||
hx-delete="/link/{{ key }}"
|
||||
>
|
||||
"X"
|
||||
</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
Loading…
Reference in a new issue