@@ -6,7 +6,10 @@ import request from './request';
66class File extends Component {
77 constructor ( props ) {
88 super ( props ) ;
9- this . state = { renaming : false } ;
9+ this . state = {
10+ renaming : false ,
11+ dragging : false
12+ } ;
1013
1114 this . open = this . open . bind ( this ) ;
1215 this . rename = this . rename . bind ( this ) ;
@@ -15,6 +18,10 @@ class File extends Component {
1518 this . stopRenaming = this . stopRenaming . bind ( this ) ;
1619 this . handleContextMenu = this . handleContextMenu . bind ( this ) ;
1720 this . handleDragStart = this . handleDragStart . bind ( this ) ;
21+ this . handleDragEnd = this . handleDragEnd . bind ( this ) ;
22+ this . handleDragOver = this . handleDragOver . bind ( this ) ;
23+ this . handleDragLeave = this . handleDragLeave . bind ( this ) ;
24+ this . handleDrop = this . handleDrop . bind ( this ) ;
1825 }
1926
2027 open ( ) {
@@ -102,12 +109,52 @@ class File extends Component {
102109 handleDragStart ( event ) {
103110 const { file } = this . props ;
104111 event . dataTransfer . setData ( file . type , JSON . stringify ( file ) ) ;
112+ this . setState ( { dragging : true } ) ;
113+ }
114+
115+ handleDragEnd ( ) {
116+ this . setState ( { dragging : false } ) ;
117+ }
118+
119+ handleDragOver ( event ) {
120+ const { dragging } = this . state ;
121+ const element = event . target ;
122+ if ( ! dragging && element . classList . contains ( 'folder' ) ) {
123+ element . classList . add ( 'grow' ) ;
124+ }
125+ event . preventDefault ( ) ;
126+ }
127+
128+ handleDragLeave ( event ) {
129+ const element = event . target ;
130+ element . classList . remove ( 'grow' ) ;
131+ }
132+
133+ handleDrop ( event ) {
134+ const { props : { file : { _id } , dropFile } , state : { dragging } } = this ;
135+ const element = event . target ;
136+
137+ if ( ! dragging && element . classList . contains ( 'folder' ) ) {
138+ dropFile ( event , _id ) ;
139+ element . classList . remove ( 'grow' ) ;
140+ }
105141 }
106142
107143 render ( ) {
108144 const { props : { file : { type, name } } , state : { renaming } } = this ;
145+
109146 return (
110- < div className = { `file ${ renaming ? 'renaming' : '' } ` } onDoubleClick = { this . open } onContextMenu = { this . handleContextMenu } onDragStart = { this . handleDragStart } draggable >
147+ < div
148+ className = { `file ${ renaming ? 'renaming' : '' } ` }
149+ onDoubleClick = { this . open }
150+ onContextMenu = { this . handleContextMenu }
151+ onDragStart = { this . handleDragStart }
152+ onDragEnd = { this . handleDragEnd }
153+ onDragOver = { this . handleDragOver }
154+ onDragLeave = { this . handleDragLeave }
155+ onDrop = { this . handleDrop }
156+ draggable
157+ >
111158 < div className = { type } />
112159 < div className = "fileName" >
113160 { ( renaming ) ? < AutoFocusInput value = { name } onStopEditing = { this . stopRenaming } /> : name }
0 commit comments