use crate::app::{actions::Action, state::AppState};
pub fn handle_log_menu(mut state: AppState, action: &Action) -> Option<AppState> {
match action {
Action::ShowLogActionMenu(hash) => {
state.log_action_menu = true;
state.log_action_selected = 0;
state.log_action_commit_hash = Some(hash.clone());
}
Action::HideLogActionMenu => {
state.log_action_menu = false;
state.log_action_selected = 0;
state.log_action_commit_hash = None;
}
Action::LogActionMenuUp => {
if state.log_action_selected > 0 {
state.log_action_selected -= 1;
}
}
Action::LogActionMenuDown => {
use crate::app::actions::LogAction;
let mut actions = vec![
LogAction::ShowDetail,
LogAction::CherryPick,
LogAction::Revert,
LogAction::ResetSoft,
LogAction::ResetMixed,
LogAction::ResetHard,
LogAction::CreateBranch,
LogAction::CreateTag,
];
if let Some(hash) = &state.log_action_commit_hash {
if let Some(first_commit) = state.commits.first() {
if first_commit.hash == *hash {
actions.insert(3, LogAction::Amend);
}
}
}
let max_idx = actions.len().saturating_sub(1);
if state.log_action_selected < max_idx {
state.log_action_selected += 1;
}
}
Action::ExecuteLogAction(_) => {
state.log_action_menu = false;
state.log_action_selected = 0;
state.log_action_commit_hash = None;
}
_ => return None,
}
Some(state)
}