1- import { toast } from ' react-toastify' ;
2- import React , { DragEvent } from ' react'
3- import { useNavigate } from ' react-router-dom' ;
1+ import { toast } from " react-toastify" ;
2+ import React , { DragEvent } from " react" ;
3+ import { useNavigate } from " react-router-dom" ;
44
5- import { useWorkbenchDB } from ' ../../contexts/workbenchContext' ;
6- import { ROUTES } from ' ../../constants/routes' ;
5+ import { useWorkbenchDB } from " ../../contexts/workbenchContext" ;
6+ import { ROUTES } from " ../../constants/routes" ;
77
8-
9- const lastLogs :{ [ key : string ] : number } = { }
8+ const lastLogs : { [ key : string ] : number } = { } ;
109export const CustomLogger = ( id : string , ...args : unknown [ ] ) => {
11- const currentTime = ( new Date ( ) ) . getTime ( ) ;
12- if ( ! ( lastLogs [ id ] && currentTime < lastLogs [ id ] + 1000 ) ) {
10+ const currentTime = new Date ( ) . getTime ( ) ;
11+ if ( ! ( lastLogs [ id ] && currentTime < lastLogs [ id ] + 1000 ) ) {
1312 console . log ( id , ...args ) ;
1413 lastLogs [ id ] = currentTime ;
1514 }
16- }
15+ } ;
1716
1817const DropZone = ( props : React . PropsWithChildren ) => {
1918 const navigate = useNavigate ( ) ;
2019 const { sqliteParser, importJsonFile } = useWorkbenchDB ( ) ;
2120
22- function DragOverHandler ( e : DragEvent ) {
21+ function DragOverHandler ( e : DragEvent ) {
2322 e . preventDefault ( ) ;
2423 e . stopPropagation ( ) ;
2524 // CustomLogger("Drag detected", e, e.dataTransfer.files);
2625 }
27- function DropHandler ( e : DragEvent ) {
26+ function DropHandler ( e : DragEvent ) {
2827 e . preventDefault ( ) ;
2928 e . stopPropagation ( ) ;
3029
3130 const regex = {
3231 json : / \. ( j s o n ) + $ / i,
3332 sqlite : / \. ( s q l i t e ) + $ / i,
34- }
33+ } ;
3534
36- const validFiles =
37- Array . from ( e . dataTransfer . files )
38- . filter ( file => file . name . match ( regex . json ) || file . name . match ( regex . sqlite ) )
39- . filter ( file => file !== null ) ;
35+ const validFiles = Array . from ( e . dataTransfer . files )
36+ . filter (
37+ ( file ) => file . name . match ( regex . json ) || file . name . match ( regex . sqlite )
38+ )
39+ . filter ( ( file ) => file !== null ) ;
4040 const fileToImport = validFiles [ 0 ] ;
41-
41+
4242 console . log ( "Dropped files:" , e , e . dataTransfer . files ) ;
4343 console . log ( "Valid files:" , validFiles ) ;
4444
45- if ( ! validFiles . length ) {
46- return toast ( 'Only json/sqlite file can be imported !' , {
47- type : 'error' ,
45+ if ( ! validFiles . length ) {
46+ return toast . error ( "Only json/sqlite file can be imported !" , {
4847 style : { width : 320 } ,
4948 } ) ;
5049 }
5150
52- if ( validFiles . length > 1 ) {
53- toast ( `Only 1 json/sqlite file will be imported at a time` , {
54- type : 'warning' ,
51+ if ( validFiles . length > 1 ) {
52+ toast . warn ( `Only 1 json/sqlite file can be imported at a time` , {
5553 style : { width : 375 } ,
5654 } ) ;
5755 }
5856
59- if ( regex . sqlite . test ( fileToImport . name ) ) {
57+ if ( regex . sqlite . test ( fileToImport . name ) ) {
6058 console . log ( "Parsing sqlite file:" , fileToImport . name ) ;
6159 sqliteParser ( fileToImport . path ) ;
6260 navigate ( ROUTES . HOME ) ;
@@ -69,9 +67,9 @@ const DropZone = (props: React.PropsWithChildren) => {
6967
7068 return (
7169 < div onDragOver = { DragOverHandler } onDrop = { DropHandler } >
72- { props . children }
70+ { props . children }
7371 </ div >
74- )
75- }
72+ ) ;
73+ } ;
7674
77- export default DropZone
75+ export default DropZone ;
0 commit comments