@@ -3,6 +3,7 @@ import type { Message } from 'ai';
33import { toast } from 'react-toastify' ;
44import { MAX_FILES , isBinaryFile , shouldIncludeFile } from '~/utils/fileUtils' ;
55import { createChatFromFolder } from '~/utils/folderImport' ;
6+ import { logStore } from '~/lib/stores/logs' ; // Assuming logStore is imported from this location
67
78interface ImportFolderButtonProps {
89 className ?: string ;
@@ -16,9 +17,15 @@ export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ classNam
1617 const allFiles = Array . from ( e . target . files || [ ] ) ;
1718
1819 if ( allFiles . length > MAX_FILES ) {
20+ const error = new Error ( `Too many files: ${ allFiles . length } ` ) ;
21+ logStore . logError ( 'File import failed - too many files' , error , {
22+ fileCount : allFiles . length ,
23+ maxFiles : MAX_FILES ,
24+ } ) ;
1925 toast . error (
2026 `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.` ,
2127 ) ;
28+
2229 return ;
2330 }
2431
@@ -31,7 +38,10 @@ export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ classNam
3138 const filteredFiles = allFiles . filter ( ( file ) => shouldIncludeFile ( file . webkitRelativePath ) ) ;
3239
3340 if ( filteredFiles . length === 0 ) {
41+ const error = new Error ( 'No valid files found' ) ;
42+ logStore . logError ( 'File import failed - no valid files' , error , { folderName } ) ;
3443 toast . error ( 'No files found in the selected folder' ) ;
44+
3545 return ;
3646 }
3747
@@ -48,11 +58,18 @@ export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ classNam
4858 . map ( ( f ) => f . file . webkitRelativePath . split ( '/' ) . slice ( 1 ) . join ( '/' ) ) ;
4959
5060 if ( textFiles . length === 0 ) {
61+ const error = new Error ( 'No text files found' ) ;
62+ logStore . logError ( 'File import failed - no text files' , error , { folderName } ) ;
5163 toast . error ( 'No text files found in the selected folder' ) ;
64+
5265 return ;
5366 }
5467
5568 if ( binaryFilePaths . length > 0 ) {
69+ logStore . logWarning ( `Skipping binary files during import` , {
70+ folderName,
71+ binaryCount : binaryFilePaths . length ,
72+ } ) ;
5673 toast . info ( `Skipping ${ binaryFilePaths . length } binary files` ) ;
5774 }
5875
@@ -62,8 +79,14 @@ export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ classNam
6279 await importChat ( folderName , [ ...messages ] ) ;
6380 }
6481
82+ logStore . logSystem ( 'Folder imported successfully' , {
83+ folderName,
84+ textFileCount : textFiles . length ,
85+ binaryFileCount : binaryFilePaths . length ,
86+ } ) ;
6587 toast . success ( 'Folder imported successfully' ) ;
6688 } catch ( error ) {
89+ logStore . logError ( 'Failed to import folder' , error , { folderName } ) ;
6790 console . error ( 'Failed to import folder:' , error ) ;
6891 toast . error ( 'Failed to import folder' ) ;
6992 } finally {
0 commit comments