Let users switch scouting app tabs when on tabs without data entry

I was getting annoyed constantly clicking OK when switching from Match
List to Data Entry even though there's no possible data loss. This
patch makes it so switching away from Match List no longer creates a
popup. I also added this behaviour for Import Match List because the
only thing users enter there is the event code. That's nothing to
worry about in terms of data loss.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I76ffdce5ddefed96518fd32b40587d58e2d97127
diff --git a/scouting/www/app.ts b/scouting/www/app.ts
index 85620f1..ab9c229 100644
--- a/scouting/www/app.ts
+++ b/scouting/www/app.ts
@@ -6,6 +6,10 @@
   | 'Entry'
   | 'ImportMatchList'
   | 'ShiftSchedule';
+
+// Ignore the guard for tabs that don't require the user to enter any data.
+const unguardedTabs: Tab[] = ['MatchList', 'ImportMatchList'];
+
 type TeamInMatch = {
   teamNumber: number;
   matchNumber: number;
@@ -29,12 +33,14 @@
 
   constructor() {
     window.addEventListener('beforeunload', (e) => {
-      if (!this.block_alerts.nativeElement.checked) {
-        // Based on
-        // https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#example
-        // This combination ensures a dialog will be shown on most browsers.
-        e.preventDefault();
-        e.returnValue = '';
+      if (!unguardedTabs.includes(this.tab)) {
+        if (!this.block_alerts.nativeElement.checked) {
+          // Based on
+          // https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#example
+          // This combination ensures a dialog will be shown on most browsers.
+          e.preventDefault();
+          e.returnValue = '';
+        }
       }
     });
   }
@@ -51,8 +57,12 @@
   switchTabToGuarded(tab: Tab) {
     let shouldSwitch = true;
     if (this.tab !== tab) {
-      if (!this.block_alerts.nativeElement.checked) {
-        shouldSwitch = window.confirm('Leave current page?');
+      if (!unguardedTabs.includes(this.tab)) {
+        if (!this.block_alerts.nativeElement.checked) {
+          shouldSwitch = window.confirm(
+            'Leave current page? You will lose all data.'
+          );
+        }
       }
     }
     if (shouldSwitch) {