import { html, render } from "/js/lib/lit-html.js"; import { Component } from "/js/components/component.js"; import { postFeedTemplate } from "/js/templates/postFeed.template.js"; import { Signal, ReactiveStore, effect } from "/js/signals.js"; class PluginPostsFeed extends Component { static get observedAttributes() { return ["uris", "empty-message"]; } connectedCallback() { if (this.initialized) return; this.initialized = true; if (!this.renderContext) { throw new Error("plugin-posts-feed requires a renderContext property"); } const { dataLayer, isAuthenticated, pluginService, postInteractionHandler, } = this.renderContext; this.dataLayer = dataLayer; this.isAuthenticated = isAuthenticated; this.pluginService = pluginService; this.postInteractionHandler = postInteractionHandler; this.state = new ReactiveStore("plugin-posts-feed"); this.state.$uris = new Signal.State(this.parseUris()); this.state.$emptyMessage = new Signal.State( this.getAttribute("empty-message"), ); this.state.$loaded = new Signal.State(false); this.state.$posts = new Signal.Computed(() => { if (!this.state.$loaded.get()) return null; const uris = this.state.$uris.get(); if (!uris) return null; return uris .map((uri) => this.dataLayer.derived.$hydratedPosts.get(uri)) .filter(Boolean); }); this.state.$error = new Signal.State(null); this._disposers = [ effect(() => { const error = this.state.$error.get(); const posts = this.state.$posts.get(); const currentUser = this.dataLayer.derived.$currentUser.get(); const emptyMessage = this.state.$emptyMessage.get(); if (error) { render(html`