import { html, render } from "lit-html"; import { keyed } from "lit-html/directives/keyed.js"; import { marked } from "marked"; import { unsafeHTML } from "lit-html/directives/unsafe-html.js"; import * as FacetCategory from "~/common/facets/category.js"; import { effect, signal } from "~/common/signal.js"; import { nothing } from "~/common/element.js"; import { deleteFacet } from "./crud.js"; import { output } from "./output.js"; import { openAddFromURIModal } from "./from-uri.js"; // Signals const FILTER_STORAGE_KEY = "diffuse/dashboard/filter"; const storedFilter = localStorage.getItem(FILTER_STORAGE_KEY); const activeFilter = signal( storedFilter === "prelude" || storedFilter === "interface" ? storedFilter : "all", ); effect(() => { localStorage.setItem(FILTER_STORAGE_KEY, activeFilter.get()); }); /** * @import OutputOrchestrator from "~/components/orchestrator/output/element.js"; */ const emptyFacetsList = () => html`

You haven't saved anything yet. Add a facet by browsing the featured ones or any of the other categories. You can click the toggle to quickly add or remove from your collection. Alternatively, add one using an URI:

`; //////////////////////////////////////////// // LIST //////////////////////////////////////////// /** @type {() => void | undefined} */ let stopMonitor; /** */ export async function renderList() { if (stopMonitor) stopMonitor(); /** @type {HTMLElement | null} */ const listEl = document.querySelector("#list"); if (!listEl) throw new Error("List element not found"); if (listEl.getAttribute("data-rendered") === "f") { listEl.innerHTML = ""; listEl.removeAttribute("data-rendered"); } const out = await output(); stopMonitor = effect(() => { _renderList(out, listEl); }); } /** * @param {OutputOrchestrator} output * @param {HTMLElement} listEl */ function _renderList(output, listEl) { const facetsCol = output.facets.collection(); if (facetsCol.state !== "loaded") { const loading = html`
Loading your software
`; render(loading, listEl); return; } const filter = activeFilter.get(); const col = facetsCol.state === "loaded" ? [...facetsCol.data] .filter((c) => filter === "all" || (filter === "prelude" ? c.kind === "prelude" : c.kind !== "prelude") ) .sort((a, b) => { return a.name.toLocaleLowerCase().localeCompare( b.name.toLocaleLowerCase(), ); }) : []; const selected = output.selected(); const outputLabel = selected?.label ?? selected?.getAttribute?.("label") ?? "Local storage"; const filterBar = html`
Filter by
Userdata from ${outputLabel}
`; const h = col.length || filter !== "all" ? html` ${filterBar} ` : html` ${filterBar} ${emptyFacetsList()} `; render(h, listEl); setTimeout(() => { /** @type {HTMLElement | null} */ const l = listEl.querySelector(".grid-filter--label-output"); /** @type {HTMLElement | null} */ const o = listEl.querySelector(".grid-filter--output"); if (o && l) { l.style.opacity = "0.4"; o.style.opacity = "1"; } }, 250); }