cyp/app/js/playlists.js

32 lines
608 B
JavaScript
Raw Normal View History

2019-03-28 22:23:28 +08:00
import * as mpd from "./lib/mpd.js";
import * as html from "./lib/html.js";
import * as pubsub from "./lib/pubsub.js";
import * as ui from "./lib/ui.js";
let node;
function buildLists(lists) {
let ul = node.querySelector("ul");
html.clear(ul);
lists.map(list => ui.playlist(list, ul));
}
async function syncLists() {
let lists = await mpd.listPlaylists();
buildLists(lists);
}
2019-03-29 03:28:55 +08:00
function onPlaylistsChange(message, publisher, data) {
syncLists();
}
2019-03-28 22:23:28 +08:00
export async function activate() {
syncLists();
}
export function init(n) {
node = n;
2019-03-29 03:28:55 +08:00
pubsub.subscribe("playlists-change", onPlaylistsChange);
2019-03-28 22:23:28 +08:00
}