import { html } from 'lit-html'; import { customElement, instance } from '@lit-html-free/core'; import { ArticleService } from 'src/resources/services/articleservice'; import { getRouter } from '@lit-html-free/router'; @customElement('editor-comp') export default class extends HTMLElement { public routeConfig: any; public slug: any; public tag: string; public article: any = { title: '', description: '', body: '', tagList: [] }; public articleService: ArticleService; constructor() { super(); this.articleService = instance(ArticleService); } public async activate(_route: string, params: any, routeConfig: any) { this.routeConfig = routeConfig; this.slug = params.slug; if (this.slug) { return (this.article = await this.articleService.get(this.slug)); } else { this.article = { title: '', description: '', body: '', tagList: [] }; } return null; } public addTag(tag: any) { this.article.tagList.push(tag); this.render(); } public removeTag(tag: any) { this.article.tagList.splice(this.article.tagList.indexOf(tag), 1); this.render(); } public async publishArticle() { const article = await this.articleService.save(this.article); this.slug = article.slug; getRouter().goto('article/:slug', { slug: this.slug }); } public render() { return html`
(this.article.title = e.target.value)} />
(this.article.description = e.target.value)} />
this.addTag(e.target.value)} />
${this.article.tagList.map((tag: any) => { console.log(tag); return html` { this.removeTag(tag); }} > ${tag} `; })}
`; } }