-
Notifications
You must be signed in to change notification settings - Fork 252
Add public user section feature. #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f0cc05d
88c1abd
e4119ae
0bf6e16
0ea5003
85c9fcf
1c96801
6abed4f
54bddb6
f46d478
ec5df24
0c91841
5cc9fba
e6ff229
9c7472e
d220f76
79753e2
87e9cc5
373f76c
9474e4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ mod nav; | |
| mod playback; | ||
| mod playlist; | ||
| mod promise; | ||
| pub mod public_user; | ||
| mod recommend; | ||
| mod search; | ||
| mod show; | ||
|
|
@@ -61,7 +62,7 @@ pub use crate::data::{ | |
| user::{PublicUser, UserProfile}, | ||
| utils::{Cached, Float64, Image, Page}, | ||
| }; | ||
| use crate::ui::credits::TrackCredits; | ||
| use crate::{data::public_user::PublicUserDetail, ui::credits::TrackCredits}; | ||
|
|
||
| pub const ALERT_DURATION: Duration = Duration::from_secs(5); | ||
|
|
||
|
|
@@ -79,6 +80,7 @@ pub struct AppState { | |
| pub album_detail: AlbumDetail, | ||
| pub artist_detail: ArtistDetail, | ||
| pub playlist_detail: PlaylistDetail, | ||
| pub public_user_detail: PublicUserDetail, | ||
| pub show_detail: ShowDetail, | ||
| pub library: Arc<Library>, | ||
| pub common_ctx: Arc<CommonCtx>, | ||
|
|
@@ -170,6 +172,9 @@ impl AppState { | |
| finder: Finder::new(), | ||
| lyrics: Promise::Empty, | ||
| credits: None, | ||
| public_user_detail: PublicUserDetail { | ||
| info: Promise::Empty, | ||
| }, | ||
|
Comment on lines
+175
to
+177
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a reason to create a struct to hold only the info? Otherwise this could be just a Promise?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in case we wanted to add the ability to view all for different elements, so for example you can have all of the user playlists or artists or friends there, and that imo would be better split into different parts? |
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use druid::{im::Vector, Data, Lens}; | ||
|
|
||
| use crate::data::{Cached, MixedView, Promise, PublicUser}; | ||
|
|
||
| #[derive(Clone, Data, Lens)] | ||
| pub struct PublicUserDetail { | ||
| pub info: Promise<Cached<Arc<PublicUserInformation>>, PublicUser>, | ||
| } | ||
|
|
||
| #[derive(Clone, Data, Lens)] | ||
| pub struct PublicUserInformation { | ||
| pub uri: String, | ||
| pub name: String, | ||
| pub image_url: Option<String>, | ||
| pub followers_count: i64, | ||
| pub following_count: i64, | ||
| pub is_following: Option<bool>, | ||
| pub is_current_user: Option<bool>, | ||
| pub recently_played_artists: MixedView, | ||
| pub public_playlists: MixedView, | ||
| pub allow_follows: bool, | ||
| pub followers: Vector<PublicUser>, | ||
| pub following: Vector<PublicUser>, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,44 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use druid::{Data, Lens}; | ||
| use serde::Deserialize; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Clone, Data, Lens, Deserialize)] | ||
| pub struct UserProfile { | ||
| #[serde(alias = "name")] | ||
| pub display_name: Arc<str>, | ||
| pub email: Arc<str>, | ||
| pub id: Arc<str>, | ||
| } | ||
|
|
||
| #[derive(Clone, Data, Lens, Deserialize, Debug)] | ||
| #[derive(Clone, Data, Lens, Serialize, Deserialize, Debug, Eq, PartialEq, Default)] | ||
| pub struct PublicUser { | ||
| pub display_name: Arc<str>, | ||
| #[serde(default)] | ||
| pub id: Arc<str>, | ||
| #[serde(default, alias = "name")] | ||
| pub display_name: Arc<str>, | ||
| // Extended profile fields (optional, for detailed responses) | ||
| #[serde(default)] | ||
| pub uri: Option<Arc<str>>, | ||
| #[serde(default)] | ||
| pub image_url: Option<Arc<str>>, | ||
| #[serde(default)] | ||
| pub followers_count: Option<i64>, | ||
| #[serde(default)] | ||
| pub is_following: Option<bool>, | ||
| } | ||
|
|
||
| impl PublicUser { | ||
| /// Get the user ID, extracting from URI if `id` is empty. | ||
| /// URI format is "spotify:user:abc123", extracts "abc123". | ||
| pub fn get_id(&self) -> Arc<str> { | ||
| if self.id.is_empty() { | ||
| self.uri | ||
| .as_ref() | ||
| .and_then(|uri| uri.split(':').nth(2).map(Arc::from)) | ||
| .unwrap_or_default() | ||
| } else { | ||
| self.id.clone() | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.