Combine play and pause controls into one that changes depending on state
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sijmen 2023-05-01 16:25:07 +02:00
parent 700a5ad1ac
commit 38a47a4a10
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
3 changed files with 14 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 134 KiB

View file

@ -33,18 +33,21 @@ async fn get_queue(_req: tide::Request<()>) -> tide::Result {
#[derive(Template)] #[derive(Template)]
#[template(path = "player.html")] #[template(path = "player.html")]
struct CurrentTemplate { struct PlayerTemplate {
song: Option<mpdrs::Song>, song: Option<mpdrs::Song>,
name: Option<String>, name: Option<String>,
state: mpdrs::State,
} }
async fn get_player(_req: tide::Request<()>) -> tide::Result { async fn get_player(_req: tide::Request<()>) -> tide::Result {
let mut mpd = mpd::connect()?; let mut mpd = mpd::connect()?;
let song = mpd.currentsong()?; let song = mpd.currentsong()?;
let state = mpd.status()?.state;
let mut template = CurrentTemplate { let mut template = PlayerTemplate {
song: song.clone(), song: song.clone(),
name: None, name: None,
state,
}; };
if let Some(song) = song { if let Some(song) = song {

View file

@ -41,14 +41,19 @@
hx-post="/previous" hx-post="/previous"
class="control material-symbols-outlined" role="button" title="Previous track" class="control material-symbols-outlined" role="button" title="Previous track"
>skip_previous</button> >skip_previous</button>
<button
hx-post="/play" {% if state == mpdrs::State::Play %}
class="control material-symbols-outlined" role="button" title="Play"
>play_arrow</button>
<button <button
hx-post="/pause" hx-post="/pause"
class="control material-symbols-outlined" role="button" title="Pause" class="control material-symbols-outlined" role="button" title="Pause"
>pause</button> >pause</button>
{% else %}
<button
hx-post="/play"
class="control material-symbols-outlined" role="button" title="Play"
>play_arrow</button>
{% endif %}
<button <button
hx-post="/next" hx-post="/next"
class="control material-symbols-outlined" role="button" title="Next track" class="control material-symbols-outlined" role="button" title="Next track"