pl_append functionality for playlists
This commit is contained in:
parent
9bdc76b6a9
commit
aca208e0d8
|
|
@ -13,14 +13,12 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
|
||||||
KeyCode::Char('k') | KeyCode::Up => app.append_list.prev(),
|
KeyCode::Char('k') | KeyCode::Up => app.append_list.prev(),
|
||||||
|
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
let pl_index = app.append_list.index;
|
// name of highlighted playlist in append list
|
||||||
let pl_name = &app.append_list.list.get(pl_index).unwrap();
|
let pl_name = &app.append_list.get_item_at_current_index();
|
||||||
|
|
||||||
let s_index: usize;
|
|
||||||
match app.selected_tab {
|
match app.selected_tab {
|
||||||
SelectedTab::Queue => {
|
SelectedTab::Queue => {
|
||||||
s_index = app.queue_list.index;
|
let short_path = &app.queue_list.get_item_at_current_index().file;
|
||||||
let short_path = &app.queue_list.list.get(s_index).unwrap().file;
|
|
||||||
|
|
||||||
if let Some(full_path) = app.conn.get_full_path(short_path) {
|
if let Some(full_path) = app.conn.get_full_path(short_path) {
|
||||||
let song = app.conn.get_song_with_only_filename(&full_path);
|
let song = app.conn.get_song_with_only_filename(&full_path);
|
||||||
|
|
@ -68,7 +66,23 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
|
SelectedTab::Playlists => {
|
||||||
|
let playlist_name = app.pl_list.get_item_at_current_index();
|
||||||
|
if *pl_name == "Current Playlist" {
|
||||||
|
app.conn.load_playlist(playlist_name)?;
|
||||||
|
app.update_queue();
|
||||||
|
} else {
|
||||||
|
let songs = app.conn.conn.playlist(playlist_name)?;
|
||||||
|
for song in songs {
|
||||||
|
// We ignore the Err() since there could be songs in playlists, which do not exist in the db anymore.
|
||||||
|
// So instead of panicking, we just ignore if the song does not exists
|
||||||
|
app.conn
|
||||||
|
.add_to_playlist(*pl_name, &song)
|
||||||
|
.unwrap_or_else(|_| {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide the playlist popup
|
// hide the playlist popup
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub fn handle_pl_rename_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
app.conn.conn.pl_rename(
|
app.conn.conn.pl_rename(
|
||||||
app.pl_list.list.get(app.pl_list.index).unwrap(),
|
app.pl_list.get_item_at_current_index(),
|
||||||
&app.pl_newname_input,
|
&app.pl_newname_input,
|
||||||
)?;
|
)?;
|
||||||
app.pl_list.list = App::get_playlist(&mut app.conn.conn)?;
|
app.pl_list.list = App::get_playlist(&mut app.conn.conn)?;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ impl<T> ContentList<T> {
|
||||||
pub fn reset_index(&mut self) {
|
pub fn reset_index(&mut self) {
|
||||||
self.index = 0;
|
self.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the self.list[index] item
|
||||||
|
pub fn get_item_at_current_index(&mut self) -> &T {
|
||||||
|
self.list.get(self.index).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Default for ContentList<T> {
|
impl<T> Default for ContentList<T> {
|
||||||
|
|
|
||||||
|
|
@ -355,7 +355,7 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pl_name = app.pl_list.list.get(app.pl_list.index).unwrap();
|
let pl_name = app.pl_list.get_item_at_current_index();
|
||||||
let songs = app.conn.conn.playlist(pl_name).unwrap();
|
let songs = app.conn.conn.playlist(pl_name).unwrap();
|
||||||
let rows = songs.iter().map(|song| {
|
let rows = songs.iter().map(|song| {
|
||||||
let title = song.clone().title.unwrap_or_default().cyan();
|
let title = song.clone().title.unwrap_or_default().cyan();
|
||||||
|
|
|
||||||
Reference in New Issue