seperate UI states into App

This commit is contained in:
krolxon 2024-06-07 23:50:05 +05:30
parent faaddc2bd7
commit 8f41c6e1d0
3 changed files with 20 additions and 9 deletions

View File

@ -35,6 +35,11 @@ pub struct App {
// Determines if the database should be updated or not // Determines if the database should be updated or not
pub should_update_song_list: bool, pub should_update_song_list: bool,
// States
pub queue_state: TableState,
pub browser_state: TableState,
pub playlists_state: ListState,
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
@ -58,6 +63,10 @@ impl App {
let browser = FileBrowser::new(); let browser = FileBrowser::new();
let queue_state = TableState::new();
let browser_state = TableState::new();
let playlists_state = ListState::default();
Ok(Self { Ok(Self {
running: true, running: true,
conn, conn,
@ -73,6 +82,9 @@ impl App {
playlist_popup: false, playlist_popup: false,
append_list, append_list,
should_update_song_list: false, should_update_song_list: false,
queue_state,
browser_state,
playlists_state,
}) })
} }

View File

@ -101,7 +101,6 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
} }
}); });
let mut state = TableState::new();
let header = ["Artist", "Track", "Title", "Album", "Time"] let header = ["Artist", "Track", "Title", "Album", "Time"]
.into_iter() .into_iter()
.map(Cell::from) .map(Cell::from)
@ -140,8 +139,8 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
.header(header) .header(header)
.flex(layout::Flex::Legacy); .flex(layout::Flex::Legacy);
state.select(Some(app.browser.selected)); app.browser_state.select(Some(app.browser.selected));
frame.render_stateful_widget(table, size, &mut state); frame.render_stateful_widget(table, size, &mut app.browser_state);
} }
/// draws playing queue /// draws playing queue
@ -196,7 +195,6 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
} }
}); });
let mut state = TableState::new();
let header = ["Artist", "Track", "Title", "Album", "Time"] let header = ["Artist", "Track", "Title", "Album", "Time"]
.into_iter() .into_iter()
.map(Cell::from) .map(Cell::from)
@ -234,8 +232,8 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
.header(header) .header(header)
.flex(layout::Flex::Legacy); .flex(layout::Flex::Legacy);
state.select(Some(app.queue_list.index)); app.queue_state.select(Some(app.queue_list.index));
frame.render_stateful_widget(table, size, &mut state); frame.render_stateful_widget(table, size, &mut app.queue_state);
} }
// Draw search bar // Draw search bar
@ -336,7 +334,6 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) {
.split(area); .split(area);
// Draw list of playlists // Draw list of playlists
let mut state = ListState::default();
let title = Block::default().title(Title::from("Playlist".green().bold())); let title = Block::default().title(Title::from("Playlist".green().bold()));
let list = List::new(app.pl_list.list.clone()) let list = List::new(app.pl_list.list.clone())
.block(title.borders(Borders::ALL)) .block(title.borders(Borders::ALL))
@ -348,8 +345,8 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) {
.add_modifier(Modifier::REVERSED), .add_modifier(Modifier::REVERSED),
) )
.repeat_highlight_symbol(true); .repeat_highlight_symbol(true);
state.select(Some(app.pl_list.index)); app.playlists_state.select(Some(app.pl_list.index));
frame.render_stateful_widget(list, layouts[0], &mut state); frame.render_stateful_widget(list, layouts[0], &mut app.playlists_state);
// Playlist viewer // Playlist viewer

2
todo.md Normal file
View File

@ -0,0 +1,2 @@
- [ ] create new playlist
- [ ] add to new playlist