-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
PlaylistIndex.tsx
355 lines (339 loc) · 10.5 KB
/
PlaylistIndex.tsx
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
import Button from '@/Bootstrap/Button';
import SafeAnchor from '@/Bootstrap/SafeAnchor';
import { Layout } from '@/Components/Shared/Layout';
import { ArtistFilters } from '@/Components/Shared/Partials/Knockout/ArtistFilters';
import { TagFilters } from '@/Components/Shared/Partials/Knockout/TagFilters';
import { EmbedPVPreview } from '@/Components/Shared/Partials/PV/EmbedPVPreview';
import { DraftIcon } from '@/Components/Shared/Partials/Shared/DraftIcon';
import { SongTypeLabel } from '@/Components/Shared/Partials/Song/SongTypeLabel';
import { useVdbPlayer } from '@/Components/VdbPlayer/VdbPlayerContext';
import { useVocaDbTitle } from '@/Components/useVocaDbTitle';
import JQueryUIButton from '@/JQueryUI/JQueryUIButton';
import JQueryUIDialog from '@/JQueryUI/JQueryUIDialog';
import { PVServiceIcons } from '@/Models/PVServiceIcons';
import { EntryUrlMapper } from '@/Shared/EntryUrlMapper';
import { UrlMapper } from '@/Shared/UrlMapper';
import { useNostalgicDiva } from '@vocadb/nostalgic-diva';
import classNames from 'classnames';
import { runInAction } from 'mobx';
import { observer } from 'mobx-react-lite';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { ReactSortable } from 'react-sortablejs';
const SkipListEdit = observer(
(): React.ReactElement => {
const { t } = useTranslation(['ViewRes', 'VocaDb.Web.Resources.Domain']);
const { playQueue } = useVdbPlayer();
return (
<JQueryUIDialog
title="Edit skip list" /* TODO: localize */
autoOpen={playQueue.skipList.dialogVisible}
width={550}
close={playQueue.skipList.hideDialog}
buttons={[
{
text: 'Done' /* TODO: localize */,
click: playQueue.skipList.hideDialog,
},
]}
>
<div className="form-horizontal">
<div className="control-group">
<div className="controls">
<label className="checkbox">
<input
type="checkbox"
checked={playQueue.skipList.removeFromPlayQueueOnSkip}
onChange={(e): void =>
runInAction(() => {
playQueue.skipList.removeFromPlayQueueOnSkip =
e.target.checked;
})
}
/>
Remove from play queue on skip{/* TODO: localize */}
</label>
</div>
</div>
<div className="control-group">
<div className="control-label">
{t('VocaDb.Web.Resources.Domain:EntryTypeNames.Artist')}
</div>
<div className="controls">
<ArtistFilters
artistFilters={playQueue.skipList.artistFilters}
artistParticipationStatus={false}
showChildVoicebanks={false}
/>
</div>
</div>
<div className="control-group">
<div className="control-label">{t('ViewRes:Shared.Tag')}</div>
<div className="controls">
<TagFilters
tagFilters={playQueue.skipList.tagFilters}
showChildTags={false}
/>
</div>
</div>
</div>
</JQueryUIDialog>
);
},
);
const urlMapper = new UrlMapper(vdb.values.baseAddress);
const pvServiceIcons = new PVServiceIcons(urlMapper);
const PlaylistIndex = observer(
(): React.ReactElement => {
const { t, ready } = useTranslation(['ViewRes', 'ViewRes.Search']);
const title = t('ViewRes.Search:Index.Playlist');
useVocaDbTitle(title, ready);
const diva = useNostalgicDiva();
const { playQueue } = useVdbPlayer();
const handleClickAddToNewSongList = React.useCallback(() => {
// TODO: Implement.
}, []);
React.useEffect(() => {
return (): void => {
playQueue.skipList.hideDialog();
};
});
return (
<Layout
title={title}
toolbar={
<>
{playQueue.currentItem && (
<div id="pvPlayer" className="song-pv-player">
<EmbedPVPreview
entry={playQueue.currentItem.entry}
pv={playQueue.currentItem.pv}
allowInline
/>
</div>
)}
<div css={{ display: 'flex' }}>
<div>
{playQueue.selectedItems.length > 0 ? (
<>
<JQueryUIButton
as={SafeAnchor}
onClick={playQueue.playSelectedItemsNext}
icons={{ primary: 'ui-icon-play' }}
>
Play next{/* TODO: localize */}
</JQueryUIButton>{' '}
<JQueryUIButton
as={SafeAnchor}
onClick={playQueue.addSelectedItemsToPlayQueue}
icons={{ primary: 'ui-icon-plus' }}
>
Add to play queue{/* TODO: localize */}
</JQueryUIButton>{' '}
<JQueryUIButton
as={SafeAnchor}
onClick={handleClickAddToNewSongList}
icons={{ primary: 'ui-icon-plus' }}
disabled={true}
title="Coming soon!" /* TODO: Remove. */
>
Add to new song list{/* TODO: localize */}
</JQueryUIButton>{' '}
<JQueryUIButton
as={SafeAnchor}
onClick={playQueue.removeSelectedItemsFromPlayQueue}
icons={{ primary: ' ui-icon-close' }}
>
Remove{/* TODO: localize */}
</JQueryUIButton>
</>
) : (
<>
<JQueryUIButton
as={SafeAnchor}
onClick={playQueue.clear}
icons={{ primary: 'ui-icon-trash' }}
disabled={playQueue.isEmpty}
>
Clear{/* TODO: localize */}
</JQueryUIButton>{' '}
<JQueryUIButton
as={SafeAnchor}
onClick={playQueue.addSelectedItemsToPlayQueue}
icons={{ primary: 'ui-icon-plus' }}
disabled={playQueue.isEmpty}
>
Add to play queue{/* TODO: localize */}
</JQueryUIButton>{' '}
<JQueryUIButton
as={SafeAnchor}
onClick={handleClickAddToNewSongList}
icons={{ primary: 'ui-icon-plus' }}
disabled={true}
title="Coming soon!" /* TODO: Remove. */
>
Add to new song list{/* TODO: localize */}
</JQueryUIButton>
</>
)}
</div>
<div css={{ flexGrow: 1 }} />
<div>
<JQueryUIButton
as={SafeAnchor}
href="#"
onClick={playQueue.skipList.showDialog}
>
Edit skip list{/* TODO: localize */}
</JQueryUIButton>
</div>
</div>
</>
}
>
{!playQueue.isEmpty && (
<table
className="table"
css={{ backgroundColor: 'rgba(255, 255, 255, 0.9)' }}
>
<thead>
<tr>
<th>
<input
type="checkbox"
checked={playQueue.allItemsSelected}
onChange={(e): void =>
runInAction(() => {
playQueue.allItemsSelected = e.target.checked;
})
}
/>
</th>
<th colSpan={2}>
{
playQueue.selectedItems.length > 0
? `${playQueue.selectedItems.length} item(s) selected` /* TODO: localize */
: 'Name' /* TODO: localize */
}
</th>
</tr>
</thead>
<ReactSortable
tag="tbody"
list={playQueue.items}
setList={(items): void =>
runInAction(() => {
playQueue.items = items;
})
}
>
{playQueue.items.map((item) => (
<tr
className={classNames(
item === playQueue.currentItem && 'info',
)}
key={item.id}
>
<td>
<input
type="checkbox"
checked={item.isSelected}
onChange={(e): void =>
runInAction(() => {
item.isSelected = e.target.checked;
})
}
/>
</td>
<td style={{ width: '80px' }}>
{item.entry.urlThumb && (
<Link
to={EntryUrlMapper.details_entry(item.entry)}
title={item.entry.additionalNames}
>
{/* eslint-disable-next-line jsx-a11y/alt-text */}
<img
src={item.entry.urlThumb}
title="Cover picture" /* TODO: localize */
className="coverPicThumb img-rounded"
referrerPolicy="same-origin"
/>
</Link>
)}
</td>
<td>
<div className="pull-right">
<Button
onClick={async (): Promise<void> => {
if (playQueue.currentItem === item) {
await diva.setCurrentTime(0);
} else {
playQueue.setCurrentItem(item);
}
}}
href="#"
>
<i className="icon-play" /> Play{/* TODO: localize */}
</Button>{' '}
<Button
onClick={(): Promise<void> =>
playQueue.removeFromPlayQueue([item])
}
href="#"
>
<i className="icon-remove" />{' '}
{t('ViewRes:Shared.Remove')}
</Button>
</div>
<Link
to={EntryUrlMapper.details_entry(item.entry)}
title={item.entry.additionalNames}
>
{item.entry.name}
</Link>{' '}
{item.entry.entryType === 'Song' /* TODO: enum */ &&
item.entry.songType && (
<>
{' '}
<SongTypeLabel songType={item.entry.songType} />
</>
)}{' '}
{pvServiceIcons
.getIconUrls(item.pv.service)
.map((icon, index) => (
<React.Fragment key={icon.service}>
{index > 0 && ' '}
{/* eslint-disable-next-line jsx-a11y/alt-text */}
<img src={icon.url} title={icon.service} />
</React.Fragment>
))}{' '}
<DraftIcon status={item.entry.status} />
{(item.entry.entryType === 'Album' ||
item.entry.entryType === 'Song') && (
<>
<br />
<small className="extraInfo">
{item.entry.artistString}
</small>
</>
)}
</td>
</tr>
))}
</ReactSortable>
</table>
)}
{playQueue.hasMoreItems && (
<h3>
<SafeAnchor onClick={playQueue.loadMore}>
{t('ViewRes:Shared.ShowMore')}
</SafeAnchor>
</h3>
)}
<SkipListEdit />
</Layout>
);
},
);
export default PlaylistIndex;