2026-02-15 13:00:10 +01:00
|
|
|
import { useState, useEffect, useRef } from 'react'
|
2026-02-16 16:56:44 +01:00
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
import { Badge } from '@/components/ui/badge'
|
2026-02-15 13:00:10 +01:00
|
|
|
|
|
|
|
|
interface CommitDialogProps {
|
|
|
|
|
open: boolean
|
|
|
|
|
modifiedCount: number
|
|
|
|
|
onCommit: (message: string) => void
|
|
|
|
|
onClose: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function CommitDialog({ open, modifiedCount, onCommit, onClose }: CommitDialogProps) {
|
|
|
|
|
const [message, setMessage] = useState('')
|
|
|
|
|
const inputRef = useRef<HTMLTextAreaElement>(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (open) {
|
|
|
|
|
setMessage('')
|
|
|
|
|
setTimeout(() => inputRef.current?.focus(), 50)
|
|
|
|
|
}
|
|
|
|
|
}, [open])
|
|
|
|
|
|
|
|
|
|
const handleSubmit = () => {
|
|
|
|
|
const trimmed = message.trim()
|
|
|
|
|
if (!trimmed) return
|
|
|
|
|
onCommit(trimmed)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
handleSubmit()
|
|
|
|
|
} else if (e.key === 'Escape') {
|
|
|
|
|
onClose()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-16 16:56:44 +01:00
|
|
|
<Dialog open={open} onOpenChange={(isOpen) => { if (!isOpen) onClose() }}>
|
|
|
|
|
<DialogContent showCloseButton={false} className="sm:max-w-[420px]">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<DialogTitle>Commit & Push</DialogTitle>
|
|
|
|
|
<Badge variant="secondary" className="text-xs">
|
|
|
|
|
{modifiedCount} file{modifiedCount !== 1 ? 's' : ''} changed
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
</DialogHeader>
|
2026-02-15 13:00:10 +01:00
|
|
|
<textarea
|
|
|
|
|
ref={inputRef}
|
2026-02-16 16:56:44 +01:00
|
|
|
className="w-full resize-y rounded-lg border border-input bg-[var(--bg-input)] px-3 py-2.5 text-[13px] text-foreground placeholder:text-muted-foreground outline-none transition-colors focus:border-ring"
|
2026-02-15 13:00:10 +01:00
|
|
|
placeholder="Commit message..."
|
|
|
|
|
value={message}
|
|
|
|
|
onChange={(e) => setMessage(e.target.value)}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
rows={3}
|
|
|
|
|
/>
|
2026-02-16 16:56:44 +01:00
|
|
|
<DialogFooter className="flex-row items-center justify-between sm:justify-between">
|
|
|
|
|
<span className="text-[11px] text-muted-foreground">Cmd+Enter to commit</span>
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Button variant="outline" onClick={onClose}>
|
2026-02-15 13:00:10 +01:00
|
|
|
Cancel
|
2026-02-16 16:56:44 +01:00
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleSubmit} disabled={!message.trim()}>
|
2026-02-15 13:00:10 +01:00
|
|
|
Commit & Push
|
2026-02-16 16:56:44 +01:00
|
|
|
</Button>
|
2026-02-15 13:00:10 +01:00
|
|
|
</div>
|
2026-02-16 16:56:44 +01:00
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
2026-02-15 13:00:10 +01:00
|
|
|
)
|
|
|
|
|
}
|