import { html } from 'lit-html'; import { customElement, instance } from '@lit-html-free/core'; import { UserService } from 'src/resources/services/userservice'; import { SharedState } from 'src/resources/state/sharedstate'; @customElement('settings-comp') export default class extends HTMLElement { public passwordConfirm: string; public password: string; public errors: any[] = []; public success: string; public userService: UserService; public sharedState: SharedState; constructor() { super(); this.userService = instance(UserService); this.sharedState = instance(SharedState); } public async update() { try { await this.userService.update(this.sharedState.currentUser); this.success = 'Updated successfully'; this.render(); setTimeout(() => { this.success = null; this.render(); }, 1500); } catch (e) { const err: any = await Promise.resolve(e); for (const k in err.errors) { if (err.errors && err.errors[k]) { this.errors.push( err.errors[k].map((x: any) => { return k + ': ' + x; }) ); } } } } get canSave() { if (this.passwordConfirm) { return ( this.sharedState && this.sharedState.currentUser && this.passwordConfirm === this.password ); } else { return this.sharedState && this.sharedState.currentUser; } } public logout() { this.userService.purgeAuth(); location.hash = 'home'; } public render() { return html`