From 14d9afcc78992d20752f848e29d07f1716d4d085 Mon Sep 17 00:00:00 2001
From: RMidhunSuresh <hi@midhun.dev>
Date: Tue, 5 Jul 2022 15:45:27 +0530
Subject: [PATCH] Render loader when waiting

---
 src/ui/views/AccountSetupView.ts        | 4 +++-
 src/viewmodels/AccountSetupViewModel.ts | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/ui/views/AccountSetupView.ts b/src/ui/views/AccountSetupView.ts
index 4d9d7b2..1010612 100644
--- a/src/ui/views/AccountSetupView.ts
+++ b/src/ui/views/AccountSetupView.ts
@@ -35,7 +35,9 @@ class PolicyAgreementView extends TemplateView<AccountSetupViewModel> {
                 ]),
             t.div({ className: "PolicyAgreementView_btn-collection" },
                 [
-                    t.button({ onClick: () => vm.completeRegistration(), className: "PolicyAgreementView_next", }, "Accept and continue to chat"),
+                    t.button({ onClick: () => vm.completeRegistration(), className: "PolicyAgreementView_next", },
+                        t.map(vm => vm.showButtonSpinner, (showButtonSpinner, t) => showButtonSpinner? t.div({ className: "loader" }): t.span("Accept and continue to chat"))
+                    ),
                     t.button({ onClick: () => vm.minimize(), className: "button-action PolicyAgreementView_cancel", }, "Cancel"),
                 ]),
         ]);
diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts
index 3e83fa8..6284729 100644
--- a/src/viewmodels/AccountSetupViewModel.ts
+++ b/src/viewmodels/AccountSetupViewModel.ts
@@ -11,6 +11,7 @@ export class AccountSetupViewModel extends ViewModel {
     private _password: string;
     private _registration: any;
     private _privacyPolicyLink: string;
+    private _showButtonSpinner: boolean = false;
 
     constructor(options) {
         super(options);
@@ -66,6 +67,8 @@ export class AccountSetupViewModel extends ViewModel {
     }
 
     async completeRegistration() {
+        this._showButtonSpinner = true;
+        this.emitChange("showButtonSpinner");
         let stage = this._startStage;
         while (stage) {
             if (
@@ -113,4 +116,8 @@ export class AccountSetupViewModel extends ViewModel {
     get footerViewModel() {
         return this.options.footerVM;
     }
+
+    get showButtonSpinner(): boolean {
+        return this._showButtonSpinner;
+    }
 }
-- 
GitLab