From d485014435c5dcdb26f8a1e56ecf66cdd6a14186 Mon Sep 17 00:00:00 2001
From: Segi Hovav <shovav@gms4sbc.com>
Date: Thu, 16 Dec 2021 16:47:56 -0800
Subject: [PATCH] Fix bug that caused IMDB Search tab to not appear in mobile
 app due to not getting the IMDBSearchEnabled status at the right time due to
 timing issue. Fixed by getting status directly in backend service

---
 src/app/core/data.service.ts | 16 ++++++++++++++--
 src/app/tabs/tabs.page.html  |  2 +-
 src/app/tabs/tabs.page.ts    | 16 +---------------
 3 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/app/core/data.service.ts b/src/app/core/data.service.ts
index 22cfd57..f864ac0 100644
--- a/src/app/core/data.service.ts
+++ b/src/app/core/data.service.ts
@@ -18,6 +18,7 @@ export class DataService {
      incompleteFilter = true;
      isAdding = false;
      isEditing = false;
+     isIMDBSearchEnabled = false;
      isMobilePlatform = false;
      platform: Platform;
      recordLimit = 10;
@@ -175,6 +176,8 @@ export class DataService {
           this.backendURL = await this.storage.get('BackEndURL');
           
           if (this.backendURL != null && this.backendURL != "") {
+               this.getIMDBSearchEnabledSubscription();
+
                this.getWatchListItemsSubscription(false);
 
                this.getWatchListSubscription();
@@ -365,14 +368,23 @@ export class DataService {
           }
 
           return throwError(error || 'Node.js server error');
-     }
+     }     
 
      isBackendURLSet() {
           return (this.backendURL != null && this.backendURL != '' ? true : false)
      }
 
-     isIMDBSearchEnabled() {
+     getIMDBSearchEnabled() {
           return this.processStep(`/IsIMDBSearchEnabled`,null);
+     }     
+
+     getIMDBSearchEnabledSubscription() {
+          this.getIMDBSearchEnabled().subscribe((response) => {
+               this.isIMDBSearchEnabled=response;
+          },
+          error => {
+               this.handleError(error);
+          });
      }
 
      processStep(path: string, params: HttpParams): Observable<any> {
diff --git a/src/app/tabs/tabs.page.html b/src/app/tabs/tabs.page.html
index 0f70c29..9c8e08d 100644
--- a/src/app/tabs/tabs.page.html
+++ b/src/app/tabs/tabs.page.html
@@ -15,7 +15,7 @@
                <ion-label>Watchlist Queue</ion-label>
           </ion-tab-button>
 
-          <ion-tab-button tab="imdb-search" *ngIf="IMDBSearchEnabled != false">
+          <ion-tab-button tab="imdb-search" *ngIf="dataService.isIMDBSearchEnabled">
                <!-- <ion-icon name="ellipse"></ion-icon> -->
                <ion-label>IMDB Search</ion-label>
           </ion-tab-button>
diff --git a/src/app/tabs/tabs.page.ts b/src/app/tabs/tabs.page.ts
index dddee59..fff6f35 100644
--- a/src/app/tabs/tabs.page.ts
+++ b/src/app/tabs/tabs.page.ts
@@ -8,19 +8,5 @@ import { DataService } from '../core/data.service';
 })
 
 export class TabsPage {
-     IMDBSearchEnabled = false;
-
-     constructor(public dataService: DataService) {
-          if (this.dataService.isBackendURLSet())
-               this.getIMDBSearchEnabled()
-      }
-
-      getIMDBSearchEnabled() {
-          this.dataService.isIMDBSearchEnabled().subscribe((response) => {
-               this.IMDBSearchEnabled=response;
-          },
-          error => {
-               alert(`The error ${error.error.toString()} occurred calling isIMDBSearchEnabled() in TabsPage`)
-          });
-      }
+     constructor(public dataService: DataService) { }
 }