cyp/app/js/elements/playlists.js
2020-03-09 22:24:31 +01:00

38 lines
716 B
JavaScript

import * as html from "../html.js";
import * as ui from "../ui.js";
import Component from "../component.js";
import Playlist from "./playlist.js";
class Playlists extends Component {
handleEvent(e) {
switch (e.type) {
case "playlists-change":
this._sync();
break;
}
}
_onAppLoad() {
this._app.addEventListener("playlists-change", this);
}
_onComponentChange(c, isThis) {
this.hidden = !isThis;
if (isThis) { this._sync(); }
}
async _sync() {
let lists = await this._mpd.listPlaylists();
this._buildLists(lists);
}
_buildLists(lists) {
html.clear(this);
lists.forEach(name => this.appendChild(new Playlist(name)));
}
}
customElements.define("cyp-playlists", Playlists);