Skip to content

Commit

Permalink
fix: tick nits
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanaden committed Jun 28, 2024
1 parent ea62952 commit bc93d68
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
38 changes: 24 additions & 14 deletions rm-main/src/ui/tabs/torrents/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use std::sync::{Arc, Mutex};
use ratatui::prelude::*;
use throbber_widgets_tui::ThrobberState;

use crate::{action::Action, app, ui::components::Component};
use crate::{
action::Action,
app::{self},
ui::components::Component,
};

use super::{
tasks::{
Expand Down Expand Up @@ -40,6 +44,24 @@ pub enum CurrentTask {
Status(StatusBar),
}

impl CurrentTask {
fn tick(&mut self) -> Option<Action> {
if let Self::Status(status_bar) = self {
// if let CurrentTaskState::Success(start) = status_bar.task_status {
// let expiration_duration = tokio::time::Duration::from_secs(5);
// if start.elapsed() > expiration_duration {
// *self = CurrentTask::Default(DefaultBar::new(ctx));
// return Some(Action::Render);
// } else {
// return status_bar.tick();
// }
// }
return status_bar.tick();
}
None
}
}

impl Component for TaskManager {
#[must_use]
fn handle_actions(&mut self, action: Action) -> Option<Action> {
Expand Down Expand Up @@ -105,19 +127,7 @@ impl Component for TaskManager {
}

fn tick(&mut self) -> Option<Action> {
if let CurrentTask::Status(status_bar) = &mut self.current_task {
if let CurrentTaskState::Success(start) = status_bar.task_status {
let expiration_duration = tokio::time::Duration::from_secs(5);
println!("{:?}, {:?}", start, expiration_duration);
if start.elapsed() > expiration_duration {
self.current_task = CurrentTask::Default(DefaultBar::new(self.ctx.clone()));
return Some(Action::Render);
} else {
return status_bar.tick();
}
}
}
None
self.current_task.tick()
}
}

Expand Down
14 changes: 7 additions & 7 deletions rm-main/src/ui/tabs/torrents/tasks/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{action::Action, ui::components::Component};

use ratatui::{prelude::*, widgets::Paragraph};
use throbber_widgets_tui::ThrobberState;
use tokio::time::Instant;
use tokio::time::{self, Instant};

pub struct StatusBar {
task: StatusTask,
Expand Down Expand Up @@ -95,11 +95,11 @@ impl Component for StatusBar {
match action {
Action::Tick => self.tick(),
Action::TaskSuccess => {
self.task_status.success(tokio::time::Instant::now());
self.task_status.set_success(time::Instant::now());
Some(Action::Render)
}
Action::Error(_) => {
self.task_status.failure();
self.task_status.set_failure();
Some(Action::Render)
}
_ => Some(action),
Expand All @@ -113,8 +113,8 @@ impl Component for StatusBar {
Some(Action::Render)
}
CurrentTaskState::Success(start) => {
let expiration_duration = tokio::time::Duration::from_secs(5);
if start.elapsed() > expiration_duration {
let expiration_duration = time::Duration::from_secs(5);
if start.elapsed() >= expiration_duration {
return Some(Action::Quit);
}
None
Expand All @@ -138,11 +138,11 @@ pub enum CurrentTaskState {
}

impl CurrentTaskState {
fn failure(&mut self) {
fn set_failure(&mut self) {
*self = Self::Failure;
}

fn success(&mut self, start: Instant) {
fn set_success(&mut self, start: Instant) {
*self = Self::Success(start);
}
}

0 comments on commit bc93d68

Please sign in to comment.