mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
fix: enhance file handling and UI improvements in chat and file preview components
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
"WebFetch(domain:ai-sdk.dev)",
|
"WebFetch(domain:ai-sdk.dev)",
|
||||||
"mcp__ide__getDiagnostics",
|
"mcp__ide__getDiagnostics",
|
||||||
"Bash(npx tsc:*)",
|
"Bash(npx tsc:*)",
|
||||||
"WebFetch(domain:sdk.vercel.ai)"
|
"WebFetch(domain:sdk.vercel.ai)",
|
||||||
|
"Bash(npm run build:*)"
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ export default function ExamplePanel({
|
|||||||
// Fetch the architecture image
|
// Fetch the architecture image
|
||||||
const response = await fetch("/architecture.png");
|
const response = await fetch("/architecture.png");
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
const file = new File([blob], "architecture.png", { type: "image/png" });
|
const file = new File([blob], "architecture.png", {
|
||||||
|
type: "image/png",
|
||||||
|
});
|
||||||
|
|
||||||
// Set the file to the files state
|
// Set the file to the files state
|
||||||
setFiles([file]);
|
setFiles([file]);
|
||||||
@@ -54,7 +56,7 @@ export default function ExamplePanel({
|
|||||||
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
||||||
onClick={handleReplicateArchitecture}
|
onClick={handleReplicateArchitecture}
|
||||||
>
|
>
|
||||||
Replicate this in aws style
|
Create this diagram in aws style
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
||||||
|
|||||||
@@ -28,12 +28,17 @@ export default function ChatPanel() {
|
|||||||
} = useDiagram();
|
} = useDiagram();
|
||||||
|
|
||||||
const onFetchChart = () => {
|
const onFetchChart = () => {
|
||||||
return new Promise<string>((resolve) => {
|
return Promise.race([
|
||||||
if (resolverRef && "current" in resolverRef) {
|
new Promise<string>((resolve) => {
|
||||||
resolverRef.current = resolve; // Store the resolver
|
if (resolverRef && "current" in resolverRef) {
|
||||||
}
|
resolverRef.current = resolve;
|
||||||
onExport(); // Trigger the export
|
}
|
||||||
});
|
onExport();
|
||||||
|
}),
|
||||||
|
new Promise<string>((_, reject) =>
|
||||||
|
setTimeout(() => reject(new Error("Chart export timed out after 10 seconds")), 10000)
|
||||||
|
)
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
// Add a step counter to track updates
|
// Add a step counter to track updates
|
||||||
|
|
||||||
@@ -112,8 +117,6 @@ export default function ChatPanel() {
|
|||||||
}
|
}
|
||||||
}, [messages]);
|
}, [messages]);
|
||||||
|
|
||||||
console.log(JSON.stringify(messages, null, 2));
|
|
||||||
|
|
||||||
const onFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
const onFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (input.trim() && status !== "streaming") {
|
if (input.trim() && status !== "streaming") {
|
||||||
|
|||||||
@@ -70,18 +70,19 @@ export function FilePreviewList({ files, onRemoveFile }: FilePreviewListProps) {
|
|||||||
onClick={() => setSelectedImage(null)}
|
onClick={() => setSelectedImage(null)}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="absolute top-4 right-4 bg-white rounded-full p-2 hover:bg-gray-200 transition-colors"
|
className="absolute top-4 right-4 z-10 bg-white rounded-full p-2 hover:bg-gray-200 transition-colors"
|
||||||
onClick={() => setSelectedImage(null)}
|
onClick={() => setSelectedImage(null)}
|
||||||
aria-label="Close"
|
aria-label="Close"
|
||||||
>
|
>
|
||||||
<X className="h-6 w-6" />
|
<X className="h-6 w-6" />
|
||||||
</button>
|
</button>
|
||||||
<div className="relative max-w-7xl max-h-[90vh] w-full h-full">
|
<div className="relative w-auto h-auto max-w-[90vw] max-h-[90vh]">
|
||||||
<Image
|
<Image
|
||||||
src={selectedImage}
|
src={selectedImage}
|
||||||
alt="Preview"
|
alt="Preview"
|
||||||
fill
|
width={1200}
|
||||||
className="object-contain"
|
height={900}
|
||||||
|
className="object-contain max-w-full max-h-[90vh] w-auto h-auto"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user