import { LitElement, html, type PropertyValueMap } from "lit"; import { customElement } from "../utils/decorators/custom-element"; import { property, state } from "lit/decorators.js"; import { consume } from "@lit/context"; import { type WeavyType, WeavyContext } from "../contexts/weavy-context"; import { localized, msg } from "@lit/localize"; import { ShadowPartsController } from "../controllers/shadow-parts-controller"; import emptyCss from "../scss/components/empty.scss"; import hostContentsCss from "../scss/host-contents.scss"; import "./ui/wy-icon"; import "./ui/wy-progress-circular"; declare global { interface HTMLElementTagNameMap { "wy-empty": WyEmpty; } } /** * Generic empty state display used across the UI. * * **Used sub components:** * * - [``](./ui/wy-icon.ts) * - [``](./ui/wy-icon.ts) * - [``](./ui/wy-progress-circular.ts) * * @slot - Default slot for empty-state content (replaces internal default icon+text). * @slot title - Named slot used inside the default content for the title/text. * * @csspart wy-empty - Root container for the empty state display. */ @customElement("wy-empty") @localized() export class WyEmpty extends LitElement { static override styles = [ emptyCss, hostContentsCss, ]; /** @internal */ protected exportParts = new ShadowPartsController(this); /** * Consumed Weavy context providing network status. * @internal */ @consume({ context: WeavyContext, subscribe: true }) @state() weavy?: WeavyType; /** * Hide network status messaging. */ @property({ type: Boolean }) noNetwork: boolean = false; /** * Force a re-render when network state changes. * @internal */ protected handleUpdate = () => this.requestUpdate(); protected override willUpdate(changedProperties: PropertyValueMap): void { super.willUpdate(changedProperties); if (changedProperties.has("weavy")) { const lastContext = changedProperties.get("weavy"); if (lastContext && lastContext !== this.weavy) { lastContext.removeNetworkListener(this.handleUpdate); } if (this.weavy && lastContext !== this.weavy) { this.weavy.addNetworkListener(this.handleUpdate); } } } override render() { return html`
${this.weavy && !this.noNetwork && this.weavy?.network.state === "unreachable" ? html` ${msg("The server is offline, try again in a few minutes...")} ` : !this.noNetwork && this.weavy?.network.state === "offline" ? html` ${msg("You are currently offline.")} ` : html` ${msg("Nothing to see here yet.")} `}
`; } override connectedCallback(): void { super.connectedCallback(); this.weavy?.addNetworkListener(this.handleUpdate); } override disconnectedCallback(): void { super.disconnectedCallback(); this.weavy?.removeNetworkListener(this.handleUpdate); } }