From dcb72a8e136c9323ad6fb2929d069cac97dc7490 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Fri, 15 Apr 2022 12:33:34 -0400 Subject: [PATCH] adds name of page into title of tab in browser --- app/client/models/DocPageModel.ts | 6 ++++++ app/client/ui/AppUI.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/client/models/DocPageModel.ts b/app/client/models/DocPageModel.ts index bb397c74..1431870e 100644 --- a/app/client/models/DocPageModel.ts +++ b/app/client/models/DocPageModel.ts @@ -53,6 +53,7 @@ export interface DocPageModel { currentOrg: Observable; currentOrgName: Observable; currentDocTitle: Observable; + currentDocPageName: Observable; isReadonly: Observable; isPrefork: Observable; isFork: Observable; @@ -93,6 +94,7 @@ export class DocPageModelImpl extends Disposable implements DocPageModel { public readonly currentOrgName = Computed.create(this, this.currentOrg, (use, org) => getOrgNameOrGuest(org, this.appModel.currentUser)); public readonly currentDocTitle = Computed.create(this, this.currentDoc, (use, doc) => doc ? doc.name : ''); + public readonly currentDocPageName = Observable.create(this, ''); public readonly isReadonly = Computed.create(this, this.currentDoc, (use, doc) => doc ? doc.isReadonly : false); public readonly isPrefork = Computed.create(this, this.currentDoc, (use, doc) => doc ? doc.isPreFork : false); public readonly isFork = Computed.create(this, this.currentDoc, (use, doc) => doc ? doc.isFork : false); @@ -134,6 +136,7 @@ export class DocPageModelImpl extends Disposable implements DocPageModel { this._openerDocKey = docKey; this.gristDoc.set(null); this.currentDoc.set(null); + this.currentDocPageName.set(''); this.undoState.set(null); if (!urlId) { this._openerHolder.clear(); @@ -284,6 +287,9 @@ export class DocPageModelImpl extends Disposable implements DocPageModel { // Move ownership of docComm to GristDoc. gristDoc.autoDispose(flow.release(docComm)); + gristDoc.autoDispose(subscribe(gristDoc.currentPageName, (use, pageName) => { + this.currentDocPageName.set(pageName); + })); // Move ownership of GristDoc to its final owner. this.gristDoc.autoDispose(flow.release(gristDoc)); diff --git a/app/client/ui/AppUI.ts b/app/client/ui/AppUI.ts index 629a28d1..d7651b5b 100644 --- a/app/client/ui/AppUI.ts +++ b/app/client/ui/AppUI.ts @@ -122,8 +122,12 @@ function pagePanelsDoc(owner: IDisposableOwner, appModel: AppModel, appObj: App) gristDoc ? RightPanel.create(use.owner, gristDoc, rightPanelOpen) : null); // Set document title to strings like "DocName - Grist" - owner.autoDispose(subscribe(pageModel.currentDocTitle, (use, docName) => { - document.title = `${docName} - Grist`; + owner.autoDispose(subscribe(pageModel.currentDocTitle, pageModel.currentDocPageName, (use, docName, pageName) => { + if (pageName) { + document.title = `${pageName} - ${docName} - Grist`; + } else { + document.title = `${docName} - Grist`; + } })); // Called after either panel is closed, opened, or resized.