From 6801f3a236f7157810f1faa1d14edd17bd09f8ab Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 7 Nov 2024 01:14:11 +0300 Subject: [PATCH] Close canvas while streaming (#500) --- components/custom/canvas.tsx | 12 +++++++++--- components/custom/multimodal-input.tsx | 4 ++-- components/custom/preview-attachment.tsx | 2 +- components/custom/use-canvas-stream.tsx | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/custom/canvas.tsx b/components/custom/canvas.tsx index 90335a9..5ef8cd5 100644 --- a/components/custom/canvas.tsx +++ b/components/custom/canvas.tsx @@ -429,7 +429,9 @@ export function Canvas({ } )}`} - ) : null} + ) : ( +
+ )}
@@ -443,6 +445,7 @@ export function Canvas({ copyToClipboard(canvas.content); toast.success('Copied to clipboard!'); }} + disabled={canvas.status === 'streaming'} > @@ -457,7 +460,9 @@ export function Canvas({ onClick={() => { handleVersionChange('prev'); }} - disabled={currentVersionIndex === 0} + disabled={ + currentVersionIndex === 0 || canvas.status === 'streaming' + } > @@ -472,7 +477,7 @@ export function Canvas({ onClick={() => { handleVersionChange('next'); }} - disabled={isCurrentVersion} + disabled={isCurrentVersion || canvas.status === 'streaming'} > @@ -489,6 +494,7 @@ export function Canvas({ onClick={() => { handleVersionChange('toggle'); }} + disabled={canvas.status === 'streaming'} > diff --git a/components/custom/multimodal-input.tsx b/components/custom/multimodal-input.tsx index 5a58997..036a8c0 100644 --- a/components/custom/multimodal-input.tsx +++ b/components/custom/multimodal-input.tsx @@ -238,7 +238,7 @@ export function MultimodalInput({ /> {(attachments.length > 0 || uploadQueue.length > 0) && ( -
+
{attachments.map((attachment) => ( ))} @@ -263,7 +263,7 @@ export function MultimodalInput({ value={input} onChange={handleInput} className={cx( - 'min-h-[24px] overflow-hidden resize-none rounded-xl text-base bg-muted', + 'min-h-[24px] max-h-[calc(75dvh)] overflow-hidden resize-none rounded-xl text-base bg-muted', className )} rows={3} diff --git a/components/custom/preview-attachment.tsx b/components/custom/preview-attachment.tsx index a21d673..f4c2b35 100644 --- a/components/custom/preview-attachment.tsx +++ b/components/custom/preview-attachment.tsx @@ -12,7 +12,7 @@ export const PreviewAttachment = ({ const { name, url, contentType } = attachment; return ( -
+
{contentType ? ( contentType.startsWith('image') ? ( diff --git a/components/custom/use-canvas-stream.tsx b/components/custom/use-canvas-stream.tsx index 9b2d226..3deb552 100644 --- a/components/custom/use-canvas-stream.tsx +++ b/components/custom/use-canvas-stream.tsx @@ -56,9 +56,11 @@ export function useCanvasStream({ ...draftCanvas, content: draftCanvas.content + (delta.content as string), isVisible: - draftCanvas.status === 'streaming' + draftCanvas.status === 'streaming' && + draftCanvas.content.length > 200 && + draftCanvas.content.length < 250 ? true - : draftCanvas.content.length > 200, + : draftCanvas.isVisible, status: 'streaming', };