cyp/app/js/elements/playlists.js

58 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-03-10 05:24:31 +08:00
import * as html from "../html.js";
import Component from "../component.js";
import Playlist from "./playlist.js";
2019-03-28 22:23:28 +08:00
2020-03-09 16:26:10 +08:00
class Playlists extends Component {
2020-03-10 17:07:30 +08:00
constructor() {
super({selection:"single"});
this._initCommands();
}
2020-03-09 16:26:10 +08:00
handleEvent(e) {
switch (e.type) {
case "playlists-change":
this._sync();
break;
}
}
2019-03-28 22:23:28 +08:00
2020-03-09 16:26:10 +08:00
_onAppLoad() {
this._app.addEventListener("playlists-change", this);
}
2019-03-28 22:23:28 +08:00
2020-03-09 16:26:10 +08:00
_onComponentChange(c, isThis) {
this.hidden = !isThis;
if (isThis) { this._sync(); }
}
2019-03-29 03:28:55 +08:00
2020-03-09 16:26:10 +08:00
async _sync() {
let lists = await this._mpd.listPlaylists();
this._buildLists(lists);
}
_buildLists(lists) {
2020-03-10 05:24:31 +08:00
html.clear(this);
2020-03-10 17:07:30 +08:00
this.selection.clear();
2019-03-28 22:23:28 +08:00
2020-03-10 05:24:31 +08:00
lists.forEach(name => this.appendChild(new Playlist(name)));
2020-03-09 16:26:10 +08:00
}
2020-03-10 17:07:30 +08:00
_initCommands() {
const sel = this.selection;
sel.addCommand(async items => {
}, {label:"Play", icon:"play"});
sel.addCommand(async items => {
}, {label:"Enqueue", icon:"plus"});
sel.addCommand(async items => {
}, {label:"Delete", icon:"delete"});
sel.addCommandCancel();
}
2019-03-28 22:23:28 +08:00
}
2020-03-09 16:26:10 +08:00
customElements.define("cyp-playlists", Playlists);