CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
CodeReviewBot-8iZLD7RW.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"CodeReviewBot-8iZLD7RW.js","sources":["../../components/features/CodeReviewBot.tsx"],"sourcesContent":["import React, { useState, useCallback } from 'react';\nimport { reviewCodeStream } from '../../services/index.ts';\nimport { CpuChipIcon } from '../icons.tsx';\nimport { LoadingSpinner } from '../shared/index.tsx';\nimport { MarkdownRenderer } from '../shared/index.tsx';\n\nconst exampleCode = `function UserList(users) {\n  if (users.length = 0) {\n    return \"no users\";\n  } else {\n    return (\n      users.map(u => {\n        return <li>{u.name}</li>\n      })\n    )\n  }\n}`;\n\nexport const CodeReviewBot: React.FC = () => {\n    const [code, setCode] = useState<string>(exampleCode);\n    const [review, setReview] = useState<string>('');\n    const [isLoading, setIsLoading] = useState<boolean>(false);\n    const [error, setError] = useState<string>('');\n\n    const handleGenerate = useCallback(async () => {\n        if (!code.trim()) {\n            setError('Please enter some code to review.');\n            return;\n        }\n        setIsLoading(true);\n        setError('');\n        setReview('');\n        try {\n            const stream = reviewCodeStream(code);\n            let fullResponse = '';\n            for await (const chunk of stream) {\n                fullResponse += chunk;\n                setReview(fullResponse);\n            }\n        } catch (err) {\n            const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n            setError(`Failed to get review: ${errorMessage}`);\n        } finally {\n            setIsLoading(false);\n        }\n    }, [code]);\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                    <CpuChipIcon />\n                    <span className=\"ml-3\">AI Code Review Bot</span>\n                </h1>\n                <p className=\"text-text-secondary mt-1\">Get an automated code review from Gemini.</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=\"code-input\" className=\"text-sm font-medium text-text-secondary mb-2\">Code to Review</label>\n                    <textarea\n                        id=\"code-input\"\n                        value={code}\n                        onChange={(e) => setCode(e.target.value)}\n                        placeholder=\"Paste your code here...\"\n                        className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm\"\n                    />\n                </div>\n                 <div className=\"flex-shrink-0\">\n                    <button\n                        onClick={handleGenerate}\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 /> : 'Request Review'}\n                    </button>\n                </div>\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <label className=\"text-sm font-medium text-text-secondary mb-2\">AI Feedback</label>\n                    <div className=\"flex-grow p-4 bg-background border border-border rounded-md overflow-y-auto\">\n                        {isLoading && !review && <div className=\"flex items-center justify-center h-full\"><LoadingSpinner /></div>}\n                        {error && <p className=\"text-red-500\">{error}</p>}\n                        {review && <MarkdownRenderer content={review} />}\n                         {!isLoading && !review && !error && <div className=\"text-text-secondary h-full flex items-center justify-center\">Review will appear here.</div>}\n                    </div>\n                </div>\n            </div>\n        </div>\n    );\n};"],"names":["exampleCode","CodeReviewBot","code","setCode","useState","review","setReview","isLoading","setIsLoading","error","setError","handleGenerate","useCallback","stream","reviewCodeStream","fullResponse","chunk","err","errorMessage","jsxs","jsx","CpuChipIcon","e","LoadingSpinner","MarkdownRenderer"],"mappings":"yTAMA,MAAMA,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAYPC,EAA0B,IAAM,CACzC,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAAA,SAAiBJ,CAAW,EAC9C,CAACK,EAAQC,CAAS,EAAIF,EAAAA,SAAiB,EAAE,EACzC,CAACG,EAAWC,CAAY,EAAIJ,EAAAA,SAAkB,EAAK,EACnD,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAAiB,EAAE,EAEvCO,EAAiBC,EA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