Added better support for contexts now and improved base Radarr UI

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent 9276fb474d
commit d39acb0683
11 changed files with 407 additions and 153 deletions
+11 -1
View File
@@ -11,7 +11,9 @@ macro_rules! generate_keybindings {
generate_keybindings! {
quit,
up,
down
down,
submit,
esc
}
pub struct KeyBinding {
@@ -31,5 +33,13 @@ pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
down: KeyBinding {
key: Key::Down,
desc: "Scroll down"
},
submit: KeyBinding {
key: Key::Enter,
desc: "Select"
},
esc: KeyBinding {
key: Key::Esc,
desc: "Exit menu"
}
};
+57 -12
View File
@@ -4,25 +4,34 @@ use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::Sender;
use tui::widgets::TableState;
use crate::app::radarr::RadarrData;
use super::network::RadarrEvent;
use crate::app::radarr::{ActiveRadarrBlock, RadarrData};
use crate::network::NetworkEvent;
use crate::network::radarr_network::RadarrEvent;
pub(crate) mod key_binding;
pub mod radarr;
#[derive(Clone, PartialEq, Eq)]
pub enum Route {
Radarr(ActiveRadarrBlock),
}
const DEFAULT_ROUTE: Route = Route::Radarr(ActiveRadarrBlock::Movies);
pub struct App {
network_tx: Option<Sender<RadarrEvent>>,
navigation_stack: Vec<Route>,
network_tx: Option<Sender<NetworkEvent>>,
pub client: Client,
pub title: &'static str,
pub tick_until_poll: u64,
pub tick_count: u64,
pub is_routing: bool,
pub config: AppConfig,
pub data: Data,
}
impl App {
pub fn new(network_tx: Sender<RadarrEvent>, tick_until_poll: u64, config: AppConfig) -> Self {
pub fn new(network_tx: Sender<NetworkEvent>, tick_until_poll: u64, config: AppConfig) -> Self {
App {
network_tx: Some(network_tx),
tick_until_poll,
@@ -31,7 +40,7 @@ impl App {
}
}
pub async fn dispatch(&mut self, action: RadarrEvent) {
pub async fn dispatch(&mut self, action: NetworkEvent) {
if let Some(network_tx) = &self.network_tx {
if let Err(e) = network_tx.send(action).await {
error!("Failed to send event. {:?}", e);
@@ -43,25 +52,61 @@ impl App {
self.tick_count = 0;
}
pub async fn on_tick(&mut self) {
if self.tick_count % self.tick_until_poll == 0 {
self.dispatch(RadarrEvent::GetOverview).await;
self.dispatch(RadarrEvent::GetStatus).await;
self.dispatch(RadarrEvent::GetMovies).await;
pub fn reset(&mut self) {
self.reset_tick_count();
self.data = Data::default();
}
pub async fn on_tick(&mut self, is_first_render: bool) {
if self.tick_count % self.tick_until_poll == 0 || self.is_routing {
match self.get_current_route() {
Route::Radarr(active_radarr_block) => {
let active_block = active_radarr_block.clone();
if is_first_render {
self.dispatch(RadarrEvent::GetQualityProfiles.into()).await;
}
self.dispatch(RadarrEvent::GetOverview.into()).await;
self.dispatch(RadarrEvent::GetStatus.into()).await;
self.dispatch_by_radarr_block(active_block).await;
}
}
self.is_routing = false;
}
self.tick_count += 1;
}
pub fn push_navigation_stack(&mut self, route: Route) {
self.navigation_stack.push(route);
self.is_routing = true;
}
pub fn pop_navigation_stack(&mut self) {
if self.navigation_stack.len() > 1 {
self.navigation_stack.pop();
}
}
pub fn get_current_route(&self) -> &Route {
self.navigation_stack.last().unwrap_or(&DEFAULT_ROUTE)
}
}
impl Default for App {
fn default() -> Self {
App {
navigation_stack: vec![DEFAULT_ROUTE],
network_tx: None,
client: Client::new(),
title: "DevTools",
title: "Managarr",
tick_until_poll: 0,
tick_count: 0,
is_routing: false,
config: AppConfig::default(),
data: Data::default(),
}
+35 -3
View File
@@ -1,7 +1,9 @@
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use crate::app::StatefulTable;
use crate::network::radarr::Movie;
use crate::app::{App, StatefulTable};
use crate::network::radarr_network::{DownloadRecord, Movie, RadarrEvent};
#[derive(Default)]
pub struct RadarrData {
@@ -9,5 +11,35 @@ pub struct RadarrData {
pub total_space: u64,
pub version: String,
pub start_time: DateTime<Utc>,
pub movies: StatefulTable<Movie>
pub movies: StatefulTable<Movie>,
pub downloads: StatefulTable<DownloadRecord>,
pub quality_profile_map: HashMap<u64, String>,
}
#[derive(Clone, PartialEq, Eq)]
pub enum ActiveRadarrBlock {
AddMovie,
Calendar,
Collections,
Events,
Logs,
Movies,
MovieDetails,
Downloads,
SearchMovie,
SortOptions,
Tasks,
}
impl App {
pub(super) async fn dispatch_by_radarr_block(&mut self, active_radarr_block: ActiveRadarrBlock) {
match active_radarr_block {
ActiveRadarrBlock::Downloads => self.dispatch(RadarrEvent::GetDownloads.into()).await,
ActiveRadarrBlock::Movies => {
self.dispatch(RadarrEvent::GetMovies.into()).await;
self.dispatch(RadarrEvent::GetDownloads.into()).await;
},
_ => ()
}
}
}