2024-08-03 00:38:54 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// elements
|
|
|
|
|
|
|
|
/** @type {HTMLButtonElement} */
|
|
|
|
let loadAlbumsBtn
|
|
|
|
|
|
|
|
/** @type {HTMLButtonElement} */
|
|
|
|
let loadPhotosBtn
|
|
|
|
|
|
|
|
/** @type {HTMLSelectElement} */
|
|
|
|
let albumSelect
|
|
|
|
|
2024-08-03 01:47:22 -04:00
|
|
|
/** @type {HTMLParagraphElement} */
|
|
|
|
let noticeP
|
|
|
|
|
|
|
|
/** @type {HTMLDialogElement} */
|
|
|
|
let noticeDialog
|
|
|
|
|
2024-08-03 00:38:54 -04:00
|
|
|
function main() {
|
|
|
|
albumSelect = document.getElementById("album_selector")
|
|
|
|
loadAlbumsBtn = document.getElementById("load_albums_button")
|
|
|
|
loadPhotosBtn = document.getElementById("load_photos_button")
|
2024-08-03 01:47:22 -04:00
|
|
|
noticeDialog = document.getElementById("notice_dialog")
|
|
|
|
noticeP = document.getElementById("notice_p")
|
2024-08-03 00:38:54 -04:00
|
|
|
loadAlbumsBtn.onclick = () => loadAlbums()
|
|
|
|
loadPhotosBtn.onclick = () => loadPhotos()
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadAlbums() {
|
|
|
|
(async () => {
|
2024-08-03 01:47:22 -04:00
|
|
|
try {
|
|
|
|
closeNotice()
|
|
|
|
const resp = await fetch("get-albums")
|
|
|
|
const albums = await resp.json()
|
|
|
|
if(albums.length == 0) {
|
|
|
|
showNotice("No Albums found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
albumSelect.replaceChildren() // This empties existing options
|
|
|
|
for(const album of albums) {
|
|
|
|
albumSelect.add(new Option(album.Title, album.UID))
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
console.log(e)
|
2024-08-03 00:38:54 -04:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2024-08-03 01:47:22 -04:00
|
|
|
function closeNotice() {
|
|
|
|
noticeDialog.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} notice
|
|
|
|
*/
|
|
|
|
function showNotice(notice) {
|
|
|
|
noticeP.textContent = notice
|
|
|
|
noticeDialog.show()
|
|
|
|
}
|
|
|
|
|
2024-08-03 00:38:54 -04:00
|
|
|
function loadPhotos() {
|
2024-08-03 01:47:22 -04:00
|
|
|
closeNotice()
|
2024-08-03 00:38:54 -04:00
|
|
|
const selected = albumSelect.selectedOptions
|
|
|
|
if(selected.length != 1) {
|
2024-08-03 01:47:22 -04:00
|
|
|
showNotice("Select an album to load photos")
|
2024-08-03 00:38:54 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
const [elem] = selected
|
|
|
|
console.log(elem)
|
|
|
|
console.log(elem.text)
|
|
|
|
console.log(elem.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main()
|