Root cause: Two problems caused "0 files changed": 1. loadModifiedFiles() was only called on mount, never refreshed after saves 2. Pending editor content wasn't flushed to disk before git commit Fix: - useEditorSave: add savePending() to flush unsaved content, onAfterSave callback to refresh git status after Cmd+S - useCommitFlow: new hook managing save→commit→push flow with proper sequencing (save pending → refresh files → show dialog → commit) - App.tsx: wire onAfterSave to loadModifiedFiles, use useCommitFlow - git.rs: include stdout in error when stderr is empty (fixes "nothing to commit" message being swallowed) - mock-tauri: track saved files so get_modified_files reflects edits Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { useCallback, useState } from 'react'
|
|
|
|
interface CommitFlowConfig {
|
|
savePending: () => Promise<void>
|
|
loadModifiedFiles: () => Promise<void>
|
|
commitAndPush: (message: string) => Promise<string>
|
|
setToastMessage: (msg: string | null) => void
|
|
}
|
|
|
|
/** Manages the Commit & Push dialog state and the save→commit→push flow. */
|
|
export function useCommitFlow({ savePending, loadModifiedFiles, commitAndPush, setToastMessage }: CommitFlowConfig) {
|
|
const [showCommitDialog, setShowCommitDialog] = useState(false)
|
|
|
|
const openCommitDialog = useCallback(async () => {
|
|
await savePending()
|
|
await loadModifiedFiles()
|
|
setShowCommitDialog(true)
|
|
}, [savePending, loadModifiedFiles])
|
|
|
|
const handleCommitPush = useCallback(async (message: string) => {
|
|
setShowCommitDialog(false)
|
|
try {
|
|
await savePending()
|
|
const result = await commitAndPush(message)
|
|
setToastMessage(result)
|
|
loadModifiedFiles()
|
|
} catch (err) {
|
|
console.error('Commit failed:', err)
|
|
setToastMessage(`Commit failed: ${err}`)
|
|
}
|
|
}, [savePending, commitAndPush, loadModifiedFiles, setToastMessage])
|
|
|
|
const closeCommitDialog = useCallback(() => setShowCommitDialog(false), [])
|
|
|
|
return { showCommitDialog, openCommitDialog, handleCommitPush, closeCommitDialog }
|
|
}
|