@@ -221,12 +221,11 @@ const EpicPage = () => {
221
221
} ;
222
222
223
223
const handleEpicDragEnd = ( event : DragEvent ) => {
224
- event . preventDefault ( ) ;
225
-
226
224
if ( draggingTaskId || draggingStoryId ) {
227
225
return ;
228
226
}
229
227
228
+ event . preventDefault ( ) ;
230
229
const targetIndex = epicList . findIndex ( ( { id } ) => id === draggingEpicId ) ;
231
230
let rankValue ;
232
231
@@ -262,12 +261,11 @@ const EpicPage = () => {
262
261
} ;
263
262
264
263
const handleStoryDragOver = ( event : DragEvent , epicIndex : number ) => {
265
- event . preventDefault ( ) ;
266
-
267
264
if ( draggingTaskId || draggingEpicId ) {
268
265
return ;
269
266
}
270
267
268
+ event . preventDefault ( ) ;
271
269
const mouseIndex = epicList [ epicIndex ] . storyList . findIndex (
272
270
( { id } ) => id === draggingStoryId
273
271
) ;
@@ -299,26 +297,26 @@ const EpicPage = () => {
299
297
}
300
298
301
299
const { epicId, storyIndex } = storyElementIndex ;
302
- const storyList = epicList . find ( ( { id } ) => id === epicId )
303
- ?. storyList as StoryDTO [ ] ;
300
+ const targetEpic = epicList . find ( ( { id } ) => id === epicId ) ;
301
+ const storyList = targetEpic ?. storyList as StoryDTO [ ] ;
304
302
const currentIndex = storyList ?. findIndex (
305
303
( { id } ) => id === draggingStoryId
306
304
) ;
307
305
308
306
let rankValue ;
309
307
310
- if ( storyIndex === currentIndex ) {
308
+ if ( storyIndex !== - 1 && storyIndex === currentIndex ) {
311
309
setDraggingStoryId ( undefined ) ;
312
310
setStoryElementIndex ( { epicId : undefined , storyIndex : undefined } ) ;
313
311
return ;
314
312
}
315
313
316
- if ( storyIndex === 0 && ! storyList . length ) {
314
+ if ( ( storyIndex === - 1 || storyIndex === 0 ) && ! storyList . length ) {
317
315
rankValue = LexoRank . middle ( ) . toString ( ) ;
318
316
} else if ( storyIndex === 0 ) {
319
317
const firstStoryRank = storyList [ 0 ] . rankValue ;
320
318
rankValue = LexoRank . parse ( firstStoryRank ) . genPrev ( ) . toString ( ) ;
321
- } else if ( storyIndex === storyList . length ) {
319
+ } else if ( storyIndex === - 1 || storyIndex === storyList . length ) {
322
320
const lastStoryRank = storyList [ storyList . length - 1 ] . rankValue ;
323
321
rankValue = LexoRank . parse ( lastStoryRank ) . genNext ( ) . toString ( ) ;
324
322
} else {
@@ -341,61 +339,16 @@ const EpicPage = () => {
341
339
setStoryElementIndex ( { epicId : undefined , storyIndex : undefined } ) ;
342
340
} ;
343
341
344
- useEffect ( ( ) => {
345
- const handleDragEvent = ( {
346
- domain,
347
- action,
348
- content,
349
- } : BacklogSocketData ) => {
350
- if (
351
- domain === "epic" &&
352
- action === "delete" &&
353
- content . id === draggingEpicId
354
- ) {
355
- setEpicElementIndex ( undefined ) ;
356
- return ;
357
- }
358
-
359
- if (
360
- domain === "story" &&
361
- action === "delete" &&
362
- content . id === draggingStoryId
363
- ) {
364
- setStoryElementIndex ( { epicId : undefined , storyIndex : undefined } ) ;
365
-
366
- return ;
367
- }
368
-
369
- if (
370
- domain === "task" &&
371
- action === "delete" &&
372
- content . id === draggingTaskId
373
- ) {
374
- setTaskElementIndex ( {
375
- epicId : undefined ,
376
- storyId : undefined ,
377
- taskIndex : undefined ,
378
- } ) ;
379
- }
380
- } ;
381
-
382
- socket . on ( "backlog" , handleDragEvent ) ;
383
-
384
- return ( ) => {
385
- socket . off ( "backlog" , handleDragEvent ) ;
386
- } ;
387
- } , [ ] ) ;
388
-
389
342
const handleTaskDragOver = (
390
343
event : DragEvent ,
391
344
epicIndex : number ,
392
345
storyIndex : number
393
346
) => {
394
- event . preventDefault ( ) ;
395
-
396
347
if ( draggingStoryId || draggingEpicId ) {
397
348
return ;
398
349
}
350
+
351
+ event . preventDefault ( ) ;
399
352
const { storyList } = epicList [ epicIndex ] ;
400
353
401
354
const mouseIndex = storyList [ storyIndex ] . taskList . findIndex (
@@ -425,15 +378,14 @@ const EpicPage = () => {
425
378
426
379
const handleTaskDragEnd = ( ) => {
427
380
const { epicId, storyId, taskIndex } = taskElementIndex ;
428
- const storyList = epicList . find ( ( { id } ) => epicId === id )
429
- ?. storyList as StoryDTO [ ] ;
430
- const taskList = storyList . find ( ( { id } ) => id === storyId )
431
- ?. taskList as TaskDTO [ ] ;
381
+ const targetEpic = epicList . find ( ( { id } ) => epicId === id ) ;
382
+ const targetStory = targetEpic ?. storyList . find ( ( { id } ) => id === storyId ) ;
383
+ const taskList = targetStory ?. taskList as TaskDTO [ ] ;
432
384
const currentIndex = taskList ?. findIndex ( ( { id } ) => id === draggingTaskId ) ;
433
385
434
386
let rankValue ;
435
387
436
- if ( taskIndex === currentIndex ) {
388
+ if ( ! taskIndex || ( taskIndex !== - 1 && taskIndex === currentIndex ) ) {
437
389
setDraggingTaskId ( undefined ) ;
438
390
setTaskElementIndex ( {
439
391
epicId : undefined ,
@@ -443,12 +395,12 @@ const EpicPage = () => {
443
395
return ;
444
396
}
445
397
446
- if ( taskIndex === 0 && ! taskList . length ) {
398
+ if ( ( taskIndex === - 1 || taskIndex === 0 ) && ! taskList . length ) {
447
399
rankValue = LexoRank . middle ( ) . toString ( ) ;
448
400
} else if ( taskIndex === 0 ) {
449
401
const firstTaskRank = taskList [ 0 ] . rankValue ;
450
402
rankValue = LexoRank . parse ( firstTaskRank ) . genPrev ( ) . toString ( ) ;
451
- } else if ( taskIndex === taskList . length ) {
403
+ } else if ( taskIndex === - 1 || taskIndex === taskList . length ) {
452
404
const lastTaskRank = taskList [ taskList . length - 1 ] . rankValue ;
453
405
rankValue = LexoRank . parse ( lastTaskRank ) . genNext ( ) . toString ( ) ;
454
406
} else {
@@ -475,6 +427,59 @@ const EpicPage = () => {
475
427
} ) ;
476
428
} ;
477
429
430
+ const handleDropTaskOnEpic = ( ) => {
431
+ setTaskElementIndex ( {
432
+ epicId : undefined ,
433
+ storyId : undefined ,
434
+ taskIndex : undefined ,
435
+ } ) ;
436
+ } ;
437
+
438
+ useEffect ( ( ) => {
439
+ const handleDragEvent = ( {
440
+ domain,
441
+ action,
442
+ content,
443
+ } : BacklogSocketData ) => {
444
+ if (
445
+ domain === "epic" &&
446
+ action === "delete" &&
447
+ content . id === draggingEpicId
448
+ ) {
449
+ setEpicElementIndex ( undefined ) ;
450
+ return ;
451
+ }
452
+
453
+ if (
454
+ domain === "story" &&
455
+ action === "delete" &&
456
+ content . id === draggingStoryId
457
+ ) {
458
+ setStoryElementIndex ( { epicId : undefined , storyIndex : undefined } ) ;
459
+
460
+ return ;
461
+ }
462
+
463
+ if (
464
+ domain === "task" &&
465
+ action === "delete" &&
466
+ content . id === draggingTaskId
467
+ ) {
468
+ setTaskElementIndex ( {
469
+ epicId : undefined ,
470
+ storyId : undefined ,
471
+ taskIndex : undefined ,
472
+ } ) ;
473
+ }
474
+ } ;
475
+
476
+ socket . on ( "backlog" , handleDragEvent ) ;
477
+
478
+ return ( ) => {
479
+ socket . off ( "backlog" , handleDragEvent ) ;
480
+ } ;
481
+ } , [ ] ) ;
482
+
478
483
return (
479
484
< div className = "gap-4 pb-10 border-t" onDragOver = { handleEpicDragOver } >
480
485
{ ! epicList . length && (
@@ -494,7 +499,11 @@ const EpicPage = () => {
494
499
taskComponentRefList . current [ epicIndex ] = [ ] ;
495
500
496
501
return (
497
- < div className = "py-2 border-t border-b" >
502
+ < div
503
+ className = "py-2 border-t border-b"
504
+ onDragOver = { ( event ) => handleStoryDragOver ( event , epicIndex ) }
505
+ onDrop = { handleDropTaskOnEpic }
506
+ >
498
507
< EpicDragContainer
499
508
{ ...{ epicIndex } }
500
509
onDragStart = { ( ) => handleEpicDragStart ( epicId ) }
@@ -511,10 +520,7 @@ const EpicPage = () => {
511
520
/>
512
521
</ EpicDragContainer >
513
522
{ showStory [ epicId ] ?. showStoryList && (
514
- < div
515
- className = "w-[65rem] ml-auto"
516
- onDragOver = { ( event ) => handleStoryDragOver ( event , epicIndex ) }
517
- >
523
+ < div className = "w-[65rem] ml-auto" >
518
524
{ ...storyList . map (
519
525
(
520
526
{ id : storyId , title, point, status, taskList } ,
@@ -536,6 +542,9 @@ const EpicPage = () => {
536
542
onDragOver = { ( event ) =>
537
543
handleTaskDragOver ( event , epicIndex , storyIndex )
538
544
}
545
+ onDrop = { ( event ) => {
546
+ event . stopPropagation ( ) ;
547
+ } }
539
548
>
540
549
< EpicPageStoryDragContainer
541
550
{ ...{ epicIndex, storyIndex } }
0 commit comments