Skip to content

Commit

Permalink
feat: improve initial behaivor PAT and instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
djego committed Oct 13, 2024
1 parent 47aecb7 commit 4f8aefc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
31 changes: 26 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,30 @@ fn main() -> Result<(), io::Error> {
KeyCode::Enter => {
if !app.pat_input.is_empty() {
app.config_pat = app.pat_input.lines().join("\n");
save_config(&app.config_pat).expect("Failed to save the configuration");
app.show_pat_popup = false;
app.set_success("PAT saved!".to_string());
let result = runtime.block_on(app.fetch_github_repo_info());
app.clear_message();
match result {
Ok(repo) => {
if let Some(link) = repo.html_url {
app.github_repository.set_url(link.to_string());
}
if let Some(branch) = repo.default_branch {
app.github_repository.set_default_branch(branch.clone());
app.pull_request.target_branch = branch;
app.set_success(
"PAT saved and validated successfully ✅".to_string(),
);
}

app.show_pat_popup = false;
app.github_repository.set_name(repo.name.clone());
save_config(&app.config_pat)
.expect("Failed to save the configuration");
}
Err(e) => {
app.set_error(format!("Error {:?}", e));
}
}
} else {
app.set_error("PAT cannot be empty!".to_string());
}
Expand All @@ -55,7 +76,7 @@ fn main() -> Result<(), io::Error> {

match app.input_mode {
InputMode::Normal => match key.code {
KeyCode::Char('q') => break,
KeyCode::Esc => break,
KeyCode::Char('e') => {
app.clear_message();
app.enter_edit_mode(app.current_field);
Expand Down Expand Up @@ -159,7 +180,7 @@ fn main() -> Result<(), io::Error> {
app.input_mode = InputMode::Editing;
app.show_confirm_popup = false;
}
KeyCode::Char('q') => {
KeyCode::Esc => {
app.input_mode = InputMode::Normal;
app.show_confirm_popup = false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ui/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ pub fn ui(f: &mut Frame, app: &App) {
// Instructions
let instructions = match app.input_mode {
InputMode::Normal => {
"[Normal mode] \n Press [n] to create PR, [e] to edit PR, [s] to sync with GitHub or [q] to quit"
"[Normal mode] \n Press [n] to create PR, [s] to sync with GitHub or [Esc] to quit"
}
InputMode::Editing => "[Editing mode] \n Press [Esc] to back, [Tab]/[BackTab] to move to next or previous field, [Enter] to send",
InputMode::Editing => "[Editing mode] \n Press [Tab]/[BackTab] to move to next or previous field, [Enter] to send or [Esc] to back",
InputMode::Creating => {
"[Confirm mode] \n Press [Enter] to confirm, Press [e] to continue editing, Press [q] to quit"
"[Confirm mode] \n Press [Enter] to confirm, Press [e] to continue editing, Press [Esc] to cancel"
}

};
Expand All @@ -174,7 +174,7 @@ pub fn ui(f: &mut Frame, app: &App) {
.borders(Borders::ALL)
.style(Style::default());

let area = centered_rect(35, 12, f.area());
let area = centered_rect(60, 12, f.area());
f.render_widget(Clear, area);
f.render_widget(popup_block, area);

Expand Down

0 comments on commit 4f8aefc

Please sign in to comment.