eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
use crate::app::{actions::Action, state::AppState};

pub fn handle_navigation(mut state: AppState, action: &Action) -> Option<AppState> {
    match action {
        Action::SetCommits(commits) => {
            state.commits = commits.clone();
            if state.commit_selected >= state.commits.len() && !state.commits.is_empty() {
                state.commit_selected = state.commits.len() - 1;
            }
        }
        Action::CommitUp => {
            if state.commit_selected > 0 {
                state.commit_selected -= 1;
            }
        }
        Action::CommitDown => {
            if !state.commits.is_empty() && state.commit_selected < state.commits.len() - 1 {
                state.commit_selected += 1;
            }
        }
        Action::SetCommitDetail(detail) => {
            state.commit_detail = detail.clone();
        }
        Action::ShowConfirm(action, message) => {
            state.confirm_action = Some((**action).clone());
            state.confirm_message = Some(message.clone());
        }
        Action::ConfirmCancel => {
            state.confirm_action = None;
            state.confirm_message = None;
        }
        Action::ToggleLogGraph => {
            state.log_graph = !state.log_graph;
        }
        Action::SetLogGraphText(text) => {
            state.log_graph_text = text.clone();
        }
        Action::SetFileHistoryPath(path) => {
            state.file_history_path = path.clone();
        }
        Action::SetFeedback(msg) => {
            state.feedback_message = msg.clone();
        }
        _ => return None,
    }
    Some(state)
}