import {OOElement} from '../oo-element' import {html} from '../../lib/html' import define from '../../lib/define' import projectStatus from '../oo-project-status' import {OOProject} from '../../type/oo-project' import getProject from '../../lib/oo-api-get-project' import weakMap from '../../lib/weak-map' import markdown from '../oo-markdown' import message from '../_atoms/oo-atoms-message' import button from '../_atoms/oo-atoms-button' import users from '../_molecules/oo-molecules-project-users' import empty from '../oo-empty' import toMap from '../../lib/extensions-to-map' import {template as tagsTemplate} from '../../lib/tags' import {href} from '../../lib/href' define('oo-markdown', markdown) define('oo-atoms-message', message) define('oo-atoms-button', button) define('oo-molecules-project-users', users) define('oo-empty', empty) define('oo-project-status', projectStatus) const ATTR = { DATA_UID: 'data-uid' } const stateUid = weakMap() const stateProject = weakMap() const stateIsUnbeheldBody = weakMap() export default class extends OOElement { static get observedAttributes() { return [ATTR.DATA_UID] } attributeChangedCallback(attr, prev, next) { if (prev === next) { return } stateUid.set(this, next) stateProject.delete(this) this.fetchProjects(stateUid.get(this)) } connectedCallback() { super.connectedCallback(false) } disconnectedCallback() { super.disconnectedCallback() stateUid.delete(this) stateProject.delete(this) stateIsUnbeheldBody.delete(this) } render() { const project = stateProject.get(this) if (!project || !('uid' in project)) { return html` ` } const {uid} = project const exts = toMap(project) const title = exts.has('title') ? exts.get('title') : '' const body = exts.has('body') ? exts.get('body') : '' const offerer = exts.has('author') ? exts.get('author') : '' const assignee = exts.has('assignee') ? exts.get('assignee') : '' const tags = exts.has('tags') ? exts.get('tags') : [] const titleHTML = title ? html`

${title}

` : html`` const isUnbeheldBody = stateIsUnbeheldBody.get(this) return html`
${titleHTML}
${body}
` } renderedCallback() { if (stateIsUnbeheldBody.has(this)) { return } const body = this.shadowRoot.querySelector('.body') const md = this.shadowRoot.querySelector('oo-markdown') if (body && md) { const bH = body.clientHeight const mH = md.clientHeight stateIsUnbeheldBody.set(this, bH < mH) this.update() } } async fetchProjects(uid: string) { const api = await getProject(uid) const {response} = api if (Array.isArray(response)) { const [project] = response stateProject.set(this, project) } else { stateProject.delete(this) } this.update() } }