From 2072f9c1609d19de06e4af5318488469a8f6acb1 Mon Sep 17 00:00:00 2001
From: Midhun Suresh <midhunr@element.io>
Date: Sun, 30 Jan 2022 20:04:16 +0530
Subject: [PATCH] Move start button to parent

---
 src/main.ts                             | 12 ++++++++++--
 src/ui/views/AccountSetupView.ts        |  2 +-
 src/ui/views/ChatterboxView.ts          |  2 +-
 src/viewmodels/AccountSetupViewModel.ts |  4 ----
 src/viewmodels/ChatterboxViewModel.ts   |  4 ----
 src/viewmodels/RootViewModel.ts         |  8 +-------
 6 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/src/main.ts b/src/main.ts
index bbdb19d..8bb1326 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -41,6 +41,7 @@ async function main() {
     platform.setNavigation(navigation);
     const urlRouter = createRouter({ navigation, history: platform.history });
     const rootViewModel = new RootViewModel(config, {platform, navigation, urlCreator: urlRouter});
+    rootViewModel.start();
     const rootView = new RootView(rootViewModel);
     root.appendChild(rootView.mount());
 }
@@ -55,8 +56,15 @@ function allowsChild(parent, child) {
     }
 }
 
-(window as any).sendViewChangeToParent = function (view: "timeline" | "start" | "account-setup") {
-    window.parent?.postMessage(view);
+(window as any).sendViewChangeToParent = function (view: "timeline" | "account-setup") {
+    window.parent?.postMessage({
+        action: "resize-iframe",
+        view
+    });
+};
+
+(window as any).sendMinimizeToParent = function () {
+    window.parent?.postMessage({ action: "minimize" });
 };
 
 main();
diff --git a/src/ui/views/AccountSetupView.ts b/src/ui/views/AccountSetupView.ts
index 4b76ccb..9586fa4 100644
--- a/src/ui/views/AccountSetupView.ts
+++ b/src/ui/views/AccountSetupView.ts
@@ -29,7 +29,7 @@ class PolicyAgreementView extends TemplateView<AccountSetupViewModel> {
             t.div(
                 { className: "PolicyAgreementView-btn-collection" },
                 [
-                t.button( { onClick: () => vm.dismiss(), className: "button-action secondary PolicyAgreementView-cancel", }, "Cancel"),
+                t.button( { onClick: () => (window as any).sendMinimizeToParent(), className: "button-action secondary PolicyAgreementView-cancel", }, "Cancel"),
                 t.button( { onClick: () => vm.completeRegistration(), className: "PolicyAgreementView-next button-action primary", }, "Next")
                 ]),
         ]);
diff --git a/src/ui/views/ChatterboxView.ts b/src/ui/views/ChatterboxView.ts
index 584b09e..b188ef1 100644
--- a/src/ui/views/ChatterboxView.ts
+++ b/src/ui/views/ChatterboxView.ts
@@ -39,7 +39,7 @@ class RoomHeaderView extends TemplateView<ChatterboxViewModel> {
             t.view(new AvatarView(vm.roomViewModel, 30)),
             t.div({ className: "RoomHeaderView_name" }, vm => vm.roomViewModel.name),
             t.div({ className: "RoomHeaderView_menu" }, [
-                t.button({ className: "RoomHeaderView_menu_minimize", onClick: () => vm.minimize() })
+                t.button({ className: "RoomHeaderView_menu_minimize", onClick: () => (window as any).sendMinimizeToParent() })
             ]),
         ]);
     }
diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts
index c43b47b..a774c1f 100644
--- a/src/viewmodels/AccountSetupViewModel.ts
+++ b/src/viewmodels/AccountSetupViewModel.ts
@@ -64,10 +64,6 @@ export class AccountSetupViewModel extends ViewModel {
         }
     }
 
-    dismiss() {
-        this.navigation.push("start");
-    }
-
     private get _homeserver(): string {
         return this._config.homeserver;
     }
diff --git a/src/viewmodels/ChatterboxViewModel.ts b/src/viewmodels/ChatterboxViewModel.ts
index 0241eb2..e1d52e8 100644
--- a/src/viewmodels/ChatterboxViewModel.ts
+++ b/src/viewmodels/ChatterboxViewModel.ts
@@ -51,10 +51,6 @@ export class ChatterboxViewModel extends ViewModel {
         return promise;
     }
 
-    minimize() {
-        this.navigation.push("start");
-    }
-
     get timelineViewModel() {
         return this._roomViewModel?.timelineViewModel;
     }
diff --git a/src/viewmodels/RootViewModel.ts b/src/viewmodels/RootViewModel.ts
index 5f63909..1207148 100644
--- a/src/viewmodels/RootViewModel.ts
+++ b/src/viewmodels/RootViewModel.ts
@@ -11,7 +11,7 @@ export class RootViewModel extends ViewModel {
     private _client: typeof Client;
     private _chatterBoxViewModel?: ChatterboxViewModel;
     private _accountSetupViewModel?: AccountSetupViewModel;
-    private _activeSection: string = "start";
+    private _activeSection?: string;
 
     constructor(config: IChatterboxConfig, options: Options) {
         super(options);
@@ -23,7 +23,6 @@ export class RootViewModel extends ViewModel {
     private _setupNavigation() {
         this.navigation.observe("account-setup").subscribe(() => this._showAccountSetup());
         this.navigation.observe("timeline").subscribe((loginPromise) => this._showTimeline(loginPromise));
-        this.navigation.observe("start").subscribe(() => this._showStartButton());
     }
 
     async start() {
@@ -63,11 +62,6 @@ export class RootViewModel extends ViewModel {
         this.emitChange("activeSection");
     }
 
-    private _showStartButton() {
-        this._activeSection = "start";
-        this.emitChange("activeSection");
-    }
-
     /**
      * Try to start Hydrogen based on an existing hydrogen session.
      * If multiple sessions exist, this method chooses the most recent one.
-- 
GitLab