Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
feat(patch): Adds review action to list interface
Erik Kundt committed 1 year ago
commit dcc51b96a90d6e63cd69fae7f29e896f13816a1f
parent 9aa7fb2
4 files changed +32 -11
modified bin/commands/patch.rs
@@ -81,7 +81,7 @@ pub struct ListOptions {
    json: bool,
}

-
#[derive(Debug, Clone, PartialEq, Eq)]
+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct ReviewOptions {
    patch_id: Option<Rev>,
    revision_id: Option<Rev>,
@@ -255,7 +255,7 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
            let rid = options.repo.unwrap_or(rid);

            // Run TUI with patch list interface
-
            let selection = interface::list(opts.clone(), profile, rid).await?;
+
            let selection = interface::list(opts.clone(), profile.clone(), rid).await?;

            if opts.json {
                let selection = selection
@@ -267,17 +267,24 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul

                eprint!("{selection}");
            } else if let Some(selection) = selection {
-
                let mut args = vec![];
+
                if let Some(operation) = selection.operation.clone() {
+
                    let mut args = vec![operation.to_string()];

-
                if let Some(operation) = selection.operation {
-
                    args.push(operation.to_string());
-
                }
-
                if let Some(id) = selection.ids.first() {
-
                    args.push(format!("{id}"));
-
                }
+
                    if let Some(id) = selection.ids.first() {
+
                        args.push(format!("{id}"));

-
                let args = args.into_iter().map(OsString::from).collect::<Vec<_>>();
-
                let _ = crate::terminal::run_rad(Some("patch"), &args);
+
                        match operation.as_str() {
+
                            "review" => {
+
                                let opts = ReviewOptions::default();
+
                                interface::review(opts, profile, rid, *id).await?;
+
                            }
+
                            _ => {
+
                                let args = args.into_iter().map(OsString::from).collect::<Vec<_>>();
+
                                let _ = crate::terminal::run_rad(Some("patch"), &args);
+
                            }
+
                        }
+
                    }
+
                }
            }
        }
        Operation::Review { ref opts } => {
modified bin/commands/patch/common.rs
@@ -19,6 +19,7 @@ pub enum Mode {
pub enum PatchOperation {
    Checkout,
    Diff,
+
    Review,
    Show,
}

@@ -31,6 +32,9 @@ impl Display for PatchOperation {
            PatchOperation::Diff => {
                write!(f, "diff")
            }
+
            PatchOperation::Review => {
+
                write!(f, "review")
+
            }
            PatchOperation::Show => {
                write!(f, "show")
            }
modified bin/commands/patch/list.rs
@@ -233,6 +233,7 @@ fn browser_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Mes
                        ("enter", "show"),
                        ("c", "checkout"),
                        ("d", "diff"),
+
                        ("r", "review"),
                        ("/", "search"),
                        ("?", "help"),
                    ],
@@ -266,6 +267,9 @@ fn browser_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Mes
                    Key::Char('d') => Some(Message::Exit {
                        operation: Some(PatchOperation::Diff),
                    }),
+
                    Key::Char('r') => Some(Message::Exit {
+
                        operation: Some(PatchOperation::Review),
+
                    }),
                    _ => None,
                }
            } else {
modified bin/commands/patch/list/imui.rs
@@ -277,6 +277,7 @@ impl Show<Message> for App {
                                                ("enter", "show"),
                                                ("c", "checkout"),
                                                ("d", "diff"),
+
                                                ("r", "review"),
                                                ("/", "search"),
                                                ("?", "help"),
                                            ]
@@ -300,6 +301,11 @@ impl Show<Message> for App {
                                        operation: Some(PatchOperation::Diff),
                                    });
                                }
+
                                if ui.input_global(|key| key == Key::Char('r')) {
+
                                    ui.send_message(Message::Exit {
+
                                        operation: Some(PatchOperation::Review),
+
                                    });
+
                                }
                                if ui.input_global(|key| key == Key::Char('c')) {
                                    ui.send_message(Message::Exit {
                                        operation: Some(PatchOperation::Checkout),