@@ -4,32 +4,35 @@ import { LexoRank } from "lexorank";
4
4
import { BacklogDTO } from "../../types/DTO/backlogDTO" ;
5
5
import StoryCreateButton from "../../components/backlog/StoryCreateButton" ;
6
6
import StoryCreateForm from "../../components/backlog/StoryCreateForm" ;
7
- import { DragEvent , useMemo , useRef , useState } from "react" ;
7
+ import { DragEvent , useEffect , useMemo , useRef , useState } from "react" ;
8
8
import changeEpicListToStoryList from "../../utils/changeEpicListToStoryList" ;
9
9
import StoryBlock from "../../components/backlog/StoryBlock" ;
10
10
import TaskBlock from "../../components/backlog/TaskBlock" ;
11
11
import useShowDetail from "../../hooks/pages/backlog/useShowDetail" ;
12
12
import useStoryEmitEvent from "../../hooks/pages/backlog/useStoryEmitEvent" ;
13
13
import getDragElementIndex from "../../utils/getDragElementIndex" ;
14
+ import { BacklogSocketData } from "../../types/common/backlog" ;
14
15
15
16
const UnfinishedStoryPage = ( ) => {
16
17
const { socket, backlog } : { socket : Socket ; backlog : BacklogDTO } =
17
18
useOutletContext ( ) ;
18
19
const { showDetail, handleShowDetail } = useShowDetail ( ) ;
19
20
const [ storyElementIndex , setStoryElementIndex ] = useState < number > ( ) ;
20
21
const storyComponentRefList = useRef < HTMLDivElement [ ] > ( [ ] ) ;
21
- const draggingComponentIndexRef = useRef < number > ( ) ;
22
+ const draggingComponentIdRef = useRef < number > ( ) ;
22
23
const storyList = useMemo (
23
24
( ) =>
24
- changeEpicListToStoryList ( backlog . epicList ) . sort ( ( storyA , storyB ) => {
25
- if ( storyA . rankValue < storyB . rankValue ) {
26
- return - 1 ;
27
- }
28
- if ( storyA . rankValue > storyB . rankValue ) {
29
- return 1 ;
30
- }
31
- return 0 ;
32
- } ) ,
25
+ changeEpicListToStoryList ( backlog . epicList )
26
+ . sort ( ( storyA , storyB ) => {
27
+ if ( storyA . rankValue < storyB . rankValue ) {
28
+ return - 1 ;
29
+ }
30
+ if ( storyA . rankValue > storyB . rankValue ) {
31
+ return 1 ;
32
+ }
33
+ return 0 ;
34
+ } )
35
+ . filter ( ( { status } ) => status !== "완료" ) ,
33
36
[ backlog . epicList ]
34
37
) ;
35
38
const epicCategoryList = useMemo (
@@ -52,23 +55,26 @@ const UnfinishedStoryPage = () => {
52
55
event . preventDefault ( ) ;
53
56
const index = getDragElementIndex (
54
57
storyComponentRefList . current ,
55
- draggingComponentIndexRef . current ,
58
+ draggingComponentIdRef . current ,
56
59
event . clientY
57
60
) ;
58
61
59
62
setStoryElementIndex ( index ) ;
60
63
} ;
61
64
62
- const handleDragStart = ( index : number ) => {
63
- draggingComponentIndexRef . current = index ;
65
+ const handleDragStart = ( id : number ) => {
66
+ draggingComponentIdRef . current = id ;
64
67
} ;
65
68
66
69
const handleDragEnd = ( event : DragEvent ) => {
67
70
event . stopPropagation ( ) ;
71
+ const targetIndex = storyList . findIndex (
72
+ ( { id } ) => id === draggingComponentIdRef . current
73
+ ) ;
68
74
let rankValue ;
69
75
70
- if ( storyElementIndex === draggingComponentIndexRef . current ) {
71
- draggingComponentIndexRef . current = undefined ;
76
+ if ( storyElementIndex === targetIndex ) {
77
+ draggingComponentIdRef . current = undefined ;
72
78
setStoryElementIndex ( undefined ) ;
73
79
return ;
74
80
}
@@ -90,14 +96,36 @@ const UnfinishedStoryPage = () => {
90
96
}
91
97
92
98
emitStoryUpdateEvent ( {
93
- id : storyList [ draggingComponentIndexRef . current as number ] . id ,
99
+ id : draggingComponentIdRef . current as number ,
94
100
rankValue,
95
101
} ) ;
96
102
97
- draggingComponentIndexRef . current = undefined ;
103
+ draggingComponentIdRef . current = undefined ;
98
104
setStoryElementIndex ( undefined ) ;
99
105
} ;
100
106
107
+ useEffect ( ( ) => {
108
+ const handleDragEvent = ( {
109
+ domain,
110
+ action,
111
+ content,
112
+ } : BacklogSocketData ) => {
113
+ if (
114
+ domain === "story" &&
115
+ action === "delete" &&
116
+ content . id === draggingComponentIdRef . current
117
+ ) {
118
+ setStoryElementIndex ( undefined ) ;
119
+ }
120
+ } ;
121
+
122
+ socket . on ( "backlog" , handleDragEvent ) ;
123
+
124
+ return ( ) => {
125
+ socket . off ( "backlog" , handleDragEvent ) ;
126
+ } ;
127
+ } , [ ] ) ;
128
+
101
129
return (
102
130
< div className = "flex flex-col items-center gap-4" >
103
131
< div className = "w-full border-b" onDragOver = { handleDragOver } >
@@ -116,7 +144,7 @@ const UnfinishedStoryPage = () => {
116
144
className = "relative"
117
145
ref = { setStoryComponentRef ( index ) }
118
146
draggable = { true }
119
- onDragStart = { ( ) => handleDragStart ( index ) }
147
+ onDragStart = { ( ) => handleDragStart ( id ) }
120
148
onDragEnd = { handleDragEnd }
121
149
>
122
150
< div
@@ -146,7 +174,7 @@ const UnfinishedStoryPage = () => {
146
174
ref = { setStoryComponentRef ( storyList . length ) }
147
175
className = { `${
148
176
storyElementIndex === storyList . length
149
- ? "w-full h-1 bg-blue-400"
177
+ ? "w-[67.9rem] h-1 bg-blue-400"
150
178
: ""
151
179
} absolute`}
152
180
/>
0 commit comments