feat: Carve out issue tui

This commit is contained in:
Erik Kundt
2023-10-06 10:55:35 +02:00
parent 21241e64b6
commit 36fa0b1ad8
12 changed files with 295 additions and 1038 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ use page::{HomeView, PatchView};
use self::page::{IssuePage, PageStack};
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum HomeCid {
pub enum ListCid {
Header,
Dashboard,
IssueBrowser,
+19 -71
View File
@@ -1,43 +1,31 @@
mod event;
mod page;
mod subscription;
mod ui;
use anyhow::Result;
use radicle::cob::issue::IssueId;
use radicle::cob::patch::PatchId;
use radicle::identity::{Id, Project};
use radicle::prelude::Signer;
use radicle::profile::Profile;
use radicle_tui::ui::subscription;
use radicle_tui::ui::widget;
use tuirealm::application::PollStrategy;
use tuirealm::{Application, Frame, NoUserEvent, Sub, SubClause};
use radicle_tui::cob;
use radicle_tui::ui::context::Context;
use radicle_tui::ui::theme::{self, Theme};
use radicle_tui::PageStack;
use radicle_tui::Tui;
use radicle_tui::{cob, ui};
use page::{HomeView, PatchView};
use self::page::{IssuePage, PageStack};
use page::{IssuePage, ListPage};
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum HomeCid {
pub enum ListCid {
Header,
Dashboard,
IssueBrowser,
PatchBrowser,
Context,
Shortcuts,
}
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
pub enum PatchCid {
Header,
Activity,
Files,
Context,
Shortcuts,
}
@@ -53,21 +41,15 @@ pub enum IssueCid {
}
/// All component ids known to this application.
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
#[derive(Debug, Default, Eq, PartialEq, Clone, Hash)]
pub enum Cid {
Home(HomeCid),
List(ListCid),
Issue(IssueCid),
Patch(PatchCid),
#[default]
GlobalListener,
Popup,
}
/// Messages handled by this application.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum HomeMessage {
RefreshIssues(Option<IssueId>),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum IssueCobMessage {
Create {
@@ -85,17 +67,12 @@ pub enum IssueMessage {
Focus(IssueCid),
Created(IssueId),
Cob(IssueCobMessage),
Reload(Option<IssueId>),
OpenForm,
HideForm,
Leave(Option<IssueId>),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PatchMessage {
Show(PatchId),
Leave,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PopupMessage {
Info(String),
@@ -104,14 +81,13 @@ pub enum PopupMessage {
Hide,
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub enum Message {
Home(HomeMessage),
Issue(IssueMessage),
Patch(PatchMessage),
NavigationChanged(u16),
FormSubmitted(String),
Popup(PopupMessage),
#[default]
Tick,
Quit,
Batch(Vec<Message>),
@@ -120,7 +96,7 @@ pub enum Message {
#[allow(dead_code)]
pub struct App {
context: Context,
pages: PageStack,
pages: PageStack<Cid, Message>,
theme: Theme,
quit: bool,
}
@@ -137,37 +113,17 @@ impl App {
}
}
fn view_home(
fn view_list(
&mut self,
app: &mut Application<Cid, Message, NoUserEvent>,
theme: &Theme,
) -> Result<()> {
let home = Box::new(HomeView::new(theme.clone()));
self.pages.push(home, app, &self.context, theme)?;
let list = Box::new(ListPage::new(theme.clone()));
self.pages.push(list, app, &self.context, theme)?;
Ok(())
}
fn view_patch(
&mut self,
app: &mut Application<Cid, Message, NoUserEvent>,
id: PatchId,
theme: &Theme,
) -> Result<()> {
let repo = self.context.repository();
if let Some(patch) = cob::patch::find(repo, &id)? {
let view = Box::new(PatchView::new(theme.clone(), (id, patch)));
self.pages.push(view, app, &self.context, theme)?;
Ok(())
} else {
Err(anyhow::anyhow!(
"Could not mount 'page::PatchView'. Patch not found."
))
}
}
fn view_issue(
&mut self,
app: &mut Application<Cid, Message, NoUserEvent>,
@@ -244,15 +200,7 @@ impl App {
}
Message::Issue(IssueMessage::Leave(id)) => {
self.pages.pop(app)?;
Ok(Some(Message::Home(HomeMessage::RefreshIssues(id))))
}
Message::Patch(PatchMessage::Show(id)) => {
self.view_patch(app, id, &theme)?;
Ok(None)
}
Message::Patch(PatchMessage::Leave) => {
self.pages.pop(app)?;
Ok(None)
Ok(Some(Message::Issue(IssueMessage::Reload(id))))
}
Message::Popup(PopupMessage::Info(info)) => {
self.show_info_popup(app, &theme, &info)?;
@@ -353,10 +301,10 @@ impl App {
impl Tui<Cid, Message> for App {
fn init(&mut self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
self.view_home(app, &self.theme.clone())?;
self.view_list(app, &self.theme.clone())?;
// Add global key listener and subscribe to key events
let global = ui::widget::common::global_listener().to_boxed();
let global = widget::common::global_listener().to_boxed();
app.mount(
Cid::GlobalListener,
global,
+5 -72
View File
@@ -9,12 +9,11 @@ use radicle_tui::ui::widget::common::container::{
use radicle_tui::ui::widget::common::context::{ContextBar, Shortcuts};
use radicle_tui::ui::widget::common::form::Form;
use radicle_tui::ui::widget::common::list::PropertyList;
use radicle_tui::ui::widget::home::{Dashboard, IssueBrowser, PatchBrowser};
use radicle_tui::ui::widget::{issue, patch};
use radicle_tui::ui::widget::Widget;
use super::{IssueCid, IssueMessage, Message, PatchMessage, PopupMessage};
use super::ui;
use super::{IssueCid, IssueMessage, Message, PopupMessage};
/// Since the framework does not know the type of messages that are being
/// passed around in the app, the following handlers need to be implemented for
@@ -49,7 +48,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<AppHeader> {
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<issue::LargeList> {
impl tuirealm::Component<Message, NoUserEvent> for Widget<ui::LargeList> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => match self.state() {
@@ -103,7 +102,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<issue::LargeList> {
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<issue::IssueDetails> {
impl tuirealm::Component<Message, NoUserEvent> for Widget<ui::IssueDetails> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Up, .. })
@@ -233,45 +232,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<Form> {
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchBrowser> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Up, .. })
| Event::Keyboard(KeyEvent {
code: Key::Char('k'),
..
}) => {
self.perform(Cmd::Move(MoveDirection::Up));
Some(Message::Tick)
}
Event::Keyboard(KeyEvent {
code: Key::Down, ..
})
| Event::Keyboard(KeyEvent {
code: Key::Char('j'),
..
}) => {
self.perform(Cmd::Move(MoveDirection::Down));
Some(Message::Tick)
}
Event::Keyboard(KeyEvent {
code: Key::Enter, ..
}) => {
let result = self.perform(Cmd::Submit);
match result {
CmdResult::Submit(State::One(StateValue::Usize(selected))) => {
let item = self.items().get(selected)?;
Some(Message::Patch(PatchMessage::Show(item.id().to_owned())))
}
_ => None,
}
}
_ => None,
}
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<IssueBrowser> {
impl tuirealm::Component<Message, NoUserEvent> for Widget<ui::IssueBrowser> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
let mut submit = || -> Option<IssueId> {
let result = self.perform(Cmd::Submit);
@@ -328,34 +289,6 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<IssueBrowser> {
}
}
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<patch::Activity> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => {
Some(Message::Patch(PatchMessage::Leave))
}
_ => None,
}
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<patch::Files> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => {
Some(Message::Patch(PatchMessage::Leave))
}
_ => None,
}
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<Popup> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
+74 -405
View File
@@ -3,8 +3,6 @@ use std::collections::HashMap;
use anyhow::Result;
use radicle::cob::issue::{Issue, IssueId};
use radicle::cob::patch::{Patch, PatchId};
use radicle_tui::cob;
use radicle_tui::ui::widget::common::context::{Progress, Shortcuts};
use tuirealm::{AttrValue, Attribute, Frame, NoUserEvent, State, StateValue, Sub, SubClause};
@@ -13,66 +11,28 @@ use radicle_tui::ui::context::Context;
use radicle_tui::ui::layout;
use radicle_tui::ui::theme::Theme;
use radicle_tui::ui::widget::{self, Widget};
use radicle_tui::ViewPage;
use super::{
subscription, Application, Cid, HomeCid, HomeMessage, IssueCid, IssueCobMessage, IssueMessage,
Message, PatchCid, PopupMessage,
Application, Cid, IssueCid, IssueCobMessage, IssueMessage, ListCid, Message, PopupMessage,
};
/// `tuirealm`'s event and prop system is designed to work with flat component hierarchies.
/// Building deep nested component hierarchies would need a lot more additional effort to
/// properly pass events and props down these hierarchies. This makes it hard to implement
/// full app views (home, patch details etc) as components.
///
/// View pages take into account these flat component hierarchies, and provide
/// switchable sets of components.
pub trait ViewPage {
/// Will be called whenever a view page is pushed onto the page stack. Should create and mount all widgets.
fn mount(
&self,
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
) -> Result<()>;
/// Will be called whenever a view page is popped from the page stack. Should unmount all widgets.
fn unmount(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()>;
/// Will be called whenever a view page is on top of the stack and can be used to update its internal
/// state depending on the message passed.
fn update(
&mut self,
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
message: Message,
) -> Result<Option<Message>>;
/// Will be called whenever a view page is on top of the page stack and needs to be rendered.
fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, frame: &mut Frame);
/// Will be called whenever this view page is pushed to the stack, or it is on top of the stack again
/// after another view page was popped from the stack.
fn subscribe(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()>;
/// Will be called whenever this view page is on top of the stack and another view page is pushed
/// to the stack, or if this is popped from the stack.
fn unsubscribe(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()>;
}
use super::subscription;
use super::ui;
///
/// Home
///
pub struct HomeView {
active_component: HomeCid,
shortcuts: HashMap<HomeCid, Widget<Shortcuts>>,
pub struct ListPage {
active_component: ListCid,
shortcuts: HashMap<ListCid, Widget<Shortcuts>>,
}
impl HomeView {
impl ListPage {
pub fn new(theme: Theme) -> Self {
let shortcuts = Self::build_shortcuts(&theme);
HomeView {
active_component: HomeCid::Dashboard,
Self {
active_component: ListCid::IssueBrowser,
shortcuts,
}
}
@@ -80,54 +40,30 @@ impl HomeView {
fn activate(
&mut self,
app: &mut Application<Cid, Message, NoUserEvent>,
cid: HomeCid,
cid: ListCid,
) -> Result<()> {
self.active_component = cid;
let cid = Cid::Home(self.active_component.clone());
let cid = Cid::List(self.active_component.clone());
app.active(&cid)?;
app.attr(&cid, Attribute::Focus, AttrValue::Flag(true))?;
Ok(())
}
fn build_shortcuts(theme: &Theme) -> HashMap<HomeCid, Widget<Shortcuts>> {
[
(
HomeCid::Dashboard,
widget::common::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "q", "quit"),
],
),
fn build_shortcuts(theme: &Theme) -> HashMap<ListCid, Widget<Shortcuts>> {
[(
ListCid::IssueBrowser,
widget::common::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "↑/↓", "navigate"),
widget::common::shortcut(theme, "enter", "show"),
widget::common::shortcut(theme, "o", "open"),
widget::common::shortcut(theme, "q", "quit"),
],
),
(
HomeCid::IssueBrowser,
widget::common::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "↑/↓", "navigate"),
widget::common::shortcut(theme, "enter", "show"),
widget::common::shortcut(theme, "o", "open"),
widget::common::shortcut(theme, "q", "quit"),
],
),
),
(
HomeCid::PatchBrowser,
widget::common::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "↑/↓", "navigate"),
widget::common::shortcut(theme, "enter", "show"),
widget::common::shortcut(theme, "q", "quit"),
],
),
),
]
)]
.iter()
.cloned()
.collect()
@@ -138,37 +74,16 @@ impl HomeView {
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
cid: HomeCid,
) -> Result<()> {
let context = match cid {
HomeCid::IssueBrowser => {
let state = app.state(&Cid::Home(HomeCid::IssueBrowser))?;
let progress = match state {
State::Tup2((StateValue::Usize(step), StateValue::Usize(total))) => {
Progress::Step(step.saturating_add(1), total)
}
_ => Progress::None,
};
let context = widget::issue::browse_context(context, theme, progress);
Some(context)
let state = app.state(&Cid::List(ListCid::IssueBrowser))?;
let progress = match state {
State::Tup2((StateValue::Usize(step), StateValue::Usize(total))) => {
Progress::Step(step.saturating_add(1), total)
}
HomeCid::PatchBrowser => {
let state = app.state(&Cid::Home(HomeCid::PatchBrowser))?;
let progress = match state {
State::Tup2((StateValue::Usize(step), StateValue::Usize(total))) => {
Progress::Step(step.saturating_add(1), total)
}
_ => Progress::None,
};
let context = widget::issue::browse_context(context, theme, progress);
Some(context)
}
_ => None,
_ => Progress::None,
};
if let Some(context) = context {
app.remount(Cid::Home(HomeCid::Context), context.to_boxed(), vec![])?;
}
let context = ui::browse_context(context, theme, progress);
app.remount(Cid::List(ListCid::Context), context.to_boxed(), vec![])?;
Ok(())
}
@@ -176,11 +91,11 @@ impl HomeView {
fn update_shortcuts(
&self,
app: &mut Application<Cid, Message, NoUserEvent>,
cid: HomeCid,
cid: ListCid,
) -> Result<()> {
if let Some(shortcuts) = self.shortcuts.get(&cid) {
app.remount(
Cid::Home(HomeCid::Shortcuts),
Cid::List(ListCid::Shortcuts),
shortcuts.clone().to_boxed(),
vec![],
)?;
@@ -189,41 +104,32 @@ impl HomeView {
}
}
impl ViewPage for HomeView {
impl ViewPage<Cid, Message> for ListPage {
fn mount(
&self,
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
) -> Result<()> {
let navigation = widget::home::navigation(theme);
let navigation = ui::list_navigation(theme);
let header = widget::common::app_header(context, theme, Some(navigation)).to_boxed();
let issue_browser = ui::issues(context, theme, None).to_boxed();
let dashboard = widget::home::dashboard(context, theme).to_boxed();
let issue_browser = widget::home::issues(context, theme, None).to_boxed();
let patch_browser = widget::home::patches(context, theme, None).to_boxed();
app.remount(Cid::List(ListCid::Header), header, vec![])?;
app.remount(Cid::List(ListCid::IssueBrowser), issue_browser, vec![])?;
app.remount(Cid::Home(HomeCid::Header), header, vec![])?;
app.remount(Cid::Home(HomeCid::Dashboard), dashboard, vec![])?;
app.remount(Cid::Home(HomeCid::IssueBrowser), issue_browser, vec![])?;
app.remount(Cid::Home(HomeCid::PatchBrowser), patch_browser, vec![])?;
let active_component = Cid::Home(self.active_component.clone());
app.active(&active_component)?;
app.active(&Cid::List(self.active_component.clone()))?;
self.update_shortcuts(app, self.active_component.clone())?;
self.update_context(app, context, theme, self.active_component.clone())?;
self.update_context(app, context, theme)?;
Ok(())
}
fn unmount(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
app.umount(&Cid::Home(HomeCid::Header))?;
app.umount(&Cid::Home(HomeCid::Dashboard))?;
app.umount(&Cid::Home(HomeCid::IssueBrowser))?;
app.umount(&Cid::Home(HomeCid::PatchBrowser))?;
app.umount(&Cid::Home(HomeCid::Context))?;
app.umount(&Cid::Home(HomeCid::Shortcuts))?;
app.umount(&Cid::List(ListCid::Header))?;
app.umount(&Cid::List(ListCid::IssueBrowser))?;
app.umount(&Cid::List(ListCid::Context))?;
app.umount(&Cid::List(ListCid::Shortcuts))?;
Ok(())
}
@@ -234,28 +140,19 @@ impl ViewPage for HomeView {
theme: &Theme,
message: Message,
) -> Result<Option<Message>> {
match message {
Message::NavigationChanged(index) => {
self.activate(app, HomeCid::from(index as usize))?;
self.update_shortcuts(app, self.active_component.clone())?;
}
Message::Home(HomeMessage::RefreshIssues(id)) => {
let selected = match id {
Some(id) => {
cob::issue::find(context.repository(), &id)?.map(|issue| (id, issue))
}
_ => None,
};
if let Message::Issue(IssueMessage::Reload(id)) = message {
let selected = match id {
Some(id) => cob::issue::find(context.repository(), &id)?.map(|issue| (id, issue)),
_ => None,
};
let issue_browser = widget::home::issues(context, theme, selected).to_boxed();
app.remount(Cid::Home(HomeCid::IssueBrowser), issue_browser, vec![])?;
let issue_browser = ui::issues(context, theme, selected).to_boxed();
app.remount(Cid::List(ListCid::IssueBrowser), issue_browser, vec![])?;
self.activate(app, HomeCid::IssueBrowser)?;
}
_ => {}
self.activate(app, ListCid::IssueBrowser)?;
}
self.update_context(app, context, theme, self.active_component.clone())?;
self.update_context(app, context, theme)?;
Ok(None)
}
@@ -265,23 +162,19 @@ impl ViewPage for HomeView {
let shortcuts_h = 1u16;
let layout = layout::default_page(area, shortcuts_h);
app.view(&Cid::Home(HomeCid::Header), frame, layout.navigation);
app.view(&Cid::List(ListCid::Header), frame, layout.navigation);
app.view(
&Cid::Home(self.active_component.clone()),
&Cid::List(self.active_component.clone()),
frame,
layout.component,
);
if self.active_component != HomeCid::Dashboard {
app.view(&Cid::Home(HomeCid::Context), frame, layout.context);
}
app.view(&Cid::Home(HomeCid::Shortcuts), frame, layout.shortcuts);
app.view(&Cid::List(ListCid::Shortcuts), frame, layout.shortcuts);
}
fn subscribe(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
app.subscribe(
&Cid::Home(HomeCid::Header),
&Cid::List(ListCid::Header),
Sub::new(subscription::navigation_clause(), SubClause::Always),
)?;
@@ -290,7 +183,7 @@ impl ViewPage for HomeView {
fn unsubscribe(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
app.unsubscribe(
&Cid::Home(HomeCid::Header),
&Cid::List(ListCid::Header),
subscription::navigation_clause(),
)?;
@@ -391,7 +284,7 @@ impl IssuePage {
}
_ => Progress::None,
};
let context = widget::issue::browse_context(context, theme, progress);
let context = ui::browse_context(context, theme, progress);
Some(context)
}
IssueCid::Details => {
@@ -400,11 +293,11 @@ impl IssuePage {
State::One(StateValue::Usize(scroll)) => Progress::Percentage(scroll),
_ => Progress::None,
};
let context = widget::issue::description_context(context, theme, progress);
let context = ui::description_context(context, theme, progress);
Some(context)
}
IssueCid::Form => {
let context = widget::issue::form_context(context, theme, Progress::None);
let context = ui::form_context(context, theme, Progress::None);
Some(context)
}
_ => None,
@@ -433,22 +326,23 @@ impl IssuePage {
}
}
impl ViewPage for IssuePage {
impl ViewPage<Cid, Message> for IssuePage {
fn mount(
&self,
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
) -> Result<()> {
let header = widget::common::app_header(context, theme, None).to_boxed();
let list = widget::issue::list(context, theme, self.issue.clone()).to_boxed();
let navigation = ui::list_navigation(theme);
let header = widget::common::app_header(context, theme, Some(navigation)).to_boxed();
let list = ui::list(context, theme, self.issue.clone()).to_boxed();
app.remount(Cid::Issue(IssueCid::Header), header, vec![])?;
app.remount(Cid::Issue(IssueCid::List), list, vec![])?;
if let Some((id, issue)) = &self.issue {
let comments = issue.comments().collect::<Vec<_>>();
let details = widget::issue::details(
let details = ui::details(
context,
theme,
(*id, issue.clone()),
@@ -496,10 +390,10 @@ impl ViewPage for IssuePage {
if let Some(issue) = cob::issue::find(repo, &id)? {
self.issue = Some((id, issue.clone()));
let list = widget::issue::list(context, theme, self.issue.clone()).to_boxed();
let list = ui::list(context, theme, self.issue.clone()).to_boxed();
let comments = issue.comments().collect::<Vec<_>>();
let details = widget::issue::details(
let details = ui::details(
context,
theme,
(id, issue.clone()),
@@ -516,7 +410,7 @@ impl ViewPage for IssuePage {
if let Some(issue) = cob::issue::find(repo, &id)? {
self.issue = Some((id, issue.clone()));
let comments = issue.comments().collect::<Vec<_>>();
let details = widget::issue::details(
let details = ui::details(
context,
theme,
(id, issue.clone()),
@@ -531,8 +425,8 @@ impl ViewPage for IssuePage {
self.update_shortcuts(app, self.active_component.clone())?;
}
Message::Issue(IssueMessage::OpenForm) => {
let new_form = widget::issue::new_form(context, theme).to_boxed();
let list = widget::issue::list(context, theme, None).to_boxed();
let new_form = ui::new_form(context, theme).to_boxed();
let list = ui::list(context, theme, None).to_boxed();
app.remount(Cid::Issue(IssueCid::List), list, vec![])?;
app.remount(Cid::Issue(IssueCid::Form), new_form, vec![])?;
@@ -545,7 +439,7 @@ impl ViewPage for IssuePage {
Message::Issue(IssueMessage::HideForm) => {
app.umount(&Cid::Issue(IssueCid::Form))?;
let list = widget::issue::list(context, theme, self.issue.clone()).to_boxed();
let list = ui::list(context, theme, self.issue.clone()).to_boxed();
app.remount(Cid::Issue(IssueCid::List), list, vec![])?;
app.subscribe(
@@ -559,7 +453,7 @@ impl ViewPage for IssuePage {
return Ok(Some(Message::Issue(IssueMessage::Focus(IssueCid::List))));
}
Message::FormSubmitted(id) => {
if id == widget::issue::FORM_ID_EDIT {
if id == ui::FORM_ID_EDIT {
let state = app.state(&Cid::Issue(IssueCid::Form))?;
if let State::Linked(mut states) = state {
let mut missing_values = vec![];
@@ -654,228 +548,3 @@ impl ViewPage for IssuePage {
Ok(())
}
}
///
/// Patch detail page
///
pub struct PatchView {
active_component: PatchCid,
patch: (PatchId, Patch),
shortcuts: HashMap<PatchCid, Widget<Shortcuts>>,
}
impl PatchView {
pub fn new(theme: Theme, patch: (PatchId, Patch)) -> Self {
let shortcuts = Self::build_shortcuts(&theme);
PatchView {
active_component: PatchCid::Activity,
patch,
shortcuts,
}
}
fn build_shortcuts(theme: &Theme) -> HashMap<PatchCid, Widget<Shortcuts>> {
[
(
PatchCid::Activity,
widget::common::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "esc", "back"),
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "q", "quit"),
],
),
),
(
PatchCid::Files,
widget::common::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "esc", "back"),
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "q", "quit"),
],
),
),
]
.iter()
.cloned()
.collect()
}
fn update_shortcuts(
&self,
app: &mut Application<Cid, Message, NoUserEvent>,
cid: PatchCid,
) -> Result<()> {
if let Some(shortcuts) = self.shortcuts.get(&cid) {
app.remount(
Cid::Patch(PatchCid::Shortcuts),
shortcuts.clone().to_boxed(),
vec![],
)?;
}
Ok(())
}
}
impl ViewPage for PatchView {
fn mount(
&self,
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
) -> Result<()> {
let navigation = widget::patch::navigation(theme);
let header = widget::common::app_header(context, theme, Some(navigation)).to_boxed();
let activity = widget::patch::activity(theme).to_boxed();
let files = widget::patch::files(theme).to_boxed();
let context = widget::patch::context(context, theme, self.patch.clone()).to_boxed();
app.remount(Cid::Patch(PatchCid::Header), header, vec![])?;
app.remount(Cid::Patch(PatchCid::Activity), activity, vec![])?;
app.remount(Cid::Patch(PatchCid::Files), files, vec![])?;
app.remount(Cid::Patch(PatchCid::Context), context, vec![])?;
let active_component = Cid::Patch(self.active_component.clone());
app.active(&active_component)?;
self.update_shortcuts(app, self.active_component.clone())?;
Ok(())
}
fn unmount(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
app.umount(&Cid::Patch(PatchCid::Header))?;
app.umount(&Cid::Patch(PatchCid::Activity))?;
app.umount(&Cid::Patch(PatchCid::Files))?;
app.umount(&Cid::Patch(PatchCid::Context))?;
app.umount(&Cid::Patch(PatchCid::Shortcuts))?;
Ok(())
}
fn update(
&mut self,
app: &mut Application<Cid, Message, NoUserEvent>,
_context: &Context,
_theme: &Theme,
message: Message,
) -> Result<Option<Message>> {
if let Message::NavigationChanged(index) = message {
self.active_component = PatchCid::from(index as usize);
let active_component = Cid::Patch(self.active_component.clone());
app.active(&active_component)?;
self.update_shortcuts(app, self.active_component.clone())?;
}
Ok(None)
}
fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, frame: &mut Frame) {
let area = frame.size();
let shortcuts_h = 1u16;
let layout = layout::default_page(area, shortcuts_h);
app.view(&Cid::Patch(PatchCid::Header), frame, layout.navigation);
app.view(
&Cid::Patch(self.active_component.clone()),
frame,
layout.component,
);
app.view(&Cid::Patch(PatchCid::Context), frame, layout.context);
app.view(&Cid::Patch(PatchCid::Shortcuts), frame, layout.shortcuts);
}
fn subscribe(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
app.subscribe(
&Cid::Patch(PatchCid::Header),
Sub::new(subscription::navigation_clause(), SubClause::Always),
)?;
Ok(())
}
fn unsubscribe(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
app.unsubscribe(
&Cid::Patch(PatchCid::Header),
subscription::navigation_clause(),
)?;
Ok(())
}
}
/// View pages need to preserve their state (e.g. selected navigation tab, contents
/// and the selected row of a table). Therefor they should not be (re-)created
/// each time they are displayed.
/// Instead the application can push a new page onto the page stack if it needs to
/// be displayed. Its components are then created using the internal state. If a
/// new page needs to be displayed, it will also be pushed onto the stack. Leaving
/// that page again will pop it from the stack. The application can then return to
/// the previously displayed page in the state it was left.
#[derive(Default)]
pub struct PageStack {
pages: Vec<Box<dyn ViewPage>>,
}
impl PageStack {
pub fn push(
&mut self,
page: Box<dyn ViewPage>,
app: &mut Application<Cid, Message, NoUserEvent>,
context: &Context,
theme: &Theme,
) -> Result<()> {
if let Some(page) = self.pages.last() {
page.unsubscribe(app)?;
}
page.mount(app, context, theme)?;
page.subscribe(app)?;
self.pages.push(page);
Ok(())
}
pub fn pop(&mut self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
self.peek_mut()?.unsubscribe(app)?;
self.peek_mut()?.unmount(app)?;
self.pages.pop();
self.peek_mut()?.subscribe(app)?;
Ok(())
}
pub fn peek_mut(&mut self) -> Result<&mut Box<dyn ViewPage>> {
match self.pages.last_mut() {
Some(page) => Ok(page),
None => Err(anyhow::anyhow!(
"Could not peek active page. Page stack is empty."
)),
}
}
}
impl From<usize> for HomeCid {
fn from(index: usize) -> Self {
match index {
0 => HomeCid::Dashboard,
1 => HomeCid::IssueBrowser,
2 => HomeCid::PatchBrowser,
_ => HomeCid::Dashboard,
}
}
}
impl From<usize> for PatchCid {
fn from(index: usize) -> Self {
match index {
0 => PatchCid::Activity,
1 => PatchCid::Files,
_ => PatchCid::Activity,
}
}
}
-22
View File
@@ -1,22 +0,0 @@
use tuirealm::event::{Key, KeyEvent, KeyModifiers};
use tuirealm::SubEventClause;
pub fn navigation_clause<UserEvent>() -> SubEventClause<UserEvent>
where
UserEvent: Clone + Eq + PartialEq + PartialOrd,
{
SubEventClause::Keyboard(KeyEvent {
code: Key::Tab,
modifiers: KeyModifiers::NONE,
})
}
pub fn global_clause<UserEvent>() -> SubEventClause<UserEvent>
where
UserEvent: Clone + Eq + PartialEq + PartialOrd,
{
SubEventClause::Keyboard(KeyEvent {
code: Key::Char('q'),
modifiers: KeyModifiers::NONE,
})
}
+104 -77
View File
@@ -3,30 +3,103 @@ use radicle::cob::thread::CommentId;
use radicle::cob::issue::Issue;
use radicle::cob::issue::IssueId;
use tuirealm::tui::layout::{Constraint, Direction, Layout};
use super::common::container::{Container, LabeledContainer};
use super::common::context::{ContextBar, Progress};
use super::common::form::Form;
use super::common::label::Textarea;
use super::common::list::List;
use super::common::list::Property;
use super::Widget;
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::tui::layout::{Constraint, Direction, Layout, Rect};
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
use crate::ui::cob;
use crate::ui::cob::IssueItem;
use crate::ui::context::Context;
use crate::ui::theme::Theme;
use crate::ui::widget::common::form::TextArea;
use crate::ui::widget::common::form::TextField;
use radicle_tui::ui::cob;
use radicle_tui::ui::cob::IssueItem;
use radicle_tui::ui::context::Context;
use radicle_tui::ui::theme::Theme;
use radicle_tui::ui::widget::common;
use radicle_tui::ui::widget::{Widget, WidgetComponent};
use super::*;
use common::container::{Container, Tabs};
use common::context::{ContextBar, Progress};
use common::form::{Form, TextArea, TextField};
use common::label::Textarea;
use common::list::{ColumnWidth, List, Property, Table};
pub const FORM_ID_EDIT: &str = "edit-form";
pub struct IssueBrowser {
items: Vec<IssueItem>,
table: Widget<Table<IssueItem, 7>>,
}
impl IssueBrowser {
pub fn new(context: &Context, theme: &Theme, selected: Option<(IssueId, Issue)>) -> Self {
let header = [
common::label(" ● "),
common::label("ID"),
common::label("Title"),
common::label("Author"),
common::label("Tags"),
common::label("Assignees"),
common::label("Opened"),
];
let widths = [
ColumnWidth::Fixed(3),
ColumnWidth::Fixed(7),
ColumnWidth::Grow,
ColumnWidth::Fixed(21),
ColumnWidth::Fixed(25),
ColumnWidth::Fixed(21),
ColumnWidth::Fixed(18),
];
let repo = context.repository();
let mut items = vec![];
for (id, issue) in context.issues() {
if let Ok(item) = IssueItem::try_from((context.profile(), repo, *id, issue.clone())) {
items.push(item);
}
}
items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
items.sort_by(|a, b| b.state().cmp(a.state()));
let selected = match selected {
Some((id, issue)) => Some(IssueItem::from((context.profile(), repo, id, issue))),
_ => items.first().cloned(),
};
let table = Widget::new(Table::new(&items, selected, header, widths, theme.clone()))
.highlight(theme.colors.item_list_highlighted_bg);
Self { items, table }
}
pub fn items(&self) -> &Vec<IssueItem> {
&self.items
}
}
impl WidgetComponent for IssueBrowser {
fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
let focus = properties
.get_or(Attribute::Focus, AttrValue::Flag(false))
.unwrap_flag();
self.table.attr(Attribute::Focus, AttrValue::Flag(focus));
self.table.view(frame, area);
}
fn state(&self) -> State {
self.table.state()
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.table.perform(cmd)
}
}
pub struct LargeList {
items: Vec<IssueItem>,
list: Widget<LabeledContainer>,
list: Widget<Container>,
}
impl LargeList {
@@ -48,7 +121,7 @@ impl LargeList {
let list = Widget::new(List::new(&items, selected, theme.clone()))
.highlight(theme.colors.item_list_highlighted_bg);
let container = common::labeled_container(theme, "Issues", list.to_boxed());
let container = common::container(theme, list.to_boxed());
Self {
items,
@@ -176,7 +249,7 @@ impl IssueDetails {
) -> Self {
Self {
header: header(context, theme, issue),
description: issue::description(context, theme, description),
description: self::description(context, theme, description),
}
}
}
@@ -246,65 +319,11 @@ impl WidgetComponent for CommentBody {
}
}
pub struct NewForm {
/// The issue this form writes its input values to.
_issue: Issue,
/// The actual form.
form: Widget<Form>,
}
impl NewForm {
pub fn new(theme: &Theme) -> Self {
use tuirealm::props::Layout;
let title = Widget::new(TextField::new(theme.clone(), "Title")).to_boxed();
let tags = Widget::new(TextField::new(theme.clone(), "Labels (bug, ...)")).to_boxed();
let assignees = Widget::new(TextField::new(
theme.clone(),
"Assignees (z6MkvAdxCp1oLVVTsqYvev9YrhSN3gBQNUSM45hhy4pgkexk, ...)",
))
.to_boxed();
let description = Widget::new(TextArea::new(theme.clone(), "Description")).to_boxed();
let mut form = Widget::new(Form::new(
theme.clone(),
vec![title, tags, assignees, description],
));
form.attr(
Attribute::Layout,
AttrValue::Layout(
Layout::default().constraints(
[
Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(3),
Constraint::Min(3),
]
.as_ref(),
),
),
);
Self {
_issue: Issue::default(),
form,
}
}
}
impl WidgetComponent for NewForm {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
self.form.view(frame, area);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.form.perform(cmd)
}
pub fn list_navigation(theme: &Theme) -> Widget<Tabs> {
common::tabs(
theme,
vec![common::reversable_label("issues").foreground(theme.colors.tabs_highlighted_fg)],
)
}
pub fn list(
@@ -406,3 +425,11 @@ pub fn form_context(_context: &Context, theme: &Theme, progress: Progress) -> Wi
common::context::bar(theme, "Open", "", "", "", &progress.to_string())
.custom(ContextBar::PROP_EDIT_MODE, AttrValue::Flag(true))
}
pub fn issues(
context: &Context,
theme: &Theme,
selected: Option<(IssueId, Issue)>,
) -> Widget<IssueBrowser> {
Widget::new(IssueBrowser::new(context, theme, selected))
}
+1 -2
View File
@@ -7,7 +7,6 @@ use radicle_tui::ui::widget::common::container::{
};
use radicle_tui::ui::widget::common::context::{ContextBar, Shortcuts};
use radicle_tui::ui::widget::common::list::PropertyList;
use radicle_tui::ui::widget::home::PatchBrowser;
use radicle_tui::ui::widget::Widget;
@@ -46,7 +45,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<AppHeader> {
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchBrowser> {
impl tuirealm::Component<Message, NoUserEvent> for Widget<ui::PatchBrowser> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Up, .. })
+1 -1
View File
@@ -96,7 +96,7 @@ impl ViewPage<Cid, Message> for ListView {
) -> Result<()> {
let navigation = ui::list_navigation(theme);
let header = widget::common::app_header(context, theme, Some(navigation)).to_boxed();
let patch_browser = widget::home::patches(context, theme, None).to_boxed();
let patch_browser = ui::patches(context, theme, None).to_boxed();
app.remount(Cid::List(ListCid::Header), header, vec![])?;
app.remount(Cid::List(ListCid::PatchBrowser), patch_browser, vec![])?;
+90 -1
View File
@@ -4,15 +4,96 @@ use tuirealm::command::{Cmd, CmdResult};
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
use radicle_tui::ui::cob;
use radicle_tui::ui::cob::PatchItem;
use radicle_tui::ui::context::Context;
use radicle_tui::ui::layout;
use radicle_tui::ui::theme::Theme;
use radicle_tui::ui::widget::common;
use radicle_tui::ui::widget::{Widget, WidgetComponent};
use radicle_tui::ui::{cob, layout};
use common::container::Tabs;
use common::context::{ContextBar, Progress};
use common::label::Label;
use common::list::{ColumnWidth, Table};
pub struct PatchBrowser {
items: Vec<PatchItem>,
table: Widget<Table<PatchItem, 8>>,
}
impl PatchBrowser {
pub fn new(context: &Context, theme: &Theme, selected: Option<(PatchId, Patch)>) -> Self {
let header = [
common::label(" ● "),
common::label("ID"),
common::label("Title"),
common::label("Author"),
common::label("Head"),
common::label("+"),
common::label("-"),
common::label("Updated"),
];
let widths = [
ColumnWidth::Fixed(3),
ColumnWidth::Fixed(7),
ColumnWidth::Grow,
ColumnWidth::Fixed(21),
ColumnWidth::Fixed(7),
ColumnWidth::Fixed(4),
ColumnWidth::Fixed(4),
ColumnWidth::Fixed(18),
];
let repo = context.repository();
let mut items = vec![];
for (id, patch) in context.patches() {
if let Ok(item) = PatchItem::try_from((context.profile(), repo, *id, patch.clone())) {
items.push(item);
}
}
items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
items.sort_by(|a, b| a.state().cmp(b.state()));
let selected = match selected {
Some((id, patch)) => {
Some(PatchItem::try_from((context.profile(), repo, id, patch)).unwrap())
}
_ => items.first().cloned(),
};
let table = Widget::new(Table::new(&items, selected, header, widths, theme.clone()))
.highlight(theme.colors.item_list_highlighted_bg);
Self { items, table }
}
pub fn items(&self) -> &Vec<PatchItem> {
&self.items
}
}
impl WidgetComponent for PatchBrowser {
fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
let focus = properties
.get_or(Attribute::Focus, AttrValue::Flag(false))
.unwrap_flag();
self.table.attr(Attribute::Focus, AttrValue::Flag(focus));
self.table.view(frame, area);
}
fn state(&self) -> State {
self.table.state()
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.table.perform(cmd)
}
}
pub struct Activity {
label: Widget<Label>,
@@ -93,6 +174,14 @@ pub fn navigation(theme: &Theme) -> Widget<Tabs> {
)
}
pub fn patches(
context: &Context,
theme: &Theme,
selected: Option<(PatchId, Patch)>,
) -> Widget<PatchBrowser> {
Widget::new(PatchBrowser::new(context, theme, selected))
}
pub fn activity(theme: &Theme) -> Widget<Activity> {
let not_implemented = common::label("not implemented").foreground(theme.colors.default_fg);
let activity = Activity::new(not_implemented);
-3
View File
@@ -1,7 +1,4 @@
pub mod common;
pub mod home;
pub mod issue;
pub mod patch;
mod utils;
use std::ops::Deref;
-237
View File
@@ -1,237 +0,0 @@
use radicle::cob::issue::{Issue, IssueId};
use radicle::cob::patch::{Patch, PatchId};
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
use super::common;
use super::common::container::{LabeledContainer, Tabs};
use super::common::list::{ColumnWidth, Table};
use super::{Widget, WidgetComponent};
use crate::ui::cob::{IssueItem, PatchItem};
use crate::ui::context::Context;
use crate::ui::theme::Theme;
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) {
self.about.view(frame, area);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct IssueBrowser {
items: Vec<IssueItem>,
table: Widget<Table<IssueItem, 7>>,
}
impl IssueBrowser {
pub fn new(context: &Context, theme: &Theme, selected: Option<(IssueId, Issue)>) -> Self {
let header = [
common::label(" ● "),
common::label("ID"),
common::label("Title"),
common::label("Author"),
common::label("Tags"),
common::label("Assignees"),
common::label("Opened"),
];
let widths = [
ColumnWidth::Fixed(3),
ColumnWidth::Fixed(7),
ColumnWidth::Grow,
ColumnWidth::Fixed(21),
ColumnWidth::Fixed(25),
ColumnWidth::Fixed(21),
ColumnWidth::Fixed(18),
];
let repo = context.repository();
let mut items = vec![];
for (id, issue) in context.issues() {
if let Ok(item) = IssueItem::try_from((context.profile(), repo, *id, issue.clone())) {
items.push(item);
}
}
items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
items.sort_by(|a, b| b.state().cmp(a.state()));
let selected = match selected {
Some((id, issue)) => Some(IssueItem::from((context.profile(), repo, id, issue))),
_ => items.first().cloned(),
};
let table = Widget::new(Table::new(&items, selected, header, widths, theme.clone()))
.highlight(theme.colors.item_list_highlighted_bg);
Self { items, table }
}
pub fn items(&self) -> &Vec<IssueItem> {
&self.items
}
}
impl WidgetComponent for IssueBrowser {
fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
let focus = properties
.get_or(Attribute::Focus, AttrValue::Flag(false))
.unwrap_flag();
self.table.attr(Attribute::Focus, AttrValue::Flag(focus));
self.table.view(frame, area);
}
fn state(&self) -> State {
self.table.state()
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.table.perform(cmd)
}
}
pub struct PatchBrowser {
items: Vec<PatchItem>,
table: Widget<Table<PatchItem, 8>>,
}
impl PatchBrowser {
pub fn new(context: &Context, theme: &Theme, selected: Option<(PatchId, Patch)>) -> Self {
let header = [
common::label(" ● "),
common::label("ID"),
common::label("Title"),
common::label("Author"),
common::label("Head"),
common::label("+"),
common::label("-"),
common::label("Updated"),
];
let widths = [
ColumnWidth::Fixed(3),
ColumnWidth::Fixed(7),
ColumnWidth::Grow,
ColumnWidth::Fixed(21),
ColumnWidth::Fixed(7),
ColumnWidth::Fixed(4),
ColumnWidth::Fixed(4),
ColumnWidth::Fixed(18),
];
let repo = context.repository();
let mut items = vec![];
for (id, patch) in context.patches() {
if let Ok(item) = PatchItem::try_from((context.profile(), repo, *id, patch.clone())) {
items.push(item);
}
}
items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
items.sort_by(|a, b| a.state().cmp(b.state()));
let selected = match selected {
Some((id, patch)) => {
Some(PatchItem::try_from((context.profile(), repo, id, patch)).unwrap())
}
_ => items.first().cloned(),
};
let table = Widget::new(Table::new(&items, selected, header, widths, theme.clone()))
.highlight(theme.colors.item_list_highlighted_bg);
Self { items, table }
}
pub fn items(&self) -> &Vec<PatchItem> {
&self.items
}
}
impl WidgetComponent for PatchBrowser {
fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
let focus = properties
.get_or(Attribute::Focus, AttrValue::Flag(false))
.unwrap_flag();
self.table.attr(Attribute::Focus, AttrValue::Flag(focus));
self.table.view(frame, area);
}
fn state(&self) -> State {
self.table.state()
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.table.perform(cmd)
}
}
pub fn navigation(theme: &Theme) -> Widget<Tabs> {
common::tabs(
theme,
vec![
common::reversable_label("dashboard").foreground(theme.colors.tabs_highlighted_fg),
common::reversable_label("issues").foreground(theme.colors.tabs_highlighted_fg),
common::reversable_label("patches").foreground(theme.colors.tabs_highlighted_fg),
],
)
}
pub fn dashboard(context: &Context, theme: &Theme) -> Widget<Dashboard> {
let about = common::labeled_container(
theme,
"about",
common::property_list(
theme,
vec![
common::property(theme, "id", &context.id().to_string()),
common::property(theme, "name", context.project().name()),
common::property(theme, "description", context.project().description()),
],
)
.to_boxed(),
);
let dashboard = Dashboard::new(about);
Widget::new(dashboard)
}
pub fn patches(
context: &Context,
theme: &Theme,
selected: Option<(PatchId, Patch)>,
) -> Widget<PatchBrowser> {
Widget::new(PatchBrowser::new(context, theme, selected))
}
pub fn issues(
context: &Context,
theme: &Theme,
selected: Option<(IssueId, Issue)>,
) -> Widget<IssueBrowser> {
Widget::new(IssueBrowser::new(context, theme, selected))
}
-146
View File
@@ -1,146 +0,0 @@
use radicle::cob::patch::{Patch, PatchId};
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
use super::{Widget, WidgetComponent};
use super::common;
use super::common::container::Tabs;
use super::common::context::{ContextBar, Progress};
use super::common::label::Label;
use crate::ui::context::Context;
use crate::ui::theme::Theme;
use crate::ui::{cob, layout};
pub struct Activity {
label: Widget<Label>,
}
impl Activity {
pub fn new(label: Widget<Label>) -> Self {
Self { label }
}
}
impl WidgetComponent for Activity {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
self.label
.view(frame, layout::centered_label(label_w, area));
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct Files {
label: Widget<Label>,
}
impl Files {
pub fn new(label: Widget<Label>) -> Self {
Self { label }
}
}
impl WidgetComponent for Files {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
self.label
.view(frame, layout::centered_label(label_w, area));
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub fn navigation(theme: &Theme) -> Widget<Tabs> {
common::tabs(
theme,
vec![
common::reversable_label("activity").foreground(theme.colors.tabs_highlighted_fg),
common::reversable_label("files").foreground(theme.colors.tabs_highlighted_fg),
],
)
}
pub fn activity(theme: &Theme) -> Widget<Activity> {
let not_implemented = common::label("not implemented").foreground(theme.colors.default_fg);
let activity = Activity::new(not_implemented);
Widget::new(activity)
}
pub fn files(theme: &Theme) -> Widget<Files> {
let not_implemented = common::label("not implemented").foreground(theme.colors.default_fg);
let files = Files::new(not_implemented);
Widget::new(files)
}
pub fn context(context: &Context, theme: &Theme, patch: (PatchId, Patch)) -> Widget<ContextBar> {
let (id, patch) = patch;
let (_, rev) = patch.latest();
let is_you = *patch.author().id() == context.profile().did();
let id = cob::format::cob(&id);
let title = patch.title();
let author = cob::format_author(patch.author().id(), is_you);
let comments = rev.discussion().len();
common::context::bar(theme, "Patch", &id, title, &author, &comments.to_string())
}
pub fn browse_context(context: &Context, theme: &Theme, progress: Progress) -> Widget<ContextBar> {
use radicle::cob::patch::State;
let patches = context.patches();
let mut draft = 0;
let mut open = 0;
let mut archived = 0;
let mut merged = 0;
for (_, patch) in patches {
match patch.state() {
State::Draft => draft += 1,
State::Open { conflicts: _ } => open += 1,
State::Archived => archived += 1,
State::Merged {
commit: _,
revision: _,
} => merged += 1,
}
}
common::context::bar(
theme,
"Browse",
"",
"",
&format!("{draft} draft | {open} open | {archived} archived | {merged} merged"),
&progress.to_string(),
)
}