Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
tui: Make patch and issue items sortable
Erik Kundt committed 2 years ago
commit f478c6743b05f7aa23e0c2eb841129f4991116a3
parent b54d6b7d596cb4b39e29f369e6d5c0f7e6b0d0d6
3 files changed +66 -14
modified radicle-tui/src/app/event.rs
@@ -62,7 +62,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchBrowser> {
                code: Key::Enter, ..
            }) => self
                .selected_item()
-
                .map(|item| Message::Patch(PatchMessage::Show(item.id()))),
+
                .map(|item| Message::Patch(PatchMessage::Show(item.id().to_owned()))),
            _ => None,
        }
    }
@@ -85,7 +85,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<IssueBrowser> {
                code: Key::Enter, ..
            }) => self
                .selected_item()
-
                .map(|item| Message::Issue(IssueMessage::Show(item.id()))),
+
                .map(|item| Message::Issue(IssueMessage::Show(item.id().to_owned()))),
            _ => None,
        }
    }
modified radicle-tui/src/ui/cob.rs
@@ -55,8 +55,36 @@ pub struct PatchItem {
}

impl PatchItem {
-
    pub fn id(&self) -> PatchId {
-
        self.id
+
    pub fn id(&self) -> &PatchId {
+
        &self.id
+
    }
+

+
    pub fn state(&self) -> &PatchState {
+
        &self.state
+
    }
+

+
    pub fn title(&self) -> &String {
+
        &self.title
+
    }
+

+
    pub fn author(&self) -> &AuthorItem {
+
        &self.author
+
    }
+

+
    pub fn head(&self) -> &Oid {
+
        &self.head
+
    }
+

+
    pub fn added(&self) -> u16 {
+
        self.added
+
    }
+

+
    pub fn removed(&self) -> u16 {
+
        self.removed
+
    }
+

+
    pub fn timestamp(&self) -> &Timestamp {
+
        &self.timestamp
    }
}

@@ -140,8 +168,32 @@ pub struct IssueItem {
}

impl IssueItem {
-
    pub fn id(&self) -> IssueId {
-
        self.id
+
    pub fn id(&self) -> &IssueId {
+
        &self.id
+
    }
+

+
    pub fn state(&self) -> &IssueState {
+
        &self.state
+
    }
+

+
    pub fn title(&self) -> &String {
+
        &self.title
+
    }
+

+
    pub fn author(&self) -> &AuthorItem {
+
        &self.author
+
    }
+

+
    pub fn tags(&self) -> &Vec<Tag> {
+
        &self.tags
+
    }
+

+
    pub fn assignees(&self) -> &Vec<AuthorItem> {
+
        &self.assignees
+
    }
+

+
    pub fn timestamp(&self) -> &Timestamp {
+
        &self.timestamp
    }
}

modified radicle-tui/src/ui/widget/home.rs
@@ -84,10 +84,7 @@ impl IssueBrowser {
        ];

        let mut items = vec![];
-
        if let Ok(mut issues) = issues {
-
            issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
-
            issues.sort_by(|(_, a, _), (_, b, _)| a.state().cmp(b.state()));
-

+
        if let Ok(issues) = issues {
            for (id, patch, _) in issues {
                if let Ok(item) = IssueItem::try_from((context.profile(), &repo, id, patch)) {
                    items.push(item);
@@ -95,6 +92,9 @@ impl IssueBrowser {
            }
        }

+
        items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
+
        items.sort_by(|a, b| a.state().cmp(b.state()));
+

        let table = Widget::new(Table::new(&items, header, widths, theme.clone()))
            .highlight(theme.colors.item_list_highlighted_bg);

@@ -162,10 +162,7 @@ impl PatchBrowser {
        ];

        let mut items = vec![];
-
        if let Ok(mut patches) = patches {
-
            patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
-
            patches.sort_by(|(_, a, _), (_, b, _)| a.state().cmp(b.state()));
-

+
        if let Ok(patches) = patches {
            for (id, patch, _) in patches {
                if let Ok(item) = PatchItem::try_from((context.profile(), &repo, id, patch)) {
                    items.push(item);
@@ -173,6 +170,9 @@ impl PatchBrowser {
            }
        }

+
        items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
+
        items.sort_by(|a, b| a.state().cmp(b.state()));
+

        let table = Widget::new(Table::new(&items, header, widths, theme.clone()))
            .highlight(theme.colors.item_list_highlighted_bg);