-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathminiCard.js
128 lines (102 loc) · 3.38 KB
/
miniCard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React from 'react';
import './static/css/minicard.css';
import { DragSource, DropTarget } from 'react-dnd';
import { findDOMNode } from 'react-dom';
import flow from 'lodash/flow'
const cardSource = {
beginDrag(props) {
console.log(props.song);
console.log(props.song.id + " "+props.index);
if(props.name === 'queue')
{
return {
id: props.song.id,
index: props.index,
}
}
return ;
}
}
const cardTarget = {
hover(props, monitor, component) {
if (!component) {
return null
}
const dragIndex = monitor.getItem().index
const hoverIndex = props.index
// Don't replace items with themselves
if (dragIndex === hoverIndex) {
return
}
const hoverBoundingRect = (findDOMNode(
component,
)).getBoundingClientRect()
const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2
const clientOffset = monitor.getClientOffset()
const hoverClientY = (clientOffset).y - hoverBoundingRect.top
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
return
}
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
return
}
props.moveCard(dragIndex, hoverIndex)
monitor.getItem().index = hoverIndex
},
}
class MiniCard extends React.Component {
play() {
this.props.playSong(this.props.song);
}
addToNowPlaying() {
this.props.addToNowPlaying(this.props.song);
}
removeSong() {
this.props.removeSong(this.props.song);
}
render() {
const {isDragging, connectDragSource,connectDropTarget,} = this.props;
const opacity = isDragging ? 0.5 : 1;
const MAX_TITLE_LENGTH = 24;
let videoTitle = this.props.song.title;
if(videoTitle.length > MAX_TITLE_LENGTH) {
videoTitle = videoTitle.substring(0, MAX_TITLE_LENGTH)+'... ';
}
console.log(this.props.name);
return (
connectDragSource &&
connectDropTarget &&
connectDragSource(
connectDropTarget(
<div className='song-card-list uk-margin-small-bottom uk-flex' style={{opacity}}>
<div className="uk-flex" onClick={this.play.bind(this)}>
<img src={this.props.song.thumb} className='uk-border-circle song-card-list-thumb'
alt='IMG'/>
<div className='song-card-list-details col-xs-11 col-sm-11 col-md-10 col-lg-8'>
<div className='song-card-list-title text-color-grey87'>
{this.props.active ? <b>{videoTitle}</b> : <div>{videoTitle}</div>}
</div>
<div className='song-card-list-channel font-size-11'>
{this.props.active ? <b>{this.props.song.uploader}</b> : <div>{this.props.song.uploader}</div>}
</div>
</div>
</div>
<div className="add-to-upnext">
{this.props.name === 'related'?<button name='plus' onClick={this.addToNowPlaying.bind(this)} className="uk-icon-link uk-icon" uk-icon="icon:plus;"/>:
<button name='plus' className="uk-icon-link uk-icon" uk-icon="icon:close;" onClick={this.removeSong.bind(this)} />}
</div>
</div>
),
)
)
}
}
export default flow(DragSource('card',
cardSource,
(connect, monitor) => ({
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging(),
}),),DropTarget('card', cardTarget, (connect) => ({
connectDropTarget: connect.dropTarget(),
})
))(MiniCard);