Skip to content

Commit

Permalink
refactor: use MqttHistory inside TopicOverview::draw
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed May 15, 2024
1 parent 27b7639 commit fb1bfe4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions src/interactive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,10 @@ impl App {
}
});

let topic_amount = history.total_topics();
let message_amount = history.total_messages();

let tree_items = history.to_tree_items();

self.topic_overview.draw(
frame,
overview_area,
topic_amount,
message_amount,
tree_items,
&history,
matches!(self.focus, ElementInFocus::TopicOverview),
);
drop(history);
Expand Down
18 changes: 8 additions & 10 deletions src/interactive/topic_overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use ratatui::layout::{Alignment, Rect};
use ratatui::style::{Color, Style};
use ratatui::widgets::{Block, BorderType, Scrollbar, ScrollbarOrientation};
use ratatui::Frame;
use tui_tree_widget::{Tree, TreeItem, TreeState};
use tui_tree_widget::{Tree, TreeState};

use super::mqtt_history::MqttHistory;
use crate::interactive::ui::{focus_color, get_row_inside, BORDERS_TOP_RIGHT};

#[derive(Default)]
Expand All @@ -22,16 +23,13 @@ impl TopicOverview {
Some(selected.join("/"))
}

pub fn draw(
&mut self,
frame: &mut Frame,
area: Rect,
topic_amount: usize,
message_amount: usize,
tree_items: Vec<TreeItem<String>>,
has_focus: bool,
) {
pub fn draw(&mut self, frame: &mut Frame, area: Rect, history: &MqttHistory, has_focus: bool) {
let topic_amount = history.total_topics();
let message_amount = history.total_messages();
let title = format!("Topics ({topic_amount}, {message_amount} messages)");

let tree_items = history.to_tree_items();

let focus_color = focus_color(has_focus);
let widget = Tree::new(&tree_items)
.experimental_scrollbar(Some(
Expand Down

0 comments on commit fb1bfe4

Please sign in to comment.