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
|
|
|
_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;
|
|
|
|
|
2020-03-10 17:42:13 +08:00
|
|
|
sel.addCommand(async item => {
|
|
|
|
const name = item.name;
|
|
|
|
const commands = ["clear", `load "${this._mpd.escape(name)}"`, "play"];
|
|
|
|
await this._mpd.command(commands);
|
|
|
|
this.selection.clear();
|
|
|
|
this._app.dispatchEvent(new CustomEvent("queue-change")); // fixme notification?
|
2020-03-10 17:07:30 +08:00
|
|
|
}, {label:"Play", icon:"play"});
|
|
|
|
|
2020-03-10 17:42:13 +08:00
|
|
|
sel.addCommand(async item => {
|
|
|
|
const name = item.name;
|
|
|
|
await this._mpd.command(`load "${this._mpd.escape(name)}"`);
|
|
|
|
this.selection.clear();
|
|
|
|
this._app.dispatchEvent(new CustomEvent("queue-change")); // fixme notification?
|
2020-03-10 17:07:30 +08:00
|
|
|
}, {label:"Enqueue", icon:"plus"});
|
|
|
|
|
2020-03-10 17:42:13 +08:00
|
|
|
sel.addCommand(async item => {
|
|
|
|
const name = item.name;
|
|
|
|
if (!confirm(`Really delete playlist '${name}'?`)) { return; }
|
|
|
|
|
|
|
|
await this._mpd.command(`rm "${this._mpd.escape(name)}"`);
|
|
|
|
this._sync();
|
2020-03-10 17:07:30 +08:00
|
|
|
}, {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);
|