diff --git a/.gitignore b/.gitignore index ea8c4bf..5421811 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +/.idea/ +Cargo.lock diff --git a/src/app/radarr.rs b/src/app/radarr.rs index 8387eff..8fc99ae 100644 --- a/src/app/radarr.rs +++ b/src/app/radarr.rs @@ -5,10 +5,10 @@ use chrono::{DateTime, Utc}; use strum::EnumIter; use crate::app::{App, Route}; +use crate::models::{ScrollableText, StatefulMatrix, StatefulTable, TabRoute, TabState}; use crate::models::radarr_models::{ Collection, CollectionMovie, Credit, DiskSpace, DownloadRecord, Movie, MovieHistoryItem, }; -use crate::models::{ScrollableText, StatefulTable, TabRoute, TabState}; use crate::network::radarr_network::RadarrEvent; pub struct RadarrData { @@ -29,6 +29,7 @@ pub struct RadarrData { pub collections: StatefulTable, pub filtered_collections: StatefulTable, pub collection_movies: StatefulTable, + pub calendar: StatefulMatrix<> pub main_tabs: TabState, pub movie_info_tabs: TabState, pub search: String, @@ -94,7 +95,7 @@ impl Default for RadarrData { TabRoute { title: "Library".to_owned(), route: ActiveRadarrBlock::Movies.into(), - help: "<↑↓> scroll | search | filter | details | cancel filter | ←→ change tab " + help: "<↑↓> scroll | search | filter | details | cancel filter | delete | ←→ change tab " .to_owned(), }, TabRoute { @@ -108,6 +109,11 @@ impl Default for RadarrData { help: "<↑↓> scroll | search | filter | details | cancel filter | ←→ change tab " .to_owned(), }, + TabRoute { + title: "Calendar".to_owned(), + route: ActiveRadarrBlock::Calendar.into(), + help: "<↑↓> scroll | details | ←→ change tab ".to_owned() + } ]), movie_info_tabs: TabState::new(vec![ TabRoute { diff --git a/src/models/mod.rs b/src/models/mod.rs index e520508..7f32675 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -113,6 +113,61 @@ impl Scrollable for StatefulTable { } } +#[derive(Default)] +pub struct StatefulMatrix { + pub selection: (usize, usize), + pub items: Vec>, +} + +impl Scrollable for StatefulMatrix { + fn scroll_down(&mut self) { + if self.selection.0 >= self.items.len() - 1 { + self.selection.0 = 0; + } else { + self.selection.0 += 1; + } + } + + fn scroll_up(&mut self) { + if self.selection.0 == 0 { + self.selection.0 = self.items.len() - 1; + } else { + self.selection.0 -= 1; + } + } + + fn scroll_to_top(&mut self) { + self.selection.0 = 0; + } + + fn scroll_to_bottom(&mut self) { + self.selection.0 = self.items.len() - 1; + } +} + +impl StatefulMatrix { + pub fn current_selection(&self) -> &T { + let (x, y) = self.selection; + &self.items[x][y] + } + + pub fn scroll_left(&mut self) { + if self.selection.1 == 0 { + self.selection.1 = self.items[0].len() - 1; + } else { + self.selection.1 -= 1; + } + } + + pub fn scroll_right(&mut self) { + if self.selection.1 >= self.items[0].len() - 1 { + self.selection.1 = 0; + } else { + self.selection.1 += 1; + } + } +} + #[derive(Default)] pub struct ScrollableText { pub items: Vec,