upload new files

This commit is contained in:
Andrew Trokhymenko
2024-11-27 14:30:09 -05:00
parent 074161024d
commit 809b54e04a
3 changed files with 139 additions and 5 deletions

View File

@@ -57,6 +57,7 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
renderLogger.trace('Workbench');
const [isSyncing, setIsSyncing] = useState(false);
const [isUploading, setIsUploading] = useState(false);
const hasPreview = useStore(computed(workbenchStore.previews, (previews) => previews.length > 0));
const showWorkbench = useStore(workbenchStore.showWorkbench);
@@ -119,6 +120,60 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
}
}, []);
const handleUploadFiles = useCallback(async () => {
setIsUploading(true);
try {
// const directoryHandle = await window.showDirectoryPicker();
// // First upload new files
// await workbenchStore.uploadFilesFromDisk(directoryHandle);
// // Get current files state
// const currentFiles = workbenchStore.files.get();
// // Create new modifications map with all files as "new"
// const newModifications = new Map();
// Object.entries(currentFiles).forEach(([path, file]) => {
// if (file.type === 'file') {
// newModifications.set(path, file.content);
// }
// });
// // Update workbench state
// await workbenchStore.refreshFiles();
// workbenchStore.resetAllFileModifications();
// toast.success('Files uploaded successfully');
// } catch (error) {
// toast.error('Failed to upload files');
// }
await handleUploadFilesFunc();
}
finally {
setIsUploading(false);
}
}, []);
async function handleUploadFilesFunc() {
try {
// First clean all statuses
await workbenchStore.saveAllFiles();
await workbenchStore.resetAllFileModifications();
await workbenchStore.refreshFiles();
// Now upload new files
const directoryHandle = await window.showDirectoryPicker();
await workbenchStore.uploadFilesFromDisk(directoryHandle);
toast.success('Files uploaded successfully');
} catch (error) {
console.error('Upload files error:', error);
toast.error('Failed to upload files');
}
}
return (
chatStarted && (
<motion.div
@@ -158,6 +213,10 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
{isSyncing ? <div className="i-ph:spinner" /> : <div className="i-ph:cloud-arrow-down" />}
{isSyncing ? 'Syncing...' : 'Sync Files'}
</PanelHeaderButton>
<PanelHeaderButton className="mr-1 text-sm" onClick={handleUploadFiles} disabled={isSyncing}>
{isSyncing ? <div className="i-ph:spinner" /> : <div className="i-ph:cloud-arrow-up" />}
{isSyncing ? 'Uploading...' : 'Upload Files'}
</PanelHeaderButton>
<PanelHeaderButton
className="mr-1 text-sm"
onClick={() => {