import { state, property } from "lit/decorators.js"; import { msg, localized } from "@lit/localize"; import type { AuthState } from "../utils/AuthService"; import type { CurrentUser } from "../types/user"; import type { ArchiveData } from "../utils/archives"; import LiteElement, { html } from "../utils/LiteElement"; @localized() export class Home extends LiteElement { @property({ type: Object }) authState?: AuthState; @property({ type: Object }) userInfo?: CurrentUser; @state() private isInviteComplete?: boolean; @state() private archiveList?: ArchiveData[]; async firstUpdated() { this.archiveList = await this.getArchives(); } connectedCallback() { if (this.authState) { super.connectedCallback(); } else { this.navTo("/log-in"); } } render() { if (!this.userInfo || !this.archiveList) { return html`
`; } let title: any; let content: any; if (this.userInfo.isAdmin === true) { title = msg("Welcome"); content = this.renderLoggedInAdmin(); } if (this.userInfo.isAdmin === false) { title = msg("Archives"); content = this.renderLoggedInNonAdmin(); } return html`

${title}


${content}
`; } private renderLoggedInAdmin() { if (this.archiveList!.length) { return html`
{ const formData = new FormData(e.target as HTMLFormElement); const id = formData.get("crawlId"); this.navTo(`/crawls/crawl/${id}`); }} >
${msg("Go to Crawl")}
${msg("Go")}

${msg("All Archives")}

${msg("Invite a User")}

${this.renderInvite()}
`; } return html`

${msg("Invite users to start archiving.")}

${this.renderInvite()}
`; } private renderLoggedInNonAdmin() { if (this.archiveList && !this.archiveList.length) { return html`

${msg("You don't have any archives.")}

`; } return html` `; } private renderInvite() { if (this.isInviteComplete) { return html` (this.isInviteComplete = false)} >${msg("Send another invite")} `; } return html` (this.isInviteComplete = true)} > `; } private async getArchives(): Promise { const data = await this.apiFetch("/archives", this.authState!); return data.archives; } }