From 1b1987f28df0eaf3f47fc5833e17a803f7ba1b8c Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 24 Jun 2025 23:04:37 -0500 Subject: make frontend work with backend and wait until album response recieved before initializing albums page. extra checks around config --- static/src/albums.js | 2 ++ static/src/connector.js | 5 +++-- static/src/pages.js | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'static') diff --git a/static/src/albums.js b/static/src/albums.js index b7523d9..0ac9195 100644 --- a/static/src/albums.js +++ b/static/src/albums.js @@ -69,6 +69,8 @@ class Album { // create albums const albumsResponse = await apiConnector.fetchAlbums() + if (!albumsResponse.length) + return false for (const res of albumsResponse) new Album(res) diff --git a/static/src/connector.js b/static/src/connector.js index 5d8b62f..9568dc8 100644 --- a/static/src/connector.js +++ b/static/src/connector.js @@ -37,12 +37,12 @@ class APIConnector { }) .catch(error => { console.error("Fetch error:", error) + return null }) } async assetDownload(key) { const filename = await this.assetFileName(key) - console.log(filename) fetch(this.assetFullsizeSrc(key)) .then(response => { if (!response.ok) @@ -59,6 +59,7 @@ class APIConnector { }) .catch(error => { console.error("Fetch error:", error) + return null }) } @@ -87,5 +88,5 @@ class APIConnector { assetFileName(key) { return this.fetch(`/asset/${key}/filename`).then(d => d.filename) } } -const apiConnector = new APIConnector("http://localhost:5000") +const apiConnector = new APIConnector(window.location.origin) export default apiConnector diff --git a/static/src/pages.js b/static/src/pages.js index f6a8b9b..e2199a4 100644 --- a/static/src/pages.js +++ b/static/src/pages.js @@ -34,13 +34,13 @@ export default class Page { this.initialized = false } - setVisible(visible) { + async setVisible(visible) { this.pageContainer.classList.toggle("hidden!", !visible) this.visible = visible if (this.visible) { /* initialize page */ if (!this.initialized && this.initialize) - this.initialized = this.initialize(this.pageContainer) + this.initialized = await this.initialize(this.pageContainer) /* set selected attribute on the link */ for (const a of menu.querySelectorAll("a")) { -- cgit v1.2.3