Compare commits
37 Commits
148-create
...
153-fix-en
Author | SHA1 | Date | |
---|---|---|---|
91cd6737f9 | |||
1a1516ff92 | |||
c9d3053c5a
|
|||
aced8723c2 | |||
ede248d961
|
|||
930618dcad
|
|||
9b48fc0204 | |||
dfbb217988 | |||
954cc0edce | |||
e5ce0eab76 | |||
45eb7191f0 | |||
21a17a8eb5 | |||
fcd987d433 | |||
dd14aa0b4d | |||
3b6035dd71 | |||
22cee4a265 | |||
b25cb4549c | |||
73b4b7674e | |||
3d1dc94b06 | |||
d8fab0e068 | |||
568f6ada0e | |||
7a1ffaad47 | |||
f1affc66bc | |||
e60243e50c | |||
ff24f68eed | |||
6aa933be09 | |||
fe1b76e6e4 | |||
acf15961cd | |||
df01bafbd1 | |||
2d7b91413b | |||
c2ebd8307f | |||
2be665c549 | |||
f104a14f98 | |||
f78066d7a8 | |||
071dcad0cc | |||
3149f65a97 | |||
ab50826d31 |
@ -3,7 +3,7 @@ name: libretunes
|
||||
services:
|
||||
libretunes:
|
||||
container_name: libretunes
|
||||
# image: registry.mregirouard.com/libretunes/libretunes:latest
|
||||
# image: git.libretunes.xyz/libretunes/libretunes:latest
|
||||
build: .
|
||||
ports:
|
||||
- "3000:3000"
|
||||
|
@ -1,11 +1,14 @@
|
||||
use crate::models::Artist;
|
||||
use crate::components::dashboard_tile::DashboardTile;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
/// Holds information about an album
|
||||
///
|
||||
/// Intended to be used in the front-end
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct AlbumData {
|
||||
/// Album id
|
||||
pub id: i32,
|
||||
@ -36,4 +39,4 @@ impl DashboardTile for AlbumData {
|
||||
fn description(&self) -> Option<String> {
|
||||
Some(format!("Album • {}", Artist::display_list(&self.artists)))
|
||||
}
|
||||
}
|
||||
}
|
33
src/api/album.rs
Normal file
33
src/api/album.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use leptos::*;
|
||||
use crate::albumdata::AlbumData;
|
||||
use crate::songdata::SongData;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use leptos::server_fn::error::NoCustomError;
|
||||
use crate::database::get_db_conn;
|
||||
}
|
||||
}
|
||||
|
||||
#[server(endpoint = "album/get")]
|
||||
pub async fn get_album(id: i32) -> Result<AlbumData, ServerFnError> {
|
||||
use crate::models::Album;
|
||||
let db_con = &mut get_db_conn();
|
||||
let album = Album::get_album_data(id,db_con)
|
||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
||||
Ok(album)
|
||||
}
|
||||
|
||||
#[server(endpoint = "album/get_songs")]
|
||||
pub async fn get_songs(id: i32) -> Result<Vec<SongData>, ServerFnError> {
|
||||
use crate::models::Album;
|
||||
use crate::auth::get_logged_in_user;
|
||||
let user = get_logged_in_user().await?;
|
||||
let db_con = &mut get_db_conn();
|
||||
// TODO: NEEDS SONG DATA QUERIES
|
||||
let songdata = Album::get_song_data(id,user,db_con)
|
||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting song data: {}", e)))?;
|
||||
Ok(songdata)
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod history;
|
||||
pub mod profile;
|
||||
pub mod songs;
|
||||
pub mod album;
|
||||
|
@ -7,6 +7,7 @@ use leptos_router::*;
|
||||
use crate::pages::login::*;
|
||||
use crate::pages::signup::*;
|
||||
use crate::pages::profile::*;
|
||||
use crate::pages::albumpage::*;
|
||||
use crate::error_template::{AppError, ErrorTemplate};
|
||||
use crate::util::state::GlobalState;
|
||||
|
||||
@ -44,6 +45,7 @@ pub fn App() -> impl IntoView {
|
||||
<Route path="search" view=Search />
|
||||
<Route path="user/:id" view=Profile />
|
||||
<Route path="user" view=Profile />
|
||||
<Route path="album/:id" view=AlbumPage />
|
||||
</Route>
|
||||
<Route path="/login" view=Login />
|
||||
<Route path="/signup" view=Signup />
|
||||
|
@ -87,6 +87,7 @@ pub async fn logout() -> Result<(), ServerFnError> {
|
||||
auth_session.logout().await
|
||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
|
||||
|
||||
leptos_axum::redirect("/login");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -8,3 +8,4 @@ pub mod upload;
|
||||
pub mod song_list;
|
||||
pub mod loading;
|
||||
pub mod error;
|
||||
pub mod album_info;
|
25
src/components/album_info.rs
Normal file
25
src/components/album_info.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use crate::albumdata::AlbumData;
|
||||
|
||||
#[component]
|
||||
pub fn AlbumInfo(albumdata: AlbumData) -> impl IntoView {
|
||||
view! {
|
||||
<div class="album-info">
|
||||
<img class="album-image" src={albumdata.image_path} alt="dashboard-tile" />
|
||||
<div class="album-body">
|
||||
<p class="album-title">{albumdata.title}</p>
|
||||
<div class="album-artists">
|
||||
{
|
||||
albumdata.artists.iter().map(|artist| {
|
||||
view! {
|
||||
<a class="album-artist" href={format!("/artist/{}", artist.id.unwrap())}>{artist.name.clone()}</a>
|
||||
}
|
||||
}).collect::<Vec<_>>()
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}.into_view()
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use crate::auth::logout;
|
||||
use crate::util::state::GlobalState;
|
||||
|
||||
#[component]
|
||||
pub fn Personal() -> impl IntoView {
|
||||
@ -14,18 +16,66 @@ pub fn Personal() -> impl IntoView {
|
||||
#[component]
|
||||
pub fn Profile() -> impl IntoView {
|
||||
let (dropdown_open, set_dropdown_open) = create_signal(false);
|
||||
|
||||
let open_dropdown = move |_| {
|
||||
let user = GlobalState::logged_in_user();
|
||||
|
||||
let open_dropdown = move |_| {
|
||||
set_dropdown_open.update(|value| *value = !*value);
|
||||
log!("opened dropdown");
|
||||
};
|
||||
|
||||
let user_profile_picture = move || {
|
||||
user.get().and_then(|user| {
|
||||
if let Some(user) = user {
|
||||
if user.id.is_none() {
|
||||
return None;
|
||||
}
|
||||
Some(format!("/assets/images/profile/{}.webp", user.id.unwrap()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
view! {
|
||||
<div class="profile-container">
|
||||
<div class="profile-name">
|
||||
<Suspense
|
||||
fallback=|| view!{
|
||||
<h1>Not Logged In</h1>
|
||||
}>
|
||||
<Show
|
||||
when=move || user.get().map(|user| user.is_some()).unwrap_or(false)
|
||||
fallback=|| view!{
|
||||
<h1>Not Logged In</h1>
|
||||
}>
|
||||
<h1>{move || user.get().map(|user| user.map(|user| user.username))}</h1>
|
||||
</Show>
|
||||
</Suspense>
|
||||
</div>
|
||||
<div class="profile-icon" on:click=open_dropdown>
|
||||
<Icon icon=icondata::CgProfile />
|
||||
<Suspense fallback=|| view! { <Icon icon=icondata::CgProfile width="45" height="45"/> }>
|
||||
<Show
|
||||
when=move || user.get().map(|user| user.is_some()).unwrap_or(false)
|
||||
fallback=|| view! { <Icon icon=icondata::CgProfile width="45" height="45"/> }
|
||||
>
|
||||
<object class="profile-image" data={user_profile_picture} type="image/webp">
|
||||
<Icon class="profile-image" icon=icondata::CgProfile width="45" height="45"/>
|
||||
</object>
|
||||
</Show>
|
||||
</Suspense>
|
||||
</div>
|
||||
<div class="dropdown-container" style={move || if dropdown_open() {"display: flex"} else {"display: none"}}>
|
||||
<DropDownNotLoggedIn />
|
||||
<Suspense
|
||||
fallback=|| view!{
|
||||
<DropDownNotLoggedIn />
|
||||
}>
|
||||
<Show
|
||||
when=move || user.get().map(|user| user.is_some()).unwrap_or(false)
|
||||
fallback=|| view!{
|
||||
<DropDownNotLoggedIn />
|
||||
}>
|
||||
<DropDownLoggedIn />
|
||||
</Show>
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@ -33,10 +83,33 @@ pub fn Profile() -> impl IntoView {
|
||||
#[component]
|
||||
pub fn DropDownNotLoggedIn() -> impl IntoView {
|
||||
view! {
|
||||
<div class="dropdown-not-logged">
|
||||
<h1>Not Logged in!</h1>
|
||||
<div class="dropdown-logged">
|
||||
<h1>Not Logged In</h1>
|
||||
<a href="/login"><button class="auth-button">Log In</button></a>
|
||||
<a href="/signup"><button class="auth-button">Sign up</button></a>
|
||||
<a href="/signup"><button class="auth-button">Sign Up</button></a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
#[component]
|
||||
pub fn DropDownLoggedIn() -> impl IntoView {
|
||||
|
||||
let logout = move |_| {
|
||||
spawn_local(async move {
|
||||
let result = logout().await;
|
||||
if let Err(err) = result {
|
||||
log!("Error logging out: {:?}", err);
|
||||
} else {
|
||||
let user = GlobalState::logged_in_user();
|
||||
user.refetch();
|
||||
log!("Logged out successfully");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
view! {
|
||||
<div class="dropdown-logged">
|
||||
<h1>"Logged In"</h1>
|
||||
<button on:click=logout class="auth-button">Log Out</button>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
153
src/models.rs
153
src/models.rs
@ -6,8 +6,10 @@ use cfg_if::cfg_if;
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use diesel::prelude::*;
|
||||
use crate::database::PgPooledConn;
|
||||
use crate::database::*;
|
||||
use std::error::Error;
|
||||
use crate::songdata::SongData;
|
||||
use crate::albumdata::AlbumData;
|
||||
}
|
||||
}
|
||||
|
||||
@ -498,7 +500,7 @@ impl Album {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get songs by this artist from the database
|
||||
/// Get songs by this album from the database
|
||||
///
|
||||
/// The `id` field of this album must be present (Some) to get songs
|
||||
///
|
||||
@ -525,6 +527,153 @@ impl Album {
|
||||
|
||||
Ok(my_songs)
|
||||
}
|
||||
|
||||
/// Obtain an album from its albumid
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `album_id` - The id of the album to select
|
||||
/// * `conn` - A mutable reference to a database connection
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Album, Box<dyn Error>>` - A result indicating success with the desired album, or an error
|
||||
///
|
||||
#[cfg(feature = "ssr")]
|
||||
pub fn get_album_data(album_id: i32, conn: &mut PgPooledConn) -> Result<AlbumData, Box<dyn Error>> {
|
||||
use crate::schema::*;
|
||||
|
||||
let album: Vec<(Album, std::option::Option<Artist>)> = albums::table
|
||||
.find(album_id)
|
||||
.left_join(songs::table.on(albums::id.nullable().eq(songs::album_id)))
|
||||
.left_join(song_artists::table.inner_join(artists::table).on(songs::id.eq(song_artists::song_id)))
|
||||
.select((
|
||||
albums::all_columns,
|
||||
artists::all_columns.nullable()
|
||||
))
|
||||
.distinct()
|
||||
.load(conn)?;
|
||||
|
||||
let mut artist_list: Vec<Artist> = Vec::new();
|
||||
|
||||
for (_, artist) in album {
|
||||
if let Some(artist) = artist {
|
||||
artist_list.push(artist);
|
||||
}
|
||||
}
|
||||
// Get info of album
|
||||
let albuminfo = albums::table
|
||||
.filter(albums::id.eq(album_id))
|
||||
.first::<Album>(conn)?;
|
||||
|
||||
let img = albuminfo.image_path.unwrap_or("/assets/images/placeholders/MusicPlaceholder.svg".to_string());
|
||||
|
||||
let albumdata = AlbumData {
|
||||
id: albuminfo.id.unwrap(),
|
||||
title: albuminfo.title,
|
||||
artists: artist_list,
|
||||
release_date: albuminfo.release_date,
|
||||
image_path: img
|
||||
};
|
||||
|
||||
Ok(albumdata)
|
||||
}
|
||||
|
||||
/// Obtain an album from its albumid
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `album_id` - The id of the album to select
|
||||
/// * `conn` - A mutable reference to a database connection
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Album, Box<dyn Error>>` - A result indicating success with the desired album, or an error
|
||||
///
|
||||
#[cfg(feature = "ssr")]
|
||||
pub fn get_song_data(album_id: i32, user_like_dislike: Option<User>, conn: &mut PgPooledConn) -> Result<Vec<SongData>, Box<dyn Error>> {
|
||||
use crate::schema::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
let song_list = if let Some(user_like_dislike) = user_like_dislike {
|
||||
let user_like_dislike_id = user_like_dislike.id.unwrap();
|
||||
let song_list: Vec<(Album, Option<Song>, Option<Artist>, Option<(i32, i32)>, Option<(i32, i32)>)> =
|
||||
albums::table
|
||||
.find(album_id)
|
||||
.left_join(songs::table.on(albums::id.nullable().eq(songs::album_id)))
|
||||
.left_join(song_artists::table.inner_join(artists::table).on(songs::id.eq(song_artists::song_id)))
|
||||
.left_join(song_likes::table.on(songs::id.eq(song_likes::song_id).and(song_likes::user_id.eq(user_like_dislike_id))))
|
||||
.left_join(song_dislikes::table.on(songs::id.eq(song_dislikes::song_id).and(song_dislikes::user_id.eq(user_like_dislike_id))))
|
||||
.select((
|
||||
albums::all_columns,
|
||||
songs::all_columns.nullable(),
|
||||
artists::all_columns.nullable(),
|
||||
song_likes::all_columns.nullable(),
|
||||
song_dislikes::all_columns.nullable()
|
||||
))
|
||||
.order(songs::track.asc())
|
||||
.load(conn)?;
|
||||
song_list
|
||||
} else {
|
||||
let song_list: Vec<(Album, Option<Song>, Option<Artist>)> =
|
||||
albums::table
|
||||
.find(album_id)
|
||||
.left_join(songs::table.on(albums::id.nullable().eq(songs::album_id)))
|
||||
.left_join(song_artists::table.inner_join(artists::table).on(songs::id.eq(song_artists::song_id)))
|
||||
.select((
|
||||
albums::all_columns,
|
||||
songs::all_columns.nullable(),
|
||||
artists::all_columns.nullable()
|
||||
))
|
||||
.order(songs::track.asc())
|
||||
.load(conn)?;
|
||||
|
||||
let song_list: Vec<(Album, Option<Song>, Option<Artist>, Option<(i32, i32)>, Option<(i32, i32)>)> =
|
||||
song_list.into_iter().map( |(album, song, artist)| (album, song, artist, None, None) ).collect();
|
||||
song_list
|
||||
};
|
||||
|
||||
let mut album_songs: HashMap<i32, SongData> = HashMap::with_capacity(song_list.len());
|
||||
|
||||
for (album, song, artist, like, dislike) in song_list {
|
||||
if let Some(song) = song {
|
||||
if let Some(stored_songdata) = album_songs.get_mut(&song.id.unwrap()) {
|
||||
// If the song is already in the map, update the artists
|
||||
if let Some(artist) = artist {
|
||||
stored_songdata.artists.push(artist);
|
||||
}
|
||||
} else {
|
||||
let like_dislike = match (like, dislike) {
|
||||
(Some(_), Some(_)) => Some((true, true)),
|
||||
(Some(_), None) => Some((true, false)),
|
||||
(None, Some(_)) => Some((false, true)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let image_path = song.image_path.unwrap_or(
|
||||
album.image_path.clone().unwrap_or("/assets/images/placeholders/MusicPlaceholder.svg".to_string()));
|
||||
|
||||
let songdata = SongData {
|
||||
id: song.id.unwrap(),
|
||||
title: song.title,
|
||||
artists: artist.map(|artist| vec![artist]).unwrap_or_default(),
|
||||
album: Some(album),
|
||||
track: song.track,
|
||||
duration: song.duration,
|
||||
release_date: song.release_date,
|
||||
song_path: song.storage_path,
|
||||
image_path: image_path,
|
||||
like_dislike: like_dislike,
|
||||
};
|
||||
|
||||
album_songs.insert(song.id.unwrap(), songdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the songs by date
|
||||
let mut songdata: Vec<SongData> = album_songs.into_values().collect();
|
||||
songdata.sort_by(|a, b| b.track.cmp(&a.track));
|
||||
Ok(songdata)
|
||||
}
|
||||
}
|
||||
|
||||
/// Model for a song
|
||||
|
@ -1,3 +1,4 @@
|
||||
pub mod login;
|
||||
pub mod signup;
|
||||
pub mod profile;
|
||||
pub mod albumpage;
|
||||
|
87
src/pages/albumpage.rs
Normal file
87
src/pages/albumpage.rs
Normal file
@ -0,0 +1,87 @@
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_router::*;
|
||||
use crate::components::song_list::*;
|
||||
use crate::api::album::*;
|
||||
use crate::components::album_info::*;
|
||||
|
||||
|
||||
#[derive(Params, PartialEq)]
|
||||
struct AlbumParams {
|
||||
id: i32
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn AlbumPage() -> impl IntoView {
|
||||
let params = use_params::<AlbumParams>();
|
||||
|
||||
let id = move || {params.with(|params| {
|
||||
params.as_ref()
|
||||
.map(|params| params.id)
|
||||
.map_err(|e| e.clone())
|
||||
})
|
||||
};
|
||||
|
||||
let song_list = create_resource(
|
||||
id,
|
||||
|value| async move {
|
||||
match value {
|
||||
Ok(v) => {get_songs(v).await},
|
||||
Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let albumdata = create_resource(
|
||||
id,
|
||||
|value| async move {
|
||||
match value {
|
||||
Ok(v) => {get_album(v).await},
|
||||
Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
view! {
|
||||
<div class="album-page-container">
|
||||
<div class="album-header">
|
||||
<Suspense
|
||||
fallback=move || view! { <p class="loading">"Loading..."</p> }
|
||||
>
|
||||
{move || {
|
||||
albumdata.with( |albumdata| {
|
||||
match albumdata {
|
||||
Some(Ok(s)) => {
|
||||
view! { <AlbumInfo albumdata=(*s).clone() /> }
|
||||
},
|
||||
Some(Err(e)) => {
|
||||
view! { <div class="error">{format!("Error loading album : {}",e)}</div> }.into_view()
|
||||
},
|
||||
None => {view! { }.into_view()}
|
||||
}
|
||||
})
|
||||
}}
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
<Suspense
|
||||
fallback=move || view! { <p class="loading">"Loading..."</p> }
|
||||
>
|
||||
{move || {
|
||||
song_list.with( |song_list| {
|
||||
match song_list {
|
||||
Some(Ok(s)) => {
|
||||
view! { <SongList songs=(*s).clone()/> }
|
||||
},
|
||||
Some(Err(e)) => {
|
||||
view! { <div class="error">{format!("Error loading albums: : {}",e)}</div> }.into_view()
|
||||
},
|
||||
None => {view! { }.into_view()}
|
||||
}
|
||||
})
|
||||
}}
|
||||
</Suspense>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use crate::users::UserCredentials;
|
||||
use crate::components::loading::Loading;
|
||||
|
||||
#[component]
|
||||
pub fn Login() -> impl IntoView {
|
||||
@ -12,10 +13,14 @@ pub fn Login() -> impl IntoView {
|
||||
|
||||
let (show_password, set_show_password) = create_signal(false);
|
||||
|
||||
let toggle_password = move |_| {
|
||||
let loading = create_rw_signal(false);
|
||||
let error_msg = create_rw_signal(None);
|
||||
|
||||
let toggle_password = move |ev: leptos::ev::MouseEvent| {
|
||||
ev.prevent_default();
|
||||
set_show_password.update(|show_password| *show_password = !*show_password);
|
||||
log!("showing password");
|
||||
};
|
||||
log!("Password visibility toggled");
|
||||
};
|
||||
|
||||
let on_submit = move |ev: leptos::ev::SubmitEvent| {
|
||||
ev.prevent_default();
|
||||
@ -24,6 +29,9 @@ pub fn Login() -> impl IntoView {
|
||||
let password1 = password.get();
|
||||
|
||||
spawn_local(async move {
|
||||
loading.set(true);
|
||||
error_msg.set(None);
|
||||
|
||||
let user_credentials = UserCredentials {
|
||||
username_or_email: username_or_email1,
|
||||
password: password1
|
||||
@ -35,6 +43,7 @@ pub fn Login() -> impl IntoView {
|
||||
if let Err(err) = login_result {
|
||||
// Handle the error here, e.g., log it or display to the user
|
||||
log!("Error logging in: {:?}", err);
|
||||
error_msg.set(Some(err.to_string()));
|
||||
|
||||
// Since we're not sure what the state is, manually refetch the user
|
||||
user.refetch();
|
||||
@ -48,10 +57,13 @@ pub fn Login() -> impl IntoView {
|
||||
log!("Navigated to home page after login");
|
||||
} else if let Ok(None) = login_result {
|
||||
log!("Invalid username or password");
|
||||
error_msg.set(Some("Invalid username or password".to_string()));
|
||||
|
||||
// User could be already logged in or not, so refetch the user
|
||||
user.refetch();
|
||||
}
|
||||
|
||||
loading.set(false);
|
||||
});
|
||||
};
|
||||
|
||||
@ -83,20 +95,26 @@ pub fn Login() -> impl IntoView {
|
||||
/>
|
||||
<span>Password</span>
|
||||
<i></i>
|
||||
<Show
|
||||
when=move || {show_password() == false}
|
||||
fallback=move || view!{ <button on:click=toggle_password class="login-password-visibility">
|
||||
<Icon icon=icondata::AiEyeInvisibleFilled />
|
||||
</button> /> }
|
||||
<Show when=move || { show_password() == false }
|
||||
fallback=move || view! {
|
||||
<button on:click=toggle_password class="login-password-visibility">
|
||||
<Icon icon=icondata::AiEyeInvisibleFilled />
|
||||
</button>
|
||||
}
|
||||
>
|
||||
<button on:click=toggle_password class="login-password-visibility">
|
||||
<Icon icon=icondata::AiEyeFilled />
|
||||
</button>
|
||||
|
||||
</Show>
|
||||
<button on:click=toggle_password class="login-password-visibility">
|
||||
<Icon icon=icondata::AiEyeFilled />
|
||||
</button>
|
||||
</Show>
|
||||
</div>
|
||||
<a href="" class="forgot-pw">Forgot Password?</a>
|
||||
<input type="submit" value="Login" />
|
||||
<div class="error-msg" >{ move || error_msg.get() }</div>
|
||||
<Show
|
||||
when=move || !loading.get()
|
||||
fallback=move || view! { <Loading /> }
|
||||
>
|
||||
<input type="submit" value="Login" />
|
||||
</Show>
|
||||
<span class="go-to-signup">
|
||||
New here? <a href="/signup">Create an Account</a>
|
||||
</span>
|
||||
|
@ -4,6 +4,7 @@ use crate::util::state::GlobalState;
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use crate::components::loading::Loading;
|
||||
|
||||
#[component]
|
||||
pub fn Signup() -> impl IntoView {
|
||||
@ -13,6 +14,9 @@ pub fn Signup() -> impl IntoView {
|
||||
|
||||
let (show_password, set_show_password) = create_signal(false);
|
||||
|
||||
let loading = create_rw_signal(false);
|
||||
let error_msg = create_rw_signal(None);
|
||||
|
||||
let toggle_password = move |_| {
|
||||
set_show_password.update(|show_password| *show_password = !*show_password);
|
||||
log!("showing password");
|
||||
@ -30,12 +34,16 @@ pub fn Signup() -> impl IntoView {
|
||||
};
|
||||
log!("new user: {:?}", new_user);
|
||||
|
||||
loading.set(true);
|
||||
error_msg.set(None);
|
||||
|
||||
let user = GlobalState::logged_in_user();
|
||||
|
||||
spawn_local(async move {
|
||||
if let Err(err) = signup(new_user.clone()).await {
|
||||
// Handle the error here, e.g., log it or display to the user
|
||||
log!("Error signing up: {:?}", err);
|
||||
error_msg.set(Some(err.to_string()));
|
||||
|
||||
// Since we're not sure what the state is, manually refetch the user
|
||||
user.refetch();
|
||||
@ -49,6 +57,8 @@ pub fn Signup() -> impl IntoView {
|
||||
leptos_router::use_navigate()("/", Default::default());
|
||||
log!("Navigated to home page after signup")
|
||||
}
|
||||
|
||||
loading.set(false);
|
||||
});
|
||||
};
|
||||
|
||||
@ -99,7 +109,13 @@ pub fn Signup() -> impl IntoView {
|
||||
</button>
|
||||
</Show>
|
||||
</div>
|
||||
<input type="submit" value="Sign Up" />
|
||||
<div class="error-msg">{ move || error_msg.get() }</div>
|
||||
<Show
|
||||
when=move || !loading.get()
|
||||
fallback=move || view!{ <Loading /> }
|
||||
>
|
||||
<input type="submit" value="Sign Up" />
|
||||
</Show>
|
||||
<span class="go-to-login">
|
||||
Already Have an Account? <a href="/login" class="link" >Go to Login</a>
|
||||
</span>
|
||||
|
@ -450,7 +450,7 @@ fn QueueToggle() -> impl IntoView {
|
||||
log!("queue button pressed, queue status: {:?}",
|
||||
GlobalState::play_status().with_untracked(|status| status.queue_open));
|
||||
};
|
||||
|
||||
|
||||
// We use this to prevent the buttons from being focused when clicked
|
||||
// If buttons were focused on clicks, then pressing space bar to play/pause would "click" the button
|
||||
// and trigger unwanted behavior
|
||||
|
@ -117,7 +117,7 @@ pub async fn validate_user(credentials: UserCredentials) -> Result<Option<User>,
|
||||
|
||||
/// Get a user from the database by username or email
|
||||
/// Returns a Result with the user if found, None if not found, or an error if there was a problem
|
||||
#[server(endpoint = "get_user")]
|
||||
#[server(endpoint = "find_user")]
|
||||
pub async fn get_user(username_or_email: String) -> Result<Option<User>, ServerFnError> {
|
||||
let mut user = find_user(username_or_email).await?;
|
||||
|
||||
|
80
style/album_page.scss
Normal file
80
style/album_page.scss
Normal file
@ -0,0 +1,80 @@
|
||||
@import 'theme.scss';
|
||||
|
||||
.album-page-container {
|
||||
width: 90vw;
|
||||
|
||||
.album-header {
|
||||
height: 40vh;
|
||||
width: 65vw;
|
||||
margin: auto;
|
||||
|
||||
|
||||
padding:20px;
|
||||
|
||||
background-image: linear-gradient($accent-color, $background-color);
|
||||
border-radius: 15px;
|
||||
|
||||
.album-info {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.album-info {
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
justify-content: space-around;
|
||||
|
||||
.album-image {
|
||||
max-width: 80%;
|
||||
max-height: 80%;
|
||||
box-shadow: 10px 10px 50px -10px $background-color;
|
||||
}
|
||||
|
||||
.album-body {
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
justify-content: center;
|
||||
|
||||
.album-title {
|
||||
color: $text-controls-color;
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
margin:15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.album-artists {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
justify-content: space-around;
|
||||
align-content: space-around;
|
||||
margin:15px;
|
||||
|
||||
color: $text-controls-color;
|
||||
font-size: 20px;
|
||||
|
||||
.album-artist {
|
||||
margin: 5px;
|
||||
text-align: center;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
color: $text-controls-color;
|
||||
}
|
||||
a:visited {
|
||||
color: $text-controls-color;
|
||||
}
|
||||
a:hover {
|
||||
color: $controls-hover-color;
|
||||
}
|
||||
|
||||
a:active {
|
||||
color: $controls-click-color;
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 27rem;
|
||||
height: 30rem;
|
||||
height: 31rem;
|
||||
transform: translate(-50%, -50%);
|
||||
background: $auth-containers;
|
||||
z-index: 1;
|
||||
@ -96,6 +96,17 @@
|
||||
color: #fff;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.login-form .error-msg {
|
||||
color: $error-color;
|
||||
margin-top: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
.login-form .loading {
|
||||
margin-top: 4.5rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: calc(1.5rem - 10px);
|
||||
}
|
||||
.login-form input[type="submit"] {
|
||||
margin-top: 3rem;
|
||||
width: 100%;
|
||||
|
@ -15,6 +15,7 @@
|
||||
@import 'song_list.scss';
|
||||
@import 'profile.scss';
|
||||
@import 'loading.scss';
|
||||
@import 'album_page.scss';
|
||||
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
|
@ -11,9 +11,19 @@
|
||||
border-radius: 0.4rem;
|
||||
margin: 0.2rem;
|
||||
min-height: 6rem;
|
||||
border: 2px solid rgba(89, 89, 89, 0.199);
|
||||
border: 0.2rem solid rgba(89, 89, 89, 0.199);
|
||||
padding: 0.5rem;
|
||||
|
||||
.profile-name {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: 0.5rem;
|
||||
h1 {
|
||||
font-size: 1.2rem;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.profile-icon {
|
||||
display: inline-flex;
|
||||
padding: 0.2rem;
|
||||
@ -21,17 +31,23 @@
|
||||
font-size: 2rem;
|
||||
border-radius: 50%;
|
||||
transition: all 0.3s;
|
||||
height: max-content;
|
||||
height: 45;
|
||||
width: 45;
|
||||
margin-left: auto;
|
||||
.profile-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.profile-icon:hover {
|
||||
transform: scale(1.1);
|
||||
transform: scale(1.05);
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.profile-icon:active {
|
||||
transform: scale(0.8);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
.dropdown-container {
|
||||
position: absolute;
|
||||
@ -41,10 +57,10 @@
|
||||
border-radius: 0.5rem;
|
||||
width: 10rem;
|
||||
z-index: 1;
|
||||
background-color: red;
|
||||
border: 1px solid grey;
|
||||
background-color: #1c1c1c;
|
||||
border: 0.2rem solid rgba(89, 89, 89, 0.199);
|
||||
|
||||
.dropdown-not-logged {
|
||||
.dropdown-logged {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
@ -53,21 +69,29 @@
|
||||
h1 {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
.profile-info {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
border-top: 0.2rem solid rgba(89, 89, 89, 0.199);
|
||||
border-bottom: 0.2rem solid rgba(89, 89, 89, 0.199);
|
||||
h1 {
|
||||
font-size: 1rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
}
|
||||
.auth-button {
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.5rem;
|
||||
background-color: #1c1c1c;
|
||||
border: 0.2rem solid rgba(89, 89, 89, 0.199);
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
.dropdown-container:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: -0.4rem;
|
||||
right: 0.92rem;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
transform: rotate(45deg);
|
||||
background-color: red;
|
||||
border-left: 1px solid grey;
|
||||
border-top: 1px solid grey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 27rem;
|
||||
height: 35rem;
|
||||
height: 36rem;
|
||||
transform: translate(-50%, -50%);
|
||||
background: $auth-containers;
|
||||
z-index: 1;
|
||||
@ -92,7 +92,17 @@
|
||||
.signup-form .input-box input:focus ~ i {
|
||||
height: 2.6rem;
|
||||
}
|
||||
|
||||
.signup-form .error-msg {
|
||||
color: $error-color;
|
||||
margin-top: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
.signup-form .loading {
|
||||
margin-top: 4.5rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: calc(1.5rem - 10px);
|
||||
}
|
||||
.signup-form input[type="submit"] {
|
||||
margin-top: 3.5rem;
|
||||
width: 100%;
|
||||
|
@ -10,10 +10,12 @@ $controls-click-color: #909090;
|
||||
$play-bar-background-color: #212121;
|
||||
$play-grad-start: #0a0533;
|
||||
$play-grad-end: $accent-color;
|
||||
$border-color: #7851ed;
|
||||
$queue-background-color: $play-bar-background-color;
|
||||
$error-color: red;
|
||||
|
||||
$auth-inputs: #796dd4;
|
||||
$auth-containers: white;
|
||||
|
||||
$dashboard-tile-size: 200px;
|
||||
$playbar-size: 75px;
|
||||
$playbar-size: 75px;
|
Reference in New Issue
Block a user