-
Notifications
You must be signed in to change notification settings - Fork 1
chore: refactor codebase for improved type safety and consistency #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ import type { ArtifactData } from './chat.types' | |
| interface AgentArtifactProps { | ||
| artifact: ArtifactData | ||
| onClose?: () => void | ||
| // eslint-disable-next-line no-unused-vars | ||
|
|
||
| onCodeUpdate?: (artifactId: string, newCode: string) => void | ||
| } | ||
|
|
||
|
|
@@ -59,14 +59,17 @@ export function AgentArtifact({ | |
| artifact.type === 'code' && | ||
| PREVIEWABLE_LANGUAGES.includes(normalizeLanguage(artifact.language)) | ||
|
|
||
| const handleCopy = useCallback(async () => { | ||
| try { | ||
| await navigator.clipboard.writeText(editedCode) | ||
| setCopied(true) | ||
| setTimeout(() => setCopied(false), 2000) | ||
| } catch (err) { | ||
| void err | ||
| const handleCopy = useCallback(() => { | ||
| const doCopy = async () => { | ||
| try { | ||
| await navigator.clipboard.writeText(editedCode) | ||
| setCopied(true) | ||
| setTimeout(() => setCopied(false), 2000) | ||
| } catch (err) { | ||
| void err | ||
| } | ||
| } | ||
| void doCopy() | ||
| }, [editedCode]) | ||
|
Comment on lines
+62
to
73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent error handling compared to similar copy logic elsewhere. The error is silently discarded with Proposed fix const handleCopy = useCallback(() => {
const doCopy = async () => {
try {
await navigator.clipboard.writeText(editedCode)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
} catch (err) {
- void err
+ console.error('Failed to copy:', err)
}
}
void doCopy()
}, [editedCode])🤖 Prompt for AI Agents |
||
|
|
||
| const handleDownload = useCallback(() => { | ||
|
|
@@ -233,7 +236,7 @@ export function AgentArtifactCompact({ | |
| // Floating action button for quick access to editor | ||
| interface ArtifactEditorFABProps { | ||
| artifact: ArtifactData | ||
| // eslint-disable-next-line no-unused-vars | ||
|
|
||
| onCodeChange?: (newCode: string) => void | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactored async pattern introduces unnecessary complexity by wrapping the async logic in an inner function. The original async callback pattern was cleaner and more idiomatic. The void operator on line 72 makes the fire-and-forget intention clear, but the extra wrapper function reduces readability. Consider keeping the original async callback if fire-and-forget is acceptable, or properly handling the promise if error handling is important.