From 2f0c35d6fe15f5c0a73ee7bcb4611a23dc284f64 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Wed, 26 Apr 2023 21:14:14 +0200 Subject: [PATCH] Make UI flicker less --- src/main.rs | 21 +++++++++++++++++++++ templates/player.html | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 60395db..952b78b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,11 @@ mod mpd; struct IndexTemplate { path: Vec, entries: Vec, + + song: Option, + name: Option, + + queue: Vec, } #[derive(Deserialize, Default)] @@ -27,12 +32,28 @@ struct IndexQuery { async fn 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, }; Ok(askama_tide::into_response(&template)) } diff --git a/templates/player.html b/templates/player.html index 5a31ca4..0860406 100644 --- a/templates/player.html +++ b/templates/player.html @@ -3,7 +3,11 @@
{% if let Some(song) = song %} - +