eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
//! Commit detail async handlers.

use crate::app::{Action, reducer};
use crate::async_result::AsyncResult;
use crate::errors::ApplicationError;
use super::super::HandlerContext;

/// Handle async commit-related actions. Returns true if handled.
pub async fn handle(action: &Action, ctx: &mut HandlerContext<'_>) -> Result<bool, ApplicationError> {
    match action {
        Action::ShowCommitDetail(hash) => {
            // Extract values before reducer to avoid multiple clones
            let path = ctx.app.state.repo_path.clone();
            let hash_clone = hash.clone();
            let git_service = ctx.app.git_service.clone();
            let async_tx = ctx.app.async_tx.clone();
            
            // Update state (reducer takes ownership, so we clone once)
            ctx.app.state = reducer(ctx.app.state.clone(), Action::SetCommitDetail(Some("Loading commit details...".to_string())));
            
            // Spawn blocking task
            tokio::task::spawn_blocking(move || {
                match git_service.show_commit(&path, &hash_clone) {
                    Ok(detail) => { let _ = async_tx.send(AsyncResult::CommitDetailLoaded(detail)); }
                    Err(e) => { let _ = async_tx.send(AsyncResult::CommitDetailError(format!("show commit error: {e}"))); }
                }
            });
            
            Ok(true)
        }
        Action::CommitUp | Action::CommitDown if ctx.app.state.commit_detail.is_some() => {
            // Reload commit detail for newly selected commit
            if let Some(commit) = ctx.app.state.commits.get(ctx.app.state.commit_selected) {
                // Extract values before reducer to avoid multiple clones
                let hash = commit.hash.clone();
                let path = ctx.app.state.repo_path.clone();
                let git_service = ctx.app.git_service.clone();
                let async_tx = ctx.app.async_tx.clone();
                
                // Update state (reducer takes ownership, so we clone once)
                ctx.app.state = reducer(ctx.app.state.clone(), Action::SetCommitDetail(Some("Loading commit details...".to_string())));
                
                tokio::task::spawn_blocking(move || {
                    match git_service.show_commit(&path, &hash) {
                        Ok(detail) => { let _ = async_tx.send(AsyncResult::CommitDetailLoaded(detail)); }
                        Err(e) => { let _ = async_tx.send(AsyncResult::CommitDetailError(format!("show commit error: {e}"))); }
                    }
                });
            }
            Ok(false) // Let other handlers continue
        }
        _ => Ok(false),
    }
}