Skip to content
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

Implement UI for creating new playlists #234

Closed
wants to merge 1 commit into from

Conversation

nuugen
Copy link
Contributor

@nuugen nuugen commented Aug 13, 2023

This attempts to implement a rudimentary UI flow for creating a new playlist.

Resolves #87.

Usage:
While focused on the playlist window, pressing N will show a pop-up prompting user to enter the name and the description of the new playlist to be created. Pressing Tab here will switch focus between the two fields.

Limitation:
For simplicity, the public and collab statuses will be omitted. The desc field looks to be broken upstream in rspotify - the new playlist does not seem to have this informatino attached. Both of these limitations are also observed in the CLI implementation (#222). This seems to be a misobservation.

I'm also relatively new to Rust, so I mainly focused on submitting a purely functioning implementation, without much regard to the DRYness of code - once there are more instances of the pop-up with input prompt (similar to both Search and PlaylistCreate here), it should be abstracted.

Suggestions and critics are of course more than welcome and would help me a lot getting started in my Rust journey.

Copy link
Owner

@aome510 aome510 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Thanks for the PR and taking time to implement this feature. A few suggestions.

The desc field looks to be broken upstream in rspotify - the new playlist does not seem to have this informatino attached. Both of these limitations are also observed in the CLI implementation

Can you elaborate by "the new playlist does not seem to have this information attached"? desc seems to work fine for me. I can see the description of new playlist created by spotify_player in the official Spotify app.

once there are more instances of the pop-up with input prompt (similar to both Search and PlaylistCreate here), it should be abstracted.

nice to have for sure but no need to implement one in this PR.

desc,
} => {
let user_id = state.data.read().user_data.user.to_owned().unwrap().id;
let _ = self
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can have a info log here saying a new playlist with ... id was successfully created.

let _ = self
.create_new_playlist(
state,
user_id.clone(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant clone?

Comment on lines +1324 to +1329
Playlist {
id: resp.id.to_owned(),
collaborative: collab,
name: playlist_name.to_string(),
owner: ("".into(), user_id),
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use resp.into() instead. state::Playlist does implement the From<rspotify_model::FullPlaylist> trait.

@@ -204,6 +206,8 @@ impl Command {
Self::ReverseTrackOrder => "reverse the order of the track table (if any)",
Self::MovePlaylistItemUp => "move playlist item up one position",
Self::MovePlaylistItemDown => "move playlist item down one position",

Self::CreatePlaylist => "create new playlist",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Self::CreatePlaylist => "create new playlist",
Self::CreatePlaylist => "create a new playlist",

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.split(chunks[1]);

let name_input = construct_and_render_block(
"Enter Name for New Playlist:",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Enter Name for New Playlist:",
"Enter Name for New Playlist",

Comment on lines +302 to +304
if !name.is_empty() {
name.pop().unwrap();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !name.is_empty() {
name.pop().unwrap();
}
name.pop();

no need to check is_empty then unwrap

Comment on lines +307 to +309
if !desc.is_empty() {
desc.pop().unwrap();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !desc.is_empty() {
desc.pop().unwrap();
}
desc.pop();

}
return Ok(true);
}
crossterm::event::KeyCode::Tab => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
crossterm::event::KeyCode::Tab => {
crossterm::event::KeyCode::Tab | crossterm::event::KeyCode::BackTab => {

can also handle shift+Tab

Comment on lines +345 to +361
let page_type = state.ui.lock().current_page().page_type();
match page_type {
PageType::Library => page::handle_key_sequence_for_library_page(key_sequence, state),
PageType::Search => {
page::handle_key_sequence_for_search_page(key_sequence, client_pub, state)
}
PageType::Context => {
page::handle_key_sequence_for_context_page(key_sequence, client_pub, state)
}
PageType::Browse => {
page::handle_key_sequence_for_browse_page(key_sequence, client_pub, state)
}
#[cfg(feature = "lyric-finder")]
PageType::Lyric => {
page::handle_key_sequence_for_lyric_page(key_sequence, client_pub, state)
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to do this for the create playlist popup. Search popup is special because the focus is not placed on it when the popup is created. It's expected to use along with the focused window for interactive searching.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return Ok(false) in this case.

Comment on lines +426 to +432
Command::CreatePlaylist => {
ui.popup = Some(PopupState::PlaylistCreate {
name: "".into(),
desc: "".into(),
current_field: PlaylistCreateCurrentField::Name,
});
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't handle the create playlist command here.

@nuugen
Copy link
Contributor Author

nuugen commented Aug 15, 2023

Can you elaborate by "the new playlist does not seem to have this information attached"? desc seems to work fine for me. I can see the description of new playlist created by spotify_player in the official Spotify app.

I just tested this again today, and the description is now transmitted properly. On the day I was implementing this feature, that was not the case - neither through the popup or the CLI. Weird.

@nuugen
Copy link
Contributor Author

nuugen commented Aug 15, 2023

Thanks for the great suggestions, will work through them when time permits.

@diegoulloao
Copy link

diegoulloao commented Dec 10, 2023

This feature looks great ✨
Anything going on the process?

@aome510
Copy link
Owner

aome510 commented Dec 10, 2023

I'm still waiting for updates from @nuugen. I can take over if time permits.

@m-torhan
Copy link
Contributor

m-torhan commented Feb 9, 2024

Hi, I noticed that this PR is stuck for some time now. May I finish this implementation as this feature would be really useful?

@nuugen
Copy link
Contributor Author

nuugen commented Feb 9, 2024

Hi, sorry all for the hold-up.

@m-torhan, please, go ahead with finishing this feature. Thanks!

@aome510
Copy link
Owner

aome510 commented Feb 12, 2024

Close in favour of #365

@aome510 aome510 closed this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add to a new playlist / create a playlist?
4 participants