tui: Add dashboard widget

This commit is contained in:
Erik Kundt 2023-04-18 17:14:06 +02:00 committed by Alexis Sellier
parent 38c9f0a1c0
commit 95b0029267
No known key found for this signature in database
3 changed files with 45 additions and 5 deletions

View File

@ -14,7 +14,9 @@ use radicle_tui::ui;
use radicle_tui::ui::components::container::{GlobalListener, LabeledContainer, Tabs};
use radicle_tui::ui::components::context::{ContextBar, Shortcuts};
use radicle_tui::ui::components::list::PropertyList;
use radicle_tui::ui::components::workspace::{Browser, IssueBrowser, PatchActivity, PatchFiles};
use radicle_tui::ui::components::workspace::{
Browser, Dashboard, IssueBrowser, PatchActivity, PatchFiles,
};
use radicle_tui::ui::layout;
use radicle_tui::ui::theme::{self, Theme};
use radicle_tui::ui::widget::Widget;
@ -428,6 +430,12 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<Browser<(PatchId, Patc
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<Dashboard> {
fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
None
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<IssueBrowser> {
fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
None

View File

@ -22,7 +22,7 @@ use widget::Widget;
use self::cob::patch;
use self::components::context::ContextBar;
use self::components::list::{List, Table};
use self::components::workspace::{Browser, IssueBrowser, PatchActivity, PatchFiles};
use self::components::workspace::{Browser, Dashboard, IssueBrowser, PatchActivity, PatchFiles};
use self::theme::Theme;
pub fn global_listener() -> Widget<GlobalListener> {
@ -212,8 +212,8 @@ pub fn patch_navigation(theme: &theme::Theme) -> Widget<Tabs> {
tabs(theme, vec![label("activity"), label("files")])
}
pub fn dashboard(theme: &theme::Theme, id: &Id, project: &Project) -> Widget<LabeledContainer> {
labeled_container(
pub fn dashboard(theme: &theme::Theme, id: &Id, project: &Project) -> Widget<Dashboard> {
let about = labeled_container(
theme,
"about",
property_list(
@ -225,5 +225,8 @@ pub fn dashboard(theme: &theme::Theme, id: &Id, project: &Project) -> Widget<Lab
],
)
.to_boxed(),
)
);
let dashboard = Dashboard::new(about);
Widget::new(dashboard)
}

View File

@ -8,6 +8,7 @@ use tuirealm::{AttrValue, Attribute, Frame, MockComponent, State};
use crate::ui::layout;
use crate::ui::widget::{Widget, WidgetComponent};
use super::container::LabeledContainer;
use super::label::Label;
use super::list::{List, Table};
@ -44,9 +45,37 @@ impl<T: List> WidgetComponent for Browser<T> {
}
}
pub struct Dashboard {
about: Widget<LabeledContainer>,
}
impl Dashboard {
pub fn new(about: Widget<LabeledContainer>) -> Self {
Self { about }
}
}
impl WidgetComponent for Dashboard {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints(vec![Constraint::Length(4)].as_ref())
.split(area);
self.about.view(frame, layout[0]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct IssueBrowser {
label: Widget<Label>,
}
impl IssueBrowser {
pub fn new(label: Widget<Label>) -> Self {
Self { label }