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
+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(),
}