From 085f97b10cec298a4cfc12c176d9f7b1b565d3ed Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Thu, 9 Jan 2025 21:49:13 -0800 Subject: [PATCH] LFS: support missing callbacks --- .../livefile-sync/useLiveFileSync.tsx | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx b/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx index dfa6462d2..1a4e5240e 100644 --- a/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx +++ b/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx @@ -48,8 +48,8 @@ export function useLiveFileSync( workspaceId: DWorkspaceId | null, isMobile: boolean, bufferText: string, - onReplaceLiveFileId: (liveFileId: LiveFileId) => void, - onSetBufferText: (text: string) => void, + onReplaceLiveFileId?: (liveFileId: LiveFileId) => void, + onSetBufferText?: (text: string) => void, ) { // state @@ -140,7 +140,7 @@ export function useLiveFileSync( console.warn('[DEV] No workspaceId to pair the file with.'); else workspaceActions().liveFileAssign(workspaceId, liveFileId); - onReplaceLiveFileId(liveFileId); + onReplaceLiveFileId?.(liveFileId); // Immediately load the preview on this ID await _handleReloadFileContent(liveFileId); } catch (error: any) { @@ -166,7 +166,7 @@ export function useLiveFileSync( if (fileContent === undefined) setStatus({ message: 'No file content loaded. Please preview changes first.', mtype: 'info' }); else - onSetBufferText(fileContent); + onSetBufferText?.(fileContent); }, [fileContent, onSetBufferText]); const handleSaveToDisk = React.useCallback(async (event: React.MouseEvent) => { @@ -196,7 +196,7 @@ export function useLiveFileSync( // Memoed components code - const liveFileControlButton = React.useMemo(() => !isLiveFileSupported() ? null : ( + const liveFileControlButton = React.useMemo(() => (!isLiveFileSupported() || !onReplaceLiveFileId) ? null : ( - ), [fileHasContent, handlePairNewFSFHandle, handlePairNewFileWithPicker, _handleReloadFileContent, isPairingValid, isSavingFile]); + ), [_handleReloadFileContent, fileHasContent, handlePairNewFSFHandle, handlePairNewFileWithPicker, isPairingValid, isSavingFile, onReplaceLiveFileId]); const liveFileActions = React.useMemo(() => { if (!isLiveFileSupported() || (!status && !fileHasContent)) @@ -244,7 +244,7 @@ export function useLiveFileSync( {/* Load from file */} - {fileIsDifferent && !isError && ( + {fileIsDifferent && !isError && !!onSetBufferText && (