CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
AiCommitGenerator-CjbukltX.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"AiCommitGenerator-CjbukltX.js","sources":["../../components/features/AiCommitGenerator.tsx"],"sourcesContent":["import React, { useState, useCallback, useEffect } from 'react';\nimport { generateCommitMessageStream } from '../../services/index.ts';\nimport { downloadFile } from '../../services/fileUtils.ts';\nimport { GitBranchIcon, ArrowDownTrayIcon } from '../icons.tsx';\nimport { LoadingSpinner } from '../shared/index.tsx';\n\nconst exampleDiff = `diff --git a/src/components/Button.tsx b/src/components/Button.tsx\nindex 1b2c3d4..5e6f7g8 100644\n--- a/src/components/Button.tsx\n+++ b/src/components/Button.tsx\n@@ -1,7 +1,7 @@\n import React from 'react';\n\n interface ButtonProps {\n-  text: string;\n+  label: string;\n   onClick: () => void;\n }\n`;\n\nexport const AiCommitGenerator: React.FC<{ diff?: string }> = ({ diff: initialDiff }) => {\n    const [diff, setDiff] = useState<string>(initialDiff || exampleDiff);\n    const [message, setMessage] = useState<string>('');\n    const [isLoading, setIsLoading] = useState<boolean>(false);\n    const [error, setError] = useState<string>('');\n\n    const handleGenerate = useCallback(async (diffToAnalyze: string) => {\n        if (!diffToAnalyze.trim()) {\n            setError('Please paste a diff to generate a message.');\n            return;\n        }\n        setIsLoading(true);\n        setError('');\n        setMessage('');\n        try {\n            const stream = generateCommitMessageStream(diffToAnalyze);\n            let fullResponse = '';\n            for await (const chunk of stream) {\n                fullResponse += chunk;\n                setMessage(fullResponse);\n            }\n        } catch (err) {\n            const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n            setError(`Failed to generate message: ${errorMessage}`);\n        } finally {\n            setIsLoading(false);\n        }\n    }, []);\n\n    useEffect(() => {\n        if (initialDiff) {\n            setDiff(initialDiff);\n            handleGenerate(initialDiff);\n        }\n    }, [initialDiff, handleGenerate]);\n    \n    const handleCopy = () => {\n        navigator.clipboard.writeText(message);\n    };\n    \n    const handleDownload = () => {\n        downloadFile(message, 'commit_message.txt', 'text/plain');\n    };\n\n    return (\n        <div className=\"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary\">\n            <header className=\"mb-6\">\n                <h1 className=\"text-3xl font-bold flex items-center\">\n                    <GitBranchIcon />\n                    <span className=\"ml-3\">AI Commit Message Generator</span>\n                </h1>\n                <p className=\"text-text-secondary mt-1\">Paste your diff and let Gemini craft the perfect commit message.</p>\n            </header>\n            <div className=\"flex-grow flex flex-col gap-4 min-h-0\">\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <label htmlFor=\"diff-input\" className=\"text-sm font-medium text-text-secondary mb-2\">Git Diff</label>\n                    <textarea\n                        id=\"diff-input\"\n                        value={diff}\n                        onChange={(e) => setDiff(e.target.value)}\n                        placeholder=\"Paste your git diff here...\"\n                        className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm text-text-primary focus:ring-2 focus:ring-primary focus:outline-none\"\n                    />\n                </div>\n                <div className=\"flex-shrink-0\">\n                    <button\n                        onClick={() => handleGenerate(diff)}\n                        disabled={isLoading}\n                        className=\"btn-primary w-full max-w-xs mx-auto flex items-center justify-center px-6 py-3\"\n                    >\n                        {isLoading ? <LoadingSpinner /> : 'Generate Commit Message'}\n                    </button>\n                </div>\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <div className=\"flex justify-between items-center mb-2\">\n                        <label className=\"text-sm font-medium text-text-secondary\">Generated Message</label>\n                        {message && !isLoading && (\n                            <div className=\"flex items-center gap-2\">\n                                <button onClick={handleCopy} className=\"px-3 py-1 bg-gray-100 text-xs rounded-md hover:bg-gray-200\">Copy</button>\n                                <button onClick={handleDownload} className=\"flex items-center gap-1 px-3 py-1 bg-gray-100 text-xs rounded-md hover:bg-gray-200\">\n                                    <ArrowDownTrayIcon className=\"w-4 h-4\" /> Download\n                                </button>\n                            </div>\n                        )}\n                    </div>\n                    <div className=\"relative flex-grow p-4 bg-surface border border-border rounded-md overflow-y-auto\">\n                        {isLoading && (\n                             <div className=\"flex items-center justify-center h-full\">\n                                <LoadingSpinner />\n                             </div>\n                        )}\n                        {error && <p className=\"text-red-500\">{error}</p>}\n                        {message && !isLoading && (\n                           <pre className=\"whitespace-pre-wrap font-sans text-text-primary\">{message}</pre>\n                        )}\n                         {!isLoading && !message && !error && (\n                            <div className=\"text-text-secondary h-full flex items-center justify-center\">\n                                The commit message will appear here.\n                            </div>\n                        )}\n                    </div>\n                </div>\n            </div>\n        </div>\n    );\n};"],"names":["exampleDiff","AiCommitGenerator","initialDiff","diff","setDiff","useState","message","setMessage","isLoading","setIsLoading","error","setError","handleGenerate","useCallback","diffToAnalyze","stream","generateCommitMessageStream","fullResponse","chunk","err","errorMessage","useEffect","handleCopy","handleDownload","downloadFile","jsxs","jsx","GitBranchIcon","e","LoadingSpinner","ArrowDownTrayIcon"],"mappings":"uyFAMA,MAAMA,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcPC,GAAiD,CAAC,CAAE,KAAMC,KAAkB,CACrF,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAAA,SAAiBH,GAAeF,CAAW,EAC7D,CAACM,EAASC,CAAU,EAAIF,EAAAA,SAAiB,EAAE,EAC3C,CAACG,EAAWC,CAAY,EAAIJ,EAAAA,SAAkB,EAAK,EACnD,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAAiB,EAAE,EAEvCO,EAAiBC,cAAY,MAAOC,GAA0B,CAChE,GAAI,CAACA,EAAc,OAAQ,CACvBH,EAAS,4CAA4C,EACrD,MACJ,CACAF,EAAa,EAAI,EACjBE,EAAS,EAAE,EACXJ,EAAW,EAAE,EACb,GAAI,CACA,MAAMQ,EAASC,EAA4BF,CAAa,EACxD,IAAIG,EAAe,GACnB,gBAAiBC,KAASH,EACtBE,GAAgBC,EAChBX,EAAWU,CAAY,CAE/B,OAASE,EAAK,CACV,MAAMC,E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