Implemented Library and Download tabs!
This commit is contained in:
@@ -12,6 +12,8 @@ generate_keybindings! {
|
||||
quit,
|
||||
up,
|
||||
down,
|
||||
left,
|
||||
right,
|
||||
submit,
|
||||
esc
|
||||
}
|
||||
@@ -34,6 +36,14 @@ pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
|
||||
key: Key::Down,
|
||||
desc: "Scroll down",
|
||||
},
|
||||
left: KeyBinding {
|
||||
key: Key::Left,
|
||||
desc: "Move left",
|
||||
},
|
||||
right: KeyBinding {
|
||||
key: Key::Right,
|
||||
desc: "Move right",
|
||||
},
|
||||
submit: KeyBinding {
|
||||
key: Key::Enter,
|
||||
desc: "Select",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use tui::widgets::TableState;
|
||||
|
||||
use crate::app::Route;
|
||||
|
||||
pub trait Scrollable {
|
||||
fn scroll_down(&mut self);
|
||||
fn scroll_up(&mut self);
|
||||
@@ -105,3 +107,41 @@ impl Scrollable for ScrollableText {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TabRoute {
|
||||
pub title: String,
|
||||
pub route: Route,
|
||||
}
|
||||
|
||||
pub struct TabState {
|
||||
pub tabs: Vec<TabRoute>,
|
||||
pub index: usize,
|
||||
}
|
||||
|
||||
impl TabState {
|
||||
pub fn new(tabs: Vec<TabRoute>) -> TabState {
|
||||
TabState { tabs, index: 0 }
|
||||
}
|
||||
|
||||
pub fn set_index(&mut self, index: usize) -> &TabRoute {
|
||||
self.index = index;
|
||||
&self.tabs[self.index]
|
||||
}
|
||||
|
||||
pub fn get_active_route(&self) -> &Route {
|
||||
&self.tabs[self.index].route
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
self.index = (self.index + 1) % self.tabs.len();
|
||||
}
|
||||
|
||||
pub fn previous(&mut self) {
|
||||
if self.index > 0 {
|
||||
self.index -= 1;
|
||||
} else {
|
||||
self.index = self.tabs.len() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-3
@@ -1,12 +1,12 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use strum::EnumIter;
|
||||
|
||||
use crate::app::models::{ScrollableText, StatefulTable};
|
||||
use crate::app::models::{ScrollableText, StatefulTable, TabRoute, TabState};
|
||||
use crate::app::App;
|
||||
use crate::network::radarr_network::{DownloadRecord, Movie, RadarrEvent};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RadarrData {
|
||||
pub free_space: u64,
|
||||
pub total_space: u64,
|
||||
@@ -16,9 +16,35 @@ pub struct RadarrData {
|
||||
pub downloads: StatefulTable<DownloadRecord>,
|
||||
pub quality_profile_map: HashMap<u64, String>,
|
||||
pub movie_details: ScrollableText,
|
||||
pub main_tabs: TabState,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
impl Default for RadarrData {
|
||||
fn default() -> RadarrData {
|
||||
RadarrData {
|
||||
free_space: u64::default(),
|
||||
total_space: u64::default(),
|
||||
version: String::default(),
|
||||
start_time: DateTime::default(),
|
||||
movies: StatefulTable::default(),
|
||||
downloads: StatefulTable::default(),
|
||||
quality_profile_map: HashMap::default(),
|
||||
movie_details: ScrollableText::default(),
|
||||
main_tabs: TabState::new(vec![
|
||||
TabRoute {
|
||||
title: "Library".to_owned(),
|
||||
route: ActiveRadarrBlock::Movies.into(),
|
||||
},
|
||||
TabRoute {
|
||||
title: "Downloads".to_owned(),
|
||||
route: ActiveRadarrBlock::Downloads.into(),
|
||||
},
|
||||
]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, EnumIter)]
|
||||
pub enum ActiveRadarrBlock {
|
||||
AddMovie,
|
||||
Calendar,
|
||||
|
||||
Reference in New Issue
Block a user