Skip to content

Commit 77c4ace

Browse files
author
seraphimrose
committed
drop hover
1 parent cc8993d commit 77c4ace

File tree

5 files changed

+76
-14
lines changed

5 files changed

+76
-14
lines changed

app/action/entity.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ export const addList = createAction("Add a new list", data => fromJS(data))
55

66
export const addCard = createAction("Add a new card", data => fromJS(data))
77

8-
export const removeCard = createAction("Remove a card", data => fromJS(data))
8+
export const removeCard = createAction("Remove a card", data => fromJS(data))
9+
10+
export const moveCard = createAction("Move a card", data => fromJS(data))
11+
12+
export const addSlot = createAction("Add a slot", data => fromJS(data))
13+
14+
export const removeSlot = createAction("Remove a slot", data => fromJS(data))

app/component/card/index.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React, { Component } from 'react'
22
import Tooltip from 'antd/lib/tooltip'
33
import Icon from 'antd/lib/icon'
44
import { DragSource, DropTarget } from 'react-dnd';
5+
import { findDOMNode } from 'react-dom'
56

6-
import { removeCard } from 'action/entity'
7+
import { removeCard, addSlot, removeSlot } from 'action/entity'
78
import style from './card.css'
89

910
const cardDragSource = {
@@ -15,7 +16,35 @@ const cardDragSource = {
1516
}
1617

1718
const cardDropTarget = {
19+
hover(props, monitor, component) {
20+
if (props.index === monitor.getItem().index) {
21+
return ;
22+
}
23+
const target = findDOMNode(component).getBoundingClientRect();
24+
const targetMiddleY = (target.bottom - target.top) / 2;
25+
const cursor = monitor.getClientOffset();
26+
27+
const cur = props.list.get('card')
28+
const ind = cur.indexOf(props.index)
29+
30+
props.board.get('list').forEach(v => {
31+
props.dispatch(removeSlot({
32+
listIndex: v
33+
}))
34+
})
1835

36+
if (cursor.y < targetMiddleY) {
37+
props.dispatch(addSlot({
38+
listIndex: props.listIndex,
39+
'new': cur.splice(ind, 0, 'slot')
40+
}))
41+
} else {
42+
props.dispatch(addSlot({
43+
listIndex: props.listIndex,
44+
'new': cur.splice(ind + 1, 0, 'slot')
45+
}))
46+
}
47+
}
1948
}
2049

2150
function dragCollect(connect, monitor) {
@@ -40,6 +69,7 @@ export default class Card extends Component {
4069

4170
render() {
4271
const {
72+
list,
4373
card,
4474
tag,
4575
member,

app/component/list/index.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,17 @@ export default class List extends Component {
111111
style={{width: 270}}
112112
>
113113
{list.get('card').map(value => (
114-
<Card
115-
{...this.props}
116-
key={value}
117-
index={value}
118-
listIndex={index}
119-
card={card.get(value)}
120-
/>
114+
value !== 'slot' ? (
115+
<Card
116+
{...this.props}
117+
key={value}
118+
index={value}
119+
listIndex={index}
120+
card={card.get(value)}
121+
/>
122+
) : (
123+
<div className={style.slot}></div>
124+
)
121125
))}
122126
</Scrollbars>
123127
{this.state.isAdding ? (

app/component/list/list.css

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
padding-bottom: 5px;
1414
}
1515

16+
:local(.slot) {
17+
width: 260px;
18+
height: 100px;
19+
margin-bottom: 8px;
20+
background: #ccc;
21+
border-radius: 5px;
22+
box-shadow: 1px 1px 1px 1px #777;
23+
}
24+
1625
:local(.new) {
1726
width: 260px;
1827
padding: 6px;

app/reducer/entity.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@ const initialState = fromJS(entity)
99
export default createReducer({
1010
[actions.addList]: (state, data) => state.mergeDeep(data),
1111
[actions.addCard]: (state, data) => state.mergeDeep(data),
12-
[actions.removeCard]: (state, key) => (
13-
state//.deleteIn(['card', key.get('index')]) // <-- unnecessary?
14-
.deleteIn(['list', key.get('listIndex'), 'card',
15-
state.getIn(['list', key.get('listIndex'), 'card']).indexOf(key.get('index'))])
16-
)
12+
13+
[actions.removeCard]: (state, data) =>
14+
state//.deleteIn(['card', data.get('index')]) // <-- unnecessary?
15+
.deleteIn(['list', data.get('listIndex'), 'card',
16+
state.getIn(['list', data.get('listIndex'), 'card']).indexOf(data.get('index'))]),
17+
18+
[actions.addSlot]: (state, data) =>
19+
state.setIn(['list', data.get('listIndex'), 'card'], data.get('new')),
20+
[actions.removeSlot]: (state, data) => {
21+
const index = state.getIn(['list', data.get('listIndex'), 'card']).indexOf('slot')
22+
return index !== -1 ? state.deleteIn(['list', data.get('listIndex'), 'card', index]) : state
23+
},
24+
25+
26+
[actions.moveCard]: (state, data) =>
27+
state.deleteIn(['list', data.get('fromListIndex'), 'card',
28+
state.getIn(['list', data.get('fromListIndex'), 'card']).indexOf(data.get('index'))])
29+
.setIn(['list', data.get('toListIndex'), 'card'], data.get('new'))
1730
}, initialState)

0 commit comments

Comments
 (0)