diff --git a/src/common/pages/build.js b/src/common/pages/build.js index 73d0497f..af7b5828 100644 --- a/src/common/pages/build.js +++ b/src/common/pages/build.js @@ -22,6 +22,36 @@ import { output } from "./output.js"; const $editor = signal(/** @type {EditorView | null} */ (null)); const $editingFacet = signal(/** @type {Facet | null} */ (null)); +//////////////////////////////////////////// +// LOADING +//////////////////////////////////////////// + +const LOADING_EL_ID = "editor-loading"; + +/** + * @param {boolean} loading + */ +function setEditorLoading(loading) { + const container = /** @type {HTMLElement | null} */ ( + document.querySelector("#html-input-container") + ); + if (!container) return; + + if (loading) { + if (document.getElementById(LOADING_EL_ID)) return; + const el = document.createElement("div"); + el.id = LOADING_EL_ID; + el.className = "with-icon"; + el.style.fontSize = "var(--fs-sm)"; + el.innerHTML = ' Loading…'; + container.before(el); + container.hidden = true; + } else { + document.getElementById(LOADING_EL_ID)?.remove(); + container.hidden = false; + } +} + //////////////////////////////////////////// // EDITOR //////////////////////////////////////////// @@ -152,8 +182,10 @@ async function editFacet(ogFacet) { // Make sure HTML is loaded if (!facet.html && facet.uri) { + setEditorLoading(true); const html = await loadURI(facet.uri); const cid = await CID.create(0x55, new TextEncoder().encode(html)); + setEditorLoading(false); facet.html = html; facet.cid = cid; @@ -216,9 +248,11 @@ export function listenForExamplesEdit() { switch (rel) { case "edit": { + setEditorLoading(true); const facet = await facetFromURI({ kind, name, uri }, { fetchHTML: true, }); + setEditorLoading(false); editFacet(facet); document.querySelector("#build")?.scrollIntoView(); break; @@ -236,9 +270,14 @@ export async function editFacetFromURL() { const idParam = new URLSearchParams(location.search).get("id"); if (idParam) { - const out = await output(); - const col = await Output.data(out.facets); - const facet = col.find((f) => f.id === idParam); - if (facet) await editFacet(facet); + setEditorLoading(true); + try { + const out = await output(); + const col = await Output.data(out.facets); + const facet = col.find((f) => f.id === idParam); + if (facet) await editFacet(facet); + } finally { + setEditorLoading(false); + } } } diff --git a/src/common/pages/dashboard.js b/src/common/pages/dashboard.js index 7560004f..2154df00 100644 --- a/src/common/pages/dashboard.js +++ b/src/common/pages/dashboard.js @@ -78,7 +78,7 @@ function _renderList(output, listEl) { if (facetsCol.state !== "loaded") { const loading = html` -
+
Loading your software
diff --git a/src/dashboard.vto b/src/dashboard.vto index 01c61ed9..e8d91f01 100644 --- a/src/dashboard.vto +++ b/src/dashboard.vto @@ -9,7 +9,7 @@ title: Your collection | Diffuse
-
+
Loading your software