diff --git a/src/main.rs b/src/main.rs index e4b72fa..d44bb95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use agahnim_web_v2::{ domain::AppState, - templates::{home::home, miniplayer::miniplayer, music::music, notfound::notfound}, + templates::{home::home, music::music, notfound::notfound}, }; use axum::{Router, routing::get}; use tower_http::services::ServeDir; @@ -16,7 +16,6 @@ async fn main() { let app = Router::new() .route("/", get(home)) .route("/music", get(music)) - .route("/miniplayer", get(miniplayer)) .nest_service("/static", ServeDir::new("static")) .fallback(notfound) .with_state(state); diff --git a/src/templates/home.rs b/src/templates/home.rs index 8cf79ee..8fa0a21 100644 --- a/src/templates/home.rs +++ b/src/templates/home.rs @@ -1,21 +1,33 @@ use askama::Template; use axum::{ + extract::State, http::HeaderMap, response::{Html, IntoResponse}, }; +use std::sync::Arc; + +use crate::domain::AppState; #[derive(Template)] #[template(path = "home.html")] -struct HomeTemplate; +struct HomeTemplate { + tracks: Vec, +} #[derive(Template)] #[template(path = "partials/home.html")] struct HomePartialTemplate; -pub async fn home(headers: HeaderMap) -> impl IntoResponse { +pub async fn home(headers: HeaderMap, state: State>) -> impl IntoResponse { if headers.contains_key("hx-request") { Html(HomePartialTemplate.render().unwrap()) } else { - Html(HomeTemplate.render().unwrap()) + Html( + HomeTemplate { + tracks: state.mp_tracks.clone(), + } + .render() + .unwrap(), + ) } } diff --git a/src/templates/miniplayer.rs b/src/templates/miniplayer.rs deleted file mode 100644 index 9b72140..0000000 --- a/src/templates/miniplayer.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::sync::Arc; - -use askama::Template; -use axum::{ - extract::State, - response::{Html, IntoResponse}, -}; - -use crate::domain::{AppState, Track}; - -#[derive(Template)] -#[template(path = "partials/miniplayer.html")] -struct MiniPlayerTemplate { - tracks: Vec, -} -pub async fn miniplayer(State(state): State>) -> impl IntoResponse { - Html( - MiniPlayerTemplate { - tracks: state.mp_tracks.clone(), - } - .render() - .unwrap(), - ) -} diff --git a/src/templates/mod.rs b/src/templates/mod.rs index 4f7ff4f..d7a6e83 100644 --- a/src/templates/mod.rs +++ b/src/templates/mod.rs @@ -1,4 +1,3 @@ pub mod home; -pub mod miniplayer; pub mod music; pub mod notfound; diff --git a/src/templates/music.rs b/src/templates/music.rs index 9337657..15c6dcd 100644 --- a/src/templates/music.rs +++ b/src/templates/music.rs @@ -1,21 +1,33 @@ use askama::Template; use axum::{ + extract::State, http::HeaderMap, response::{Html, IntoResponse}, }; +use std::sync::Arc; + +use crate::domain::AppState; #[derive(Template)] #[template(path = "music.html")] -struct MusicTemplate; +struct MusicTemplate { + tracks: Vec, +} #[derive(Template)] #[template(path = "partials/music.html")] struct MusicPartialTemplate; -pub async fn music(headers: HeaderMap) -> impl IntoResponse { +pub async fn music(headers: HeaderMap, state: State>) -> impl IntoResponse { if headers.contains_key("hx-request") { Html(MusicPartialTemplate.render().unwrap()) } else { - Html(MusicTemplate.render().unwrap()) + Html( + MusicTemplate { + tracks: state.p_tracks.clone(), + } + .render() + .unwrap(), + ) } } diff --git a/static/miniplayer.js b/static/miniplayer.js index de586d6..5240957 100644 --- a/static/miniplayer.js +++ b/static/miniplayer.js @@ -111,4 +111,3 @@ function initMiniPlayer() { } initMiniPlayer(); -document.addEventListener("htmx:afterSwap", initMiniPlayer); diff --git a/static/style.css b/static/style.css index 2cf1b39..c0d053d 100644 --- a/static/style.css +++ b/static/style.css @@ -79,13 +79,14 @@ navbar { navbar-content { display: flex; - gap: 1rem; + gap: 0.3rem; label { cursor: pointer; padding: 4px 8px; border: 2px solid black; background: var(--win-bg-grey); + border-color: #ffffff #808080 #808080 #ffffff; &:has(input:checked) { background: #ff75a7; @@ -94,8 +95,9 @@ navbar { } &:active { - border-color: #808080 #ffffff #ffffff #808080; + border-color: #ffffff #808080 #808080 #ffffff; padding: 5px 7px 3px 9px; + border-color: #808080 #ffffff #ffffff #808080; } &:hover { diff --git a/templates/base.html b/templates/base.html index fdd3916..098ea1c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,20 +12,19 @@ + - - + {% include "partials/header.html" %} - - -

Chargement...

-
+ + {% block miniplayer %}{% endblock %} +
-
- {% block content %}{% endblock %} -
+
+ {% block content %}{% endblock %} +
+
- - \ No newline at end of file + diff --git a/templates/home.html b/templates/home.html index 6797858..60927c5 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,6 +1,9 @@ {% extends "base.html" %} - {% block content %} {% include "partials/home.html" %} -{% endblock %} \ No newline at end of file +{% endblock %} + +{% block miniplayer %} +{% include "partials/miniplayer.html" %} +{% endblock %} diff --git a/templates/music.html b/templates/music.html index dceed8d..8f01d3b 100644 --- a/templates/music.html +++ b/templates/music.html @@ -3,3 +3,7 @@ {% block content %} {% include "partials/music.html" %} {% endblock %} + +{% block miniplayer %} +{% include "partials/miniplayer.html" %} +{% endblock %} diff --git a/templates/partials/header.html b/templates/partials/header.html index 0bf0cf5..b6d5f9d 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -4,5 +4,9 @@ Accueil + \ No newline at end of file