mini-player, header: make it persistent, add music page button and check current route
This commit is contained in:
parent
4b4044d689
commit
2ed650c3f4
11 changed files with 78 additions and 52 deletions
|
|
@ -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<crate::domain::Track>,
|
||||
}
|
||||
|
||||
#[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<Arc<AppState>>) -> 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Track>,
|
||||
}
|
||||
pub async fn miniplayer(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
||||
Html(
|
||||
MiniPlayerTemplate {
|
||||
tracks: state.mp_tracks.clone(),
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
pub mod home;
|
||||
pub mod miniplayer;
|
||||
pub mod music;
|
||||
pub mod notfound;
|
||||
|
|
|
|||
|
|
@ -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<crate::domain::Track>,
|
||||
}
|
||||
|
||||
#[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<Arc<AppState>>) -> 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue