Working Albums Page (BETA)
This commit is contained in:
parent
7a1ffaad47
commit
568f6ada0e
@ -13,25 +13,20 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[server(endpoint = "album/get")]
|
#[server(endpoint = "album/get")]
|
||||||
// pub async fn get_album(id: Option<i32>) -> Result<Album, ServerFnError> {
|
pub async fn get_album(id: i32) -> Result<Album, ServerFnError> {
|
||||||
// let db_con = &mut get_db_conn();
|
let db_con = &mut get_db_conn();
|
||||||
// let album = Album::get_album(id,db_con)
|
let album = Album::get_album(id,db_con)
|
||||||
// .map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
||||||
// Ok(album)
|
Ok(album)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[server(endpoint = "album/get_songs")]
|
#[server(endpoint = "album/get_songs")]
|
||||||
// pub async fn get_songs(album: Option<Album>) -> Result<Vec<Song>, ServerFnError> {
|
pub async fn get_songs(id: i32) -> Result<Vec<SongData>, ServerFnError> {
|
||||||
// let db_con = &mut get_db_conn();
|
let user = get_user().await?;
|
||||||
// let songs = album.get_songs(db_con)
|
let db_con = &mut get_db_conn();
|
||||||
// .map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
// TODO: NEEDS SONG DATA QUERIES
|
||||||
// Ok(songs)
|
let songdata = Album::get_song_data(id,user.id.unwrap(),db_con)
|
||||||
// }
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting song data: {}", e)))?;
|
||||||
|
Ok(songdata)
|
||||||
// #[server(endpoint = "album/get_song_list")]
|
}
|
||||||
// pub async fn get_song_data(album: Option<Album>) -> Result<Vec<Song>, ServerFnError> {
|
|
||||||
// let user = get_user().await?;
|
|
||||||
// let db_con = &mut get_db_conn();
|
|
||||||
// // TODO: NEEDS SONG DATA QUERIES
|
|
||||||
// }
|
|
@ -43,7 +43,7 @@ pub fn App() -> impl IntoView {
|
|||||||
<Route path="" view=Dashboard />
|
<Route path="" view=Dashboard />
|
||||||
<Route path="dashboard" view=Dashboard />
|
<Route path="dashboard" view=Dashboard />
|
||||||
<Route path="search" view=Search />
|
<Route path="search" view=Search />
|
||||||
//<Route path="album/:id" view=AlbumPage />
|
<Route path="album/:id" view=AlbumPage />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/login" view=Login />
|
<Route path="/login" view=Login />
|
||||||
<Route path="/signup" view=Signup />
|
<Route path="/signup" view=Signup />
|
||||||
|
@ -540,7 +540,7 @@ impl Album {
|
|||||||
/// * `Result<Album, Box<dyn Error>>` - A result indicating success with the desired album, or an error
|
/// * `Result<Album, Box<dyn Error>>` - A result indicating success with the desired album, or an error
|
||||||
///
|
///
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub fn get_album(album_id: i32, user_id: i32, conn: &mut PgPooledConn) -> Result<Album, Box<dyn Error>> {
|
pub fn get_album(album_id: i32, conn: &mut PgPooledConn) -> Result<Album, Box<dyn Error>> {
|
||||||
use crate::schema::albums::dsl::*;
|
use crate::schema::albums::dsl::*;
|
||||||
use crate::database::get_db_conn;
|
use crate::database::get_db_conn;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ use leptos::*;
|
|||||||
use leptos_router::*;
|
use leptos_router::*;
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
use crate::components::song_list::*;
|
use crate::components::song_list::*;
|
||||||
|
use crate::api::album::*;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Params, PartialEq)]
|
#[derive(Params, PartialEq)]
|
||||||
@ -10,7 +11,6 @@ struct AlbumParams {
|
|||||||
id: i32
|
id: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn AlbumPage() -> impl IntoView {
|
pub fn AlbumPage() -> impl IntoView {
|
||||||
let params = use_params::<AlbumParams>();
|
let params = use_params::<AlbumParams>();
|
||||||
@ -26,8 +26,8 @@ pub fn AlbumPage() -> impl IntoView {
|
|||||||
id,
|
id,
|
||||||
|value| async move {
|
|value| async move {
|
||||||
match value {
|
match value {
|
||||||
Ok(v) => {get_album(v).await},
|
Ok(v) => {get_songs(v).await},
|
||||||
Err(e) => {Err(ServerFnError::Request("Invalid album!".into()))},
|
Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -40,7 +40,7 @@ pub fn AlbumPage() -> impl IntoView {
|
|||||||
song_list.with( |song_list| {
|
song_list.with( |song_list| {
|
||||||
match song_list {
|
match song_list {
|
||||||
Some(Ok(s)) => {
|
Some(Ok(s)) => {
|
||||||
view! { <SongList songs=s.clone().into()/> }.into_view()
|
view! { <SongList songs=(*s).clone().into()/> }.into_view()
|
||||||
},
|
},
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
view! { <div>"Error loading albums: :e"</div> }.into_view()
|
view! { <div>"Error loading albums: :e"</div> }.into_view()
|
||||||
@ -52,4 +52,4 @@ pub fn AlbumPage() -> impl IntoView {
|
|||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user