mini-player: implemented
This commit is contained in:
parent
55fa3b9196
commit
36208255b2
10 changed files with 81 additions and 23 deletions
|
|
@ -3,36 +3,36 @@
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"title": "Good old times",
|
"title": "Good old times",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/times.mp3"
|
"src": "/static/assets/music/times.mp3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"title": "Identification",
|
"title": "Identification",
|
||||||
"artist": "Infinity Frequencies",
|
"artist": "Infinity Frequencies",
|
||||||
"src": "/static/music/infinity.mp3"
|
"src": "/static/assets/music/infinity.mp3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"title": "Flip the Switch",
|
"title": "Flip the Switch",
|
||||||
"artist": "Stevia Sphere",
|
"artist": "Stevia Sphere",
|
||||||
"src": "/static/music/switch.mp3"
|
"src": "/static/assets/music/switch.mp3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 4,
|
"id": 4,
|
||||||
"title": "Machines Vs Water",
|
"title": "Machines Vs Water",
|
||||||
"artist": "Stevia Sphere",
|
"artist": "Stevia Sphere",
|
||||||
"src": "/static/music/machines.mp3"
|
"src": "/static/assets/music/machines.mp3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"title": "Elevator 1",
|
"title": "Elevator 1",
|
||||||
"artist": "Stevia Sphere",
|
"artist": "Stevia Sphere",
|
||||||
"src": "/static/music/elevator.mp3"
|
"src": "/static/assets/music/elevator.mp3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
"title": "Somewhere Dark",
|
"title": "Somewhere Dark",
|
||||||
"artist": "Monodrone",
|
"artist": "Monodrone",
|
||||||
"src": "/static/music/dark.mp3"
|
"src": "/static/assets/music/dark.mp3"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -3,70 +3,70 @@
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"title": "I'm getting tired of farewells",
|
"title": "I'm getting tired of farewells",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/farewells.mp3",
|
"src": "/static/assets/music/farewells.mp3",
|
||||||
"album": "LIFE"
|
"album": "LIFE"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"title": "DAWN",
|
"title": "DAWN",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/DAWN.mp3",
|
"src": "/static/assets/music/DAWN.mp3",
|
||||||
"album": "DAWN"
|
"album": "DAWN"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"title": "Move on",
|
"title": "Move on",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/move_on.mp3",
|
"src": "/static/assets/music/move_on.mp3",
|
||||||
"album": "DAWN"
|
"album": "DAWN"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 4,
|
"id": 4,
|
||||||
"title": "Carcer",
|
"title": "Carcer",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/carcer.mp3",
|
"src": "/static/assets/music/carcer.mp3",
|
||||||
"album": "LIFE"
|
"album": "LIFE"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"title": "Under listening",
|
"title": "Under listening",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/listening.mp3",
|
"src": "/static/assets/music/listening.mp3",
|
||||||
"album": "Justice"
|
"album": "Justice"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
"title": "Fading away",
|
"title": "Fading away",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/fading.mp3",
|
"src": "/static/assets/music/fading.mp3",
|
||||||
"album": "LIFE"
|
"album": "LIFE"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 7,
|
"id": 7,
|
||||||
"title": "Hindsight",
|
"title": "Hindsight",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/hindsight.mp3",
|
"src": "/static/assets/music/hindsight.mp3",
|
||||||
"album": "The End"
|
"album": "The End"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 8,
|
"id": 8,
|
||||||
"title": "With or without",
|
"title": "With or without",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/without.mp3",
|
"src": "/static/assets/music/without.mp3",
|
||||||
"album": "Extinction"
|
"album": "Extinction"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 9,
|
"id": 9,
|
||||||
"title": "Perfect Light",
|
"title": "Perfect Light",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/perfect_light.mp3",
|
"src": "/static/assets/music/perfect_light.mp3",
|
||||||
"album": "Rebirth"
|
"album": "Rebirth"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 10,
|
"id": 10,
|
||||||
"title": "Good old times",
|
"title": "Good old times",
|
||||||
"artist": "Agahnim",
|
"artist": "Agahnim",
|
||||||
"src": "/static/music/times.mp3",
|
"src": "/static/assets/music/times.mp3",
|
||||||
"album": "Extinction"
|
"album": "Extinction"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -24,7 +24,7 @@ impl AppState {
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct Track {
|
pub struct Track {
|
||||||
title: String,
|
pub title: String,
|
||||||
artist: String,
|
pub artist: String,
|
||||||
src: String,
|
pub src: String,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use agahnim_web_v2::{
|
use agahnim_web_v2::{
|
||||||
domain::AppState,
|
domain::AppState,
|
||||||
templates::{index::home, miniplayer::miniplayer, notfound::notfound},
|
templates::{index::home, miniplayer::miniplayer, music::music, notfound::notfound},
|
||||||
};
|
};
|
||||||
use axum::{Router, routing::get};
|
use axum::{Router, routing::get};
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
@ -15,6 +15,7 @@ async fn main() {
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(home))
|
.route("/", get(home))
|
||||||
|
.route("/music", get(music))
|
||||||
.route("/miniplayer", get(miniplayer))
|
.route("/miniplayer", get(miniplayer))
|
||||||
.nest_service("/static", ServeDir::new("static"))
|
.nest_service("/static", ServeDir::new("static"))
|
||||||
.fallback(notfound)
|
.fallback(notfound)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
pub mod index;
|
pub mod index;
|
||||||
pub mod miniplayer;
|
pub mod miniplayer;
|
||||||
|
pub mod music;
|
||||||
pub mod notfound;
|
pub mod notfound;
|
||||||
|
|
|
||||||
21
src/templates/music.rs
Normal file
21
src/templates/music.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
use askama::Template;
|
||||||
|
use axum::{
|
||||||
|
http::HeaderMap,
|
||||||
|
response::{Html, IntoResponse},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "music.html")]
|
||||||
|
struct MusicTemplate;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "partials/music.html")]
|
||||||
|
struct MusicPartialTemplate;
|
||||||
|
|
||||||
|
pub async fn music(headers: HeaderMap) -> impl IntoResponse {
|
||||||
|
if headers.contains_key("hx-request") {
|
||||||
|
Html(MusicPartialTemplate.render().unwrap())
|
||||||
|
} else {
|
||||||
|
Html(MusicTemplate.render().unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,11 +12,30 @@
|
||||||
|
|
||||||
<body hx-boost="true" hx-target="#content">
|
<body hx-boost="true" hx-target="#content">
|
||||||
{% include "partials/header.html" %}
|
{% include "partials/header.html" %}
|
||||||
<!-- <div hx-get="/miniplayer" hx-trigger="load" hx-swap="outerHtml"></div> -->
|
<div id="miniplayer-container" hx-get="/miniplayer" hx-trigger="load" hx-swap="innerHTML"
|
||||||
|
hx-target="#miniplayer-container">
|
||||||
|
<miniplayer>
|
||||||
|
<h1>Chargement...</h1>
|
||||||
|
</miniplayer>
|
||||||
|
</div>
|
||||||
|
|
||||||
<main id="content">
|
<main id="content">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function updateMiniplayerVisibility() {
|
||||||
|
const isMusicPage = window.location.pathname === '/music';
|
||||||
|
const miniplayer = document.getElementById('miniplayer-container');
|
||||||
|
if (miniplayer) {
|
||||||
|
miniplayer.style.display = isMusicPage ? 'none' : '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMiniplayerVisibility();
|
||||||
|
|
||||||
|
document.body.addEventListener('htmx:afterSwap', updateMiniplayerVisibility);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
5
templates/music.html
Normal file
5
templates/music.html
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include "partials/music.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -1,3 +1,13 @@
|
||||||
<miniplayer>
|
<miniplayer>
|
||||||
<h1>Je suis un miniplayer</h1>
|
<h1>Miniplayer</h1>
|
||||||
|
{% if tracks.is_empty() %}
|
||||||
|
<p>Aucune track</p>
|
||||||
|
{% else %}
|
||||||
|
{% for track in tracks %}
|
||||||
|
<div class="track">
|
||||||
|
<p>{{ track.title }} - {{ track.artist }}</p>
|
||||||
|
<audio controls src="{{ track.src }}"></audio>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
</miniplayer>
|
</miniplayer>
|
||||||
1
templates/partials/music.html
Normal file
1
templates/partials/music.html
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<h1>y'a pas de miniplayer ici</h1>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue