mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-04-28 09:52:19 +00:00
Merge pull request #939 from juanmcampos/fix-project-import-button
fix: import folder filtering
This commit is contained in:
commit
93c2a6e81d
@ -16,35 +16,40 @@ export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ classNam
|
|||||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const allFiles = Array.from(e.target.files || []);
|
const allFiles = Array.from(e.target.files || []);
|
||||||
|
|
||||||
if (allFiles.length > MAX_FILES) {
|
const filteredFiles = allFiles.filter((file) => {
|
||||||
const error = new Error(`Too many files: ${allFiles.length}`);
|
const path = file.webkitRelativePath.split('/').slice(1).join('/');
|
||||||
|
const include = shouldIncludeFile(path);
|
||||||
|
|
||||||
|
return include;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filteredFiles.length === 0) {
|
||||||
|
const error = new Error('No valid files found');
|
||||||
|
logStore.logError('File import failed - no valid files', error, { folderName: 'Unknown Folder' });
|
||||||
|
toast.error('No files found in the selected folder');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filteredFiles.length > MAX_FILES) {
|
||||||
|
const error = new Error(`Too many files: ${filteredFiles.length}`);
|
||||||
logStore.logError('File import failed - too many files', error, {
|
logStore.logError('File import failed - too many files', error, {
|
||||||
fileCount: allFiles.length,
|
fileCount: filteredFiles.length,
|
||||||
maxFiles: MAX_FILES,
|
maxFiles: MAX_FILES,
|
||||||
});
|
});
|
||||||
toast.error(
|
toast.error(
|
||||||
`This folder contains ${allFiles.length.toLocaleString()} files. This product is not yet optimized for very large projects. Please select a folder with fewer than ${MAX_FILES.toLocaleString()} files.`,
|
`This folder contains ${filteredFiles.length.toLocaleString()} files. This product is not yet optimized for very large projects. Please select a folder with fewer than ${MAX_FILES.toLocaleString()} files.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const folderName = allFiles[0]?.webkitRelativePath.split('/')[0] || 'Unknown Folder';
|
const folderName = filteredFiles[0]?.webkitRelativePath.split('/')[0] || 'Unknown Folder';
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const loadingToast = toast.loading(`Importing ${folderName}...`);
|
const loadingToast = toast.loading(`Importing ${folderName}...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const filteredFiles = allFiles.filter((file) => shouldIncludeFile(file.webkitRelativePath));
|
|
||||||
|
|
||||||
if (filteredFiles.length === 0) {
|
|
||||||
const error = new Error('No valid files found');
|
|
||||||
logStore.logError('File import failed - no valid files', error, { folderName });
|
|
||||||
toast.error('No files found in the selected folder');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileChecks = await Promise.all(
|
const fileChecks = await Promise.all(
|
||||||
filteredFiles.map(async (file) => ({
|
filteredFiles.map(async (file) => ({
|
||||||
file,
|
file,
|
||||||
|
Loading…
Reference in New Issue
Block a user