From 21387e08345bc54eb1218d16af64ce01c125ab0c Mon Sep 17 00:00:00 2001 From: Sijmen Date: Thu, 27 Apr 2023 04:35:48 +0200 Subject: [PATCH] Replace template includes with htmx hx-gets --- src/main.rs | 33 ++------------------------------- templates/browser.html | 27 ++++++++++++++++++++------- templates/index.html | 15 ++++++--------- 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/main.rs b/src/main.rs index be60c35..9448c41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,13 +14,7 @@ mod mpd; #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate { - path: Vec, - entries: Vec, - - song: Option, - name: Option, - - queue: Vec, + path: String, } #[derive(Deserialize, Default)] @@ -31,30 +25,7 @@ struct IndexQuery { async fn get_index(req: tide::Request<()>) -> tide::Result { let query: IndexQuery = req.query()?; - let entries = mpd::ls(&query.path)?; - let queue = mpd::playlist()?; - - // TODO dry - let mut mpd = mpd::connect()?; - let song = mpd.currentsong()?; - - let name = if let Some(song) = &song { - let name = song.title.as_ref().unwrap_or(&song.file).to_string(); - Some(name) - } else { - None - }; - - let template = IndexTemplate { - path: Path::new(&query.path) - .iter() - .map(|s| s.to_string_lossy().to_string()) - .collect(), - entries, - name, - song, - queue, - }; + let template = IndexTemplate { path: query.path }; Ok(askama_tide::into_response(&template)) } diff --git a/templates/browser.html b/templates/browser.html index 11348b0..843e96c 100644 --- a/templates/browser.html +++ b/templates/browser.html @@ -1,14 +1,23 @@ {# #}