import {OOElement} from '../oo-element' import {html, render} from '../../lib/html' import askWithSiginIn from '../oo-ask-with-sign-in' import created from '../_organisms/oo-organisms-ask-created' import profile from '../oo-profile' import define from '../../lib/define' import empty from '../oo-empty' import weakMap from '../../lib/weak-map' import getUser from '../../lib/oo-api-get-user' import {HTMLElementEventProjectCreated} from '../../type/event' import {Scope} from '../../type/scope' import {asTags, asScope, asSignInFlow} from '../../lib/as' import {SignInFlow} from '../../type/sign-in-flow' define('oo-profile', profile) define('oo-ask-with-sign-in', askWithSiginIn) define('oo-organisms-ask-created', created) define('oo-empty', empty) const ATTR = { DATA_IAM: 'data-iam', DATA_TAGS: 'data-tags', DATA_SCOPE: 'data-scope', DATA_SIGN_IN_FLOW: 'data-sign-in-flow' } const iam = weakMap() const authorization = weakMap() const userFound = weakMap() const stateScope = weakMap() const stateTags = weakMap>() const signInFlow = weakMap() export default class extends OOElement { static get observedAttributes() { return [ATTR.DATA_IAM, ATTR.DATA_SCOPE, ATTR.DATA_TAGS, ATTR.DATA_SIGN_IN_FLOW] } constructor() { super() authorization.set(this, false) } attributeChangedCallback(attr, prev, next) { if (prev === next || !next) { return } switch(attr) { case ATTR.DATA_IAM: iam.set(this, next) this.fetchUserData() break case ATTR.DATA_TAGS: stateTags.set(this, asTags(next)) break case ATTR.DATA_SCOPE: stateScope.set(this, asScope(next)) break case ATTR.DATA_SIGN_IN_FLOW: signInFlow.set(this, asSignInFlow(next)) if (this.connected) { this.update() } break default: break } } render() { const found = userFound.get(this) const uid = iam.get(this) const scope = stateScope.get(this) const flow = signInFlow.get(this) const tags = stateTags.get(this) || [] if (found === false) { return html` ` } return html`
` } htmlForProjectCreated(uid: string) { return html` ` } onProjectCreated(e: HTMLElementEventProjectCreated) { const {detail} = e const {response} = detail if (Array.isArray(response)) { const [project] = response render(this.htmlForProjectCreated(project.uid), this) } } async fetchUserData() { const api = await getUser(iam.get(this)) const {response} = api if (Array.isArray(response)) { userFound.set(this, true) } else { userFound.set(this, false) } this.update() } }