Pre-existing type mismatch where useEditorSave returns Promise<boolean> but useCommitFlow expected Promise<void>. The return value is unused. 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 | boolean>
|
|
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 }
|
|
}
|