| 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 | 1x
1x
1x
1x
1x
1x
1x
1x
56x
56x
56x
56x
56x
56x
56x
56x
56x
56x
56x
176x
13x
12x
1x
5x
5x
5x
2x
2x
2x
1x
2x
176x
176x
5x
5x
5x
5x
5x
5x
2x
2x
2x
176x
176x
3x
3x
90x
90x
1x
89x
89x
1x
177x
177x
1x
92x
92x
1x
178x
178x
1x
264x
88x
264x
5x
23x
44x
1x
11x
11x
1x
| import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {DropDown} from 'nexshop-web-dropdown';
import {formatSeconds} from "../../../helpers/time-helper";
import {leftPadZero} from "../../../helpers/string-helper";
import {EFFECT_TYPES} from "../../../constants/effect-types"
import {DURATION_ITEMS} from "../../../constants/duration-items";
import {FIT_MODES} from "../../../constants/fit-modes"
class PlaylistEditorView extends Component {
constructor(props) {
super(props);
this.state = {
mouseOverUUID: '',
mouseOverDomType: '',
isDragging: false,
top: 1,
left: 1,
width: 1,
draggingContentItem: null,
selectItem: {
uuid: '',
selectedValue: '',
}
};
this.onMouseOver = this.onMouseOver.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
this.onDeleteClick = this.onDeleteClick.bind(this);
this.onDragStart = this.onDragStart.bind(this);
this.onDragEnd = this.onDragEnd.bind(this);
this.onDragOver = this.onDragOver.bind(this);
this.onTransitionEffectChange = this.onTransitionEffectChange.bind(this);
this.onDurationChange = this.onDurationChange.bind(this);
this.onFitModeChange = this.onFitModeChange.bind(this);
}
onMouseOver(uuid) {
return () => {
if (this.state.isDragging) return;
this.setState({
mouseOverUUID: uuid
});
}
}
onMouseLeave() {
this.setState({
mouseOverUUID: ''
});
}
onDeleteClick(index) {
const {onDeleteItem} = this.props;
onDeleteItem(index);
setTimeout(() => {
//this will be triggered after view is rendered
const {contentItems} = this.props;
let mouseOverUUID = '';
if (index < contentItems.length) {
mouseOverUUID = contentItems[index].uuid
}
this.setState({mouseOverUUID});
}, 0)
}
onDragStart(index) {
const {onOrderChangeStart, contentItems} = this.props;
return (e) => {
const {currentTarget, nativeEvent: {offsetX, offsetY}} = e;
this.setState({isDragging: true, draggingContentItem: {...contentItems[index]}});
//TODO: not tested
this.preview.style.width = `${currentTarget.clientWidth + 5}px`;
//TODO: technical dept
e.dataTransfer.effectAllowed = 'copy';
e.dataTransfer.setDragImage(this.preview, offsetX, offsetY);
onOrderChangeStart(index);
}
}
onDragEnd() {
const {onOrderChangeEnd} = this.props;
this.setState({isDragging: false, draggingContentItem: null});
onOrderChangeEnd();
}
onDragOver(index) {
const {onOrderChangeProcess} = this.props;
return (e) => {
e.preventDefault();
onOrderChangeProcess(index);
}
}
onTransitionEffectChange(uuid) {
const {onUpdateContentItemTransition} = this.props;
return ({value}) => {
onUpdateContentItemTransition(uuid, value);
};
}
onDurationChange(uuid) {
const {onUpdateContentItemDuration} = this.props;
return ({value}) => {
onUpdateContentItemDuration(uuid, value);
};
}
onFitModeChange(uuid) {
const {onUpdateContentItemFitMode} = this.props;
return ({value}) => {
onUpdateContentItemFitMode(uuid, value);
};
}
render() {
const {
resolution: {value, orientation},
onDropDragContentsItem,
contentItems,
blankIndex,
onOrderChangeEnd,
onSelectPreviewItem,
} = this.props;
return (
<div className="playlist-editor-wrapper" onDragOver={(e) => e.preventDefault()}
onDrop={onDropDragContentsItem}>
<div className="playlist-editor">
<div className="playlist-top">
<div className="playlist-summary">
<span className="playlist-summary__label">Counts</span>
<span className="playlist-summary__value">{leftPadZero(contentItems.length)}</span>
<span className="playlist-summary__label">Total</span>
<span className="playlist-summary__value">{
formatSeconds(contentItems.reduce((sum, content) => sum + content.durationSeconds, 0),'hh:mm:ss')
}</span>
</div>
<div className="playlist-resolution">
<div className="playlist-resolution__value">{value}</div>
<div className={`playlist-resolution__${orientation}`}/>
</div>
</div>
<div className="playlist-items">
{
contentItems.map(({contents, uuid, transitionEffect, durationSeconds, fitMode}, index) => {
return (
index === blankIndex ?
<div key={uuid} className="playlist-placeholder" onDragEnd={this.onDragEnd}
onDrop={onOrderChangeEnd}/>
:
<div key={uuid} data-uuid={uuid}
className={`playlist-item${this.state.mouseOverUUID === uuid ? '--hovered' : ''}`}
onMouseLeave={this.onMouseLeave}
onMouseOver={this.onMouseOver(uuid)}
onDragStart={this.onDragStart(index)}
onDragEnd={this.onDragEnd}
onDragOver={this.onDragOver(index)}
draggable={true}>
{uuid === this.state.mouseOverUUID &&
<div className="playlist-item-preview-link">
<div className="playlist-item-preview" onClick={() => {
onSelectPreviewItem(index)
}}>
<div className="playlist-item-preview__play"/>
</div>
</div>}
<div className="playlist-item__thumbnail"
style={{backgroundImage: `url(${contents.thumbnailUrls.thumbnail ? contents.thumbnailUrls.thumbnail : ''})`}}/>
<div className={`playlist-item__type--${contents.type}`}/>
<div className="playlist-item__name">{contents.name}</div>
<div
className={`playlist-item__duration${contents.type === 'video' ? '__video' : ''}`}>
{
contents.type === 'video' ?
(
formatSeconds(durationSeconds, durationSeconds >= 3600 ? 'hh:mm:ss' : 'mm:ss')
) :
(
<DropDown items={DURATION_ITEMS}
selected={DURATION_ITEMS.find((item) => item.value === durationSeconds)}
onSelect={this.onDurationChange(uuid)}/>
)
}
</div>
<div className='playlist-item__effect'>
{
contents.type === 'video' ?
(
<div>No Effect</div>
) :
(
<DropDown items={EFFECT_TYPES}
selected={EFFECT_TYPES.find((item) => item.value === transitionEffect)}
onSelect={this.onTransitionEffectChange(uuid)}/>
)
}
</div>
<div className="playlist-item__fitMode">
<DropDown items={FIT_MODES}
selected={FIT_MODES.find((item) => item.value === fitMode)}
onSelect={this.onFitModeChange(uuid)}
classNamePrefix={'playlist-fitMode'}
/>
</div>
{
this.state.mouseOverUUID === uuid &&
<div className="playlist-item__delete"
onClick={() => this.onDeleteClick(index)}/>
}
</div>
)
})
}
</div>
</div>
<div className="dragging" ref={(preview) => this.preview = preview}>
{
this.state.draggingContentItem &&
<DraggingContentItem contentItem={this.state.draggingContentItem}
durationSeconds={this.state.draggingContentItem.durationSeconds}
transitionEffect={EFFECT_TYPES.filter((item) =>
item.value === this.state.draggingContentItem.transitionEffect)[0]}
/>
}
</div>
</div>
);
}
}
const DraggingContentItem = ({contentItem: {contents}, transitionEffect, durationSeconds}) => {
let formattedDurationSeconds = formatSeconds(durationSeconds, durationSeconds >= 3600 ? 'hh:mm:ss' : 'mm:ss');
return (
<div className='playlist-item playlist-item-shadow'>
<div className="playlist-item__thumbnail"
style={{backgroundImage: `url(${contents.thumbnailUrls.thumbnail ? contents.thumbnailUrls.thumbnail : ''})`}}/>
<div className={`playlist-item__type--${contents.type}`}/>
<div className="playlist-item__name">{contents.name}</div>
<div className="playlist-item__duration">{formattedDurationSeconds}</div>
<div className="playlist-item__effect">{transitionEffect.text}</div>
</div>
)
};
PlaylistEditorView.propTypes = {
resolution: PropTypes.object.isRequired,
contentItems: PropTypes.array.isRequired,
onDropDragContentsItem: PropTypes.func.isRequired,
onDeleteItem: PropTypes.func.isRequired,
onOrderChangeStart: PropTypes.func.isRequired,
onOrderChangeProcess: PropTypes.func.isRequired,
onOrderChangeEnd: PropTypes.func.isRequired,
blankIndex: PropTypes.number,
onSelectPreviewItem: PropTypes.func.isRequired,
onUpdateContentItemTransition: PropTypes.func.isRequired,
onUpdateContentItemDuration: PropTypes.func.isRequired,
onUpdateContentItemFitMode: PropTypes.func.isRequired,
};
export default PlaylistEditorView; |