fix: Update browser title (#2054)

Updates browser title when visiting the following pages:

- Superadmin dashboard
- Org top-level pages
- Account settings
This commit is contained in:
sua yoo 2024-08-29 16:50:14 -07:00 committed by GitHub
parent 988d9c9e2b
commit eb2dab8ae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 103 additions and 16 deletions

View File

@ -0,0 +1,24 @@
import { LitElement, type PropertyValues } from "lit";
import { customElement, property } from "lit/decorators.js";
/**
* Updates user's browser title bar
*/
@customElement("btrix-document-title")
export class DocumentTitle extends LitElement {
@property({ type: String })
title = "";
disconnectedCallback(): void {
// Reset back to default title
document.title = "Browsertrix";
super.disconnectedCallback();
}
willUpdate(changedProperties: PropertyValues<this>) {
if (changedProperties.has("title") && this.title) {
document.title = this.title;
}
}
}

View File

@ -1,5 +1,6 @@
import "./ui"; import "./ui";
import "./utils"; import "./utils";
import "./document-title";
import("./orgs-list"); import("./orgs-list");
import("./not-found"); import("./not-found");

View File

@ -1,3 +1,2 @@
import("./account-settings");
import("./invite-form"); import("./invite-form");
import("./sign-up-form"); import("./sign-up-form");

View File

@ -124,6 +124,10 @@ export class AccountSettings extends LiteElement {
render() { render() {
if (!this.userInfo) return; if (!this.userInfo) return;
return html` return html`
<btrix-document-title
title=${msg("Account Settings")}
></btrix-document-title>
<div class="mx-auto max-w-screen-sm"> <div class="mx-auto max-w-screen-sm">
<h1 class="mb-7 text-xl font-semibold leading-8"> <h1 class="mb-7 text-xl font-semibold leading-8">
${msg("Account Settings")} ${msg("Account Settings")}

View File

@ -99,6 +99,10 @@ export class Home extends LiteElement {
if (this.userInfo.orgs.length && !this.orgList) { if (this.userInfo.orgs.length && !this.orgList) {
return html` return html`
<btrix-document-title
title=${msg("Admin dashboard")}
></btrix-document-title>
<div class="my-24 flex items-center justify-center text-3xl"> <div class="my-24 flex items-center justify-center text-3xl">
<sl-spinner></sl-spinner> <sl-spinner></sl-spinner>
</div> </div>
@ -106,6 +110,10 @@ export class Home extends LiteElement {
} }
return html` return html`
<btrix-document-title
title=${msg("Admin dashboard")}
></btrix-document-title>
<div class="bg-white"> <div class="bg-white">
<header <header
class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4 md:py-8" class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4 md:py-8"

View File

@ -95,14 +95,16 @@ export class Crawls extends LiteElement {
} }
render() { render() {
return html` <div return html`<btrix-document-title
class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4" title=${msg("Running crawls")}
> ></btrix-document-title>
${this.crawlId
? // Render loading indicator while preparing to redirect <div class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4">
this.renderLoading() ${this.crawlId
: this.renderCrawls()} ? // Render loading indicator while preparing to redirect
</div>`; this.renderLoading()
: this.renderCrawls()}
</div>`;
} }
private renderCrawls() { private renderCrawls() {

View File

@ -9,3 +9,4 @@ import(/* webpackChunkName: "verify" */ "./verify");
import(/* webpackChunkName: "reset-password" */ "./reset-password"); import(/* webpackChunkName: "reset-password" */ "./reset-password");
import(/* webpackChunkName: "users-invite" */ "./users-invite"); import(/* webpackChunkName: "users-invite" */ "./users-invite");
import(/* webpackChunkName: "accept-invite" */ "./invite/accept"); import(/* webpackChunkName: "accept-invite" */ "./invite/accept");
import(/* webpackChunkName: "account-settings" */ "./account-settings");

View File

@ -87,6 +87,10 @@ export class AcceptInvite extends BtrixElement {
} }
return html` return html`
<btrix-document-title
title=${msg("Accept invitation")}
></btrix-document-title>
<section <section
class="flex min-h-full w-full flex-col justify-center gap-12 p-5 md:flex-row md:gap-16 md:py-16" class="flex min-h-full w-full flex-col justify-center gap-12 p-5 md:flex-row md:gap-16 md:py-16"
> >

View File

@ -1,4 +1,5 @@
import { localized, msg, str } from "@lit/localize"; import { localized, msg, str } from "@lit/localize";
import { nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js"; import { customElement, property, state } from "lit/decorators.js";
import { choose } from "lit/directives/choose.js"; import { choose } from "lit/directives/choose.js";
import { ifDefined } from "lit/directives/if-defined.js"; import { ifDefined } from "lit/directives/if-defined.js";
@ -231,6 +232,10 @@ export class Org extends LiteElement {
this.orgTab === "items" && (this.params as OrgParams["items"]).qaTab; this.orgTab === "items" && (this.params as OrgParams["items"]).qaTab;
return html` return html`
<btrix-document-title
title=${ifDefined(this.userOrg?.name)}
></btrix-document-title>
<div class="flex min-h-full flex-col"> <div class="flex min-h-full flex-col">
<btrix-org-status-banner></btrix-org-status-banner> <btrix-org-status-banner></btrix-org-status-banner>
${this.renderOrgNavBar()} ${this.renderOrgNavBar()}
@ -240,19 +245,58 @@ export class Org extends LiteElement {
: "w-full max-w-screen-desktop pt-7"} mx-auto box-border flex flex-1 flex-col p-3" : "w-full max-w-screen-desktop pt-7"} mx-auto box-border flex flex-1 flex-col p-3"
aria-labelledby="${this.orgTab}-tab" aria-labelledby="${this.orgTab}-tab"
> >
${when(this.userOrg, () => ${when(this.userOrg, (userOrg) =>
choose( choose(
this.orgTab, this.orgTab,
[ [
["home", this.renderDashboard], ["home", this.renderDashboard],
["items", this.renderArchivedItem], [
["workflows", this.renderWorkflows], "items",
["browser-profiles", this.renderBrowserProfiles], () => html`
["collections", this.renderCollections], <btrix-document-title
title=${`${msg("Archived Items")} - ${userOrg.name}`}
></btrix-document-title>
${this.renderArchivedItem()}
`,
],
[
"workflows",
() => html`
<btrix-document-title
title=${`${msg("Crawl Workflows")} - ${userOrg.name}`}
></btrix-document-title>
${this.renderWorkflows()}
`,
],
[
"browser-profiles",
() => html`
<btrix-document-title
title=${`${msg("Browser Profiles")} - ${userOrg.name}`}
></btrix-document-title>
${this.renderBrowserProfiles()}
`,
],
[
"collections",
() => html`
<btrix-document-title
title=${`${msg("Collections")} - ${userOrg.name}`}
></btrix-document-title>
${this.renderCollections()}
`,
],
[ [
"settings", "settings",
() => () =>
this.appState.isAdmin ? this.renderOrgSettings() : html``, this.appState.isAdmin
? html`
<btrix-document-title
title=${`${msg("Org Settings")} - ${userOrg.name}`}
></btrix-document-title>
${this.renderOrgSettings()}
`
: nothing,
], ],
], ],
() => () =>
@ -429,7 +473,7 @@ export class Org extends LiteElement {
></btrix-archived-item-qa>`; ></btrix-archived-item-qa>`;
} }
return html` <btrix-archived-item-detail return html`<btrix-archived-item-detail
crawlId=${params.itemId} crawlId=${params.itemId}
collectionId=${params.collectionId || ""} collectionId=${params.collectionId || ""}
workflowId=${params.workflowId || ""} workflowId=${params.workflowId || ""}