From 0ad9383a08737c2041ba8ca125a2a001cb067f80 Mon Sep 17 00:00:00 2001 From: Aidan Westphal Date: Fri, 29 Nov 2024 23:37:16 +0000 Subject: [PATCH] Friend Page & Components --- src/app.rs | 2 + src/components.rs | 2 +- .../{user_row.rs => friend_list.rs} | 18 +++++- src/pages.rs | 1 + src/pages/friends.rs | 64 +++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) rename src/components/{user_row.rs => friend_list.rs} (62%) create mode 100644 src/pages/friends.rs diff --git a/src/app.rs b/src/app.rs index 4784702..4259cea 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,6 +8,7 @@ use crate::pages::login::*; use crate::pages::signup::*; use crate::pages::profile::*; use crate::pages::albumpage::*; +use crate::pages::friends::*; use crate::error_template::{AppError, ErrorTemplate}; use crate::util::state::GlobalState; @@ -45,6 +46,7 @@ pub fn App() -> impl IntoView { + diff --git a/src/components.rs b/src/components.rs index 646510e..662ad00 100644 --- a/src/components.rs +++ b/src/components.rs @@ -9,4 +9,4 @@ pub mod song_list; pub mod loading; pub mod error; pub mod album_info; -pub mod user_row; \ No newline at end of file +pub mod friend_list; \ No newline at end of file diff --git a/src/components/user_row.rs b/src/components/friend_list.rs similarity index 62% rename from src/components/user_row.rs rename to src/components/friend_list.rs index 5269b26..21c188e 100644 --- a/src/components/user_row.rs +++ b/src/components/friend_list.rs @@ -3,9 +3,8 @@ use leptos::*; use leptos_icons::*; use crate::frienddata::FriendData; - #[component] -pub fn UserRow(user: FriendData) -> impl IntoView { +pub fn FriendRow(user: FriendData) -> impl IntoView { view! {
@@ -19,3 +18,18 @@ pub fn UserRow(user: FriendData) -> impl IntoView {
}.into_view() } + +#[component] +pub fn FriendList(friends: Vec) -> impl IntoView { + view! { +
+ { + friends.iter().map(|friend| { + view! { + + } + }).collect::>() + } +
+ }.into_view() +} \ No newline at end of file diff --git a/src/pages.rs b/src/pages.rs index 0ad5d6f..52c6ca1 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -2,3 +2,4 @@ pub mod login; pub mod signup; pub mod profile; pub mod albumpage; +pub mod friends; \ No newline at end of file diff --git a/src/pages/friends.rs b/src/pages/friends.rs new file mode 100644 index 0000000..2a8d297 --- /dev/null +++ b/src/pages/friends.rs @@ -0,0 +1,64 @@ +use leptos::leptos_dom::*; +use leptos::*; +use leptos_router::*; +use crate::api::profile::*; +use crate::components::friend_list::*; +use crate::components::loading::Loading; + + +#[derive(Params, PartialEq)] +struct FriendParams { + id: i32 +} + +#[component] +pub fn Friends() -> impl IntoView { + let params = use_params::(); + + let id = move || {params.with(|params| { + params.as_ref() + .map(|params| params.id) + .map_err(|e| e.clone()) + }) + }; + + let friend_list = create_resource( + id, + |value| async move { + match value { + Ok(v) => {friends(v).await}, + Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))}, + } + }, + ); + + view! { +
+

"Friends:"

+ + } + > + {e.to_string()}

}) + .collect_view() + } + } + > + { + friend_list.get().map(|friend_list| { + friend_list.map(|friend_list| { + view! {} + }) + }) + } +
+
+
+ } +} +