#![allow(dead_code)]
use crate::app::{actions::Action, state::AppState};
use crate::app::actions::LogAction;
pub fn handle(state: &mut AppState, action: &Action) -> bool {
match action {
Action::ShowLogActionMenu => {
state.log_action_menu = true;
state.log_action_selected = 0;
if let Some(entry) = state.commits.get(state.commit_selected) {
state.log_action_commit_hash = Some(entry.hash.clone());
}
true
}
Action::HideLogActionMenu => {
state.log_action_menu = false;
state.log_action_commit_hash = None;
true
}
Action::LogActionUp => {
if state.log_action_selected > 0 {
state.log_action_selected -= 1;
}
true
}
Action::LogActionDown => {
let is_head = state
.commits
.first()
.map(|c| Some(&c.hash) == state.log_action_commit_hash.as_ref())
.unwrap_or(false);
let max_items = if is_head { 5 } else { 9 };
if state.log_action_selected + 1 < max_items {
state.log_action_selected += 1;
}
true
}
Action::ExecuteLogAction(log_action) => {
state.log_action_menu = false;
state.log_action_selected = 0;
match log_action {
LogAction::ShowDetail => {
if let Some(hash) = &state.log_action_commit_hash {
state.commit_detail = Some(hash.clone());
}
}
_ => {
}
}
state.log_action_commit_hash = None;
true
}
_ => false,
}
}