 ;; Init
 ;;------------------------------------------------------------------------------
 
-(defn- init!
-  "Initialize the Admin page."
-  []
-  ;; trigger the initial render
-  (swap! page-state identity))
+(def init!
+  "Initialize the Admin page.
+   NOTE: this function may only be called one time."
+  (once
+    (fn []
+      ;; do they have the password in localStorage?
+      (if-not (blank? (:password @page-state))
+        ;; attempt to login
+        (click-login-btn nil)
+        ;; else trigger an initial render
+        (swap! page-state identity)))))
 
 (init!)

(defn- compare-team-name [[teamA-id teamA] [teamB-id teamB]]
  (compare (:name teamA) (:name teamB)))

;; TODO: use a faster component for team selection than a <select>
(rum/defc TeamSelect < rum/static
  [teams game-id game team-key]
  (let [sorted-teams (sort compare-team-name teams)]


(def initial-page-state
  {;; login related
   :logging-in? false
   :password ""
   :password-error? false
   :password-valid? false

   ;; GameTabs across the top
   :tab-id "swiss-round-1"
