@@ -18,6 +18,7 @@
let ws = null;
let wasm_exports = null;
let prevFileIndex = null;
let library_view = "album";
const text_decoder = new TextDecoder();
const text_encoder = new TextEncoder();
@@ -164,7 +165,20 @@
domSectQueue.classList.remove("hidden");
}
function renderLibraryUi() {
function renderLibraryUiArtists() {
const artists_len = wasm_exports.artists_len();
resizeDomList(domListLibrary, artists_len, '<li></li>');
for (let i = 0; i < artists_len; i += 1) {
const dbName = unwrapString(wasm_exports.artist_name(i));
const name = (dbName.length == 0) ? "[Unknown Artist]" : dbName;
const liDom = domListLibrary.children[i];
liDom.textContent = name;
liDom.attributes['data-id'] = 'r' + i;
}
}
function renderLibraryUiAlbums() {
const albums_len = wasm_exports.albums_len();
resizeDomList(domListLibrary, albums_len, '<li></li>');
@@ -176,6 +190,31 @@
liDom.textContent = title;
liDom.attributes['data-id'] = 'a' + i;
}
}
function renderLibraryUiFiles() {
const files_len = wasm_exports.files_len();
resizeDomList(domListLibrary, files_len, '<li></li>');
for (let i = 0; i < files_len; i += 1) {
const dbName = unwrapString(wasm_exports.file_name(i));
const name = (dbName.length == 0) ? "[Error in filename]" : dbName;
const liDom = domListLibrary.children[i];
liDom.textContent = name;
liDom.attributes['data-id'] = 'f' + i;
}
}
function renderLibraryUi() {
if (library_view == "album") {
renderLibraryUiAlbums();
} else if (library_view == "artist") {
renderLibraryUiArtists();
} else if (library_view == "file") {
renderLibraryUiFiles();
} else {
console.log("unhandled library_view");
}
domSectLibrary.classList.remove("hidden");
}
@@ -203,12 +242,32 @@
renderPlaybackUi();
}
function onClickOrganize(ev) {
const elm = ev.srcElement;
if (elm.text == "Artist / Album / Song") {
library_view = "artist";
} else if (elm.text == "Album / Song") {
library_view = "album";
} else if (elm.text == "All Files") {
library_view = "file";
} else {
console.log("unknown element '" + ev.srcElement.text + "'");
}
renderLibraryUi()
}
function onClickLibrary(ev) {
const id = ev.srcElement.attributes['data-id'];
if (id == null) return;
if (id[0] == 'a') {
const albumIndex = +id.substring(1);
wasm_exports.enqueueAlbum(albumIndex);
const album_index = +id.substring(1);
wasm_exports.enqueueAlbum(album_index);
} else if (id[0] == 'r') {
const artist_index = +id.substring(1);
wasm_exports.enqueueArtist(artist_index);
} else if (id[0] == 'f') {
const file_index = +id.substring(1);
wasm_exports.enqueueFile(file_index);
}
}