|
1 | 1 | import React, {useContext} from 'react'; |
2 | | -import {connect} from 'react-redux'; |
| 2 | +import {useSelector, useDispatch} from 'react-redux'; |
3 | 3 | import PropTypes from 'prop-types'; |
4 | 4 | import {useDrag, useDrop} from 'react-dnd'; |
5 | 5 |
|
@@ -29,17 +29,17 @@ const Story = ({ |
29 | 29 | story, |
30 | 30 | isHighlighted, |
31 | 31 | onStoryClicked, |
32 | | - selectedStoryId, |
33 | | - selectStory, |
34 | | - editStory, |
35 | | - trashStory, |
36 | | - isWaiting, |
37 | | - isStoryEstimated, |
38 | 32 | dndDragEnd, |
39 | 33 | dndMoveStory, |
40 | 34 | dndFindStory |
41 | 35 | }) => { |
42 | 36 | const {t, format} = useContext(L10nContext); |
| 37 | + const dispatch = useDispatch(); |
| 38 | + |
| 39 | + const selectedStoryId = useSelector(getSelectedStoryId); |
| 40 | + const isWaiting = useSelector(state => isThisStoryWaiting(state, story.id)); |
| 41 | + const isStoryEstimated = useSelector(state => isThisStoryEstimated(state, story.id)); |
| 42 | + |
43 | 43 | const isSelected = selectedStoryId === story.id; |
44 | 44 | const hasConsensus = hasStoryConsensus(story); |
45 | 45 |
|
@@ -70,6 +70,20 @@ const Story = ({ |
70 | 70 | [dndFindStory, dndMoveStory] |
71 | 71 | ); |
72 | 72 |
|
| 73 | + const triggerSelect = () => { |
| 74 | + dispatch(selectStory(story.id)); |
| 75 | + }; |
| 76 | + |
| 77 | + const triggerEdit = (e) => { |
| 78 | + e.stopPropagation(); // make sure to stop bubbling up. we do not want to trigger story select |
| 79 | + dispatch(editStory(story.id)); |
| 80 | + }; |
| 81 | + |
| 82 | + const triggerTrash = (e) => { |
| 83 | + e.stopPropagation(); // make sure to stop bubbling up. we do not want to trigger story select |
| 84 | + dispatch(trashStory(story.id)); |
| 85 | + }; |
| 86 | + |
73 | 87 | return ( |
74 | 88 | <StyledStory |
75 | 89 | ref={(node) => drag(drop(node))} |
@@ -138,42 +152,15 @@ const Story = ({ |
138 | 152 | } |
139 | 153 | </StyledStory> |
140 | 154 | ); |
141 | | - |
142 | | - function triggerSelect() { |
143 | | - selectStory(story.id); |
144 | | - } |
145 | | - |
146 | | - function triggerEdit(e) { |
147 | | - e.stopPropagation(); // make sure to stop bubbling up. we do not want to trigger story select |
148 | | - editStory(story.id); |
149 | | - } |
150 | | - |
151 | | - function triggerTrash(e) { |
152 | | - e.stopPropagation(); // make sure to stop bubbling up. we do not want to trigger story select |
153 | | - trashStory(story.id); |
154 | | - } |
155 | 155 | }; |
156 | 156 |
|
157 | 157 | Story.propTypes = { |
158 | 158 | story: PropTypes.object, |
159 | | - isWaiting: PropTypes.bool, |
160 | 159 | isHighlighted: PropTypes.bool, |
161 | | - isStoryEstimated: PropTypes.bool, |
162 | | - selectedStoryId: PropTypes.string, |
163 | 160 | onStoryClicked: PropTypes.func, |
164 | | - selectStory: PropTypes.func, |
165 | | - editStory: PropTypes.func, |
166 | | - trashStory: PropTypes.func, |
167 | 161 | dndDragEnd: PropTypes.func, |
168 | 162 | dndMoveStory: PropTypes.func, |
169 | 163 | dndFindStory: PropTypes.func |
170 | 164 | }; |
171 | 165 |
|
172 | | -export default connect( |
173 | | - (state, props) => ({ |
174 | | - selectedStoryId: getSelectedStoryId(state), |
175 | | - isWaiting: isThisStoryWaiting(state, props.story.id), |
176 | | - isStoryEstimated: isThisStoryEstimated(state, props.story.id) |
177 | | - }), |
178 | | - {selectStory, editStory, trashStory} |
179 | | -)(Story); |
| 166 | +export default Story; |
0 commit comments