@@ -4,9 +4,6 @@ import Config, * as UpdateConfig from "../config";
44import * as Misc from "../utils/misc" ;
55import * as DB from "../db" ;
66import * as Loader from "../elements/loader" ;
7- import * as PageTransition from "../states/page-transition" ;
8- import * as ActivePage from "../states/active-page" ;
9- import * as LoadingPage from "../pages/loading" ;
107import * as LoginPage from "../pages/login" ;
118import * as RegisterCaptchaModal from "../modals/register-captcha" ;
129import * as Account from "../pages/account" ;
@@ -65,13 +62,6 @@ async function sendVerificationEmail(): Promise<void> {
6562async function getDataAndInit ( ) : Promise < boolean > {
6663 try {
6764 console . log ( "getting account data" ) ;
68- if ( window . location . pathname !== "/account" ) {
69- LoadingPage . updateBar ( 90 ) ;
70- } else {
71- LoadingPage . updateBar ( 45 ) ;
72- }
73- LoadingPage . updateText ( "Downloading user data..." ) ;
74- await LoadingPage . showBar ( ) ;
7565 const snapshot = await DB . initSnapshot ( ) ;
7666
7767 if ( snapshot === false ) {
@@ -91,12 +81,6 @@ async function getDataAndInit(): Promise<boolean> {
9181 true
9282 ) ;
9383 }
94- if ( ActivePage . get ( ) === "loading" ) {
95- LoadingPage . updateBar ( 100 ) ;
96- } else {
97- LoadingPage . updateBar ( 45 ) ;
98- }
99- LoadingPage . updateText ( "Applying settings..." ) ;
10084
10185 const areConfigsEqual =
10286 JSON . stringify ( Config ) === JSON . stringify ( snapshot . config ) ;
@@ -114,14 +98,8 @@ async function getDataAndInit(): Promise<boolean> {
11498 }
11599 }
116100 if ( window . location . pathname === "/account" ) {
117- LoadingPage . updateBar ( 90 ) ;
118101 await Account . downloadResults ( ) ;
119102 }
120- if ( window . location . pathname === "/login" ) {
121- navigate ( "/account" ) ;
122- } else {
123- navigate ( ) ;
124- }
125103 return true ;
126104 } catch ( error ) {
127105 console . error ( error ) ;
@@ -155,56 +133,76 @@ async function getDataAndInit(): Promise<boolean> {
155133}
156134
157135export async function loadUser ( _user : UserType ) : Promise < void > {
158- // User is signed in.
159- PageTransition . set ( false ) ;
160136 if ( ! ( await getDataAndInit ( ) ) ) {
161137 signOut ( ) ;
138+ return ;
162139 }
163-
164140 AuthEvent . dispatch ( { type : "snapshotUpdated" , data : { isInitial : true } } ) ;
165-
166- // var displayName = user.displayName;
167- // var email = user.email;
168- // var emailVerified = user.emailVerified;
169- // var photoURL = user.photoURL;
170- // var isAnonymous = user.isAnonymous;
171- // var uid = user.uid;
172- // var providerData = user.providerData;
173- LoginPage . hidePreloader ( ) ;
174-
175- // showFavouriteThemesAtTheTop();
176141}
177142
178143export async function onAuthStateChanged (
179144 authInitialisedAndConnected : boolean ,
180145 user : UserType | null
181146) : Promise < void > {
182147 console . debug ( `account controller ready` ) ;
148+
149+ let userPromise : Promise < void > = Promise . resolve ( ) ;
150+
183151 if ( authInitialisedAndConnected ) {
184152 console . debug ( `auth state changed, user ${ user ? "true" : "false" } ` ) ;
185153 console . debug ( user ) ;
186154 if ( user ) {
187- await loadUser ( user ) ;
155+ userPromise = loadUser ( user ) ;
188156 } else {
189- if ( window . location . pathname === "/account" ) {
190- window . history . replaceState ( "" , "" , "/login" ) ;
191- }
192-
193157 DB . setSnapshot ( undefined ) ;
194- Sentry . clearUser ( ) ;
195- PageTransition . set ( false ) ;
196- navigate ( ) ;
197- }
198- } else {
199- console . debug ( `auth not initialised or not connected` ) ;
200- if ( window . location . pathname === "/account" ) {
201- window . history . replaceState ( "" , "" , "/login" ) ;
202158 }
159+ }
160+
161+ if ( ! authInitialisedAndConnected || ! user ) {
203162 Sentry . clearUser ( ) ;
204- PageTransition . set ( false ) ;
205- navigate ( ) ;
206163 }
207164
165+ let keyframes = [
166+ {
167+ percentage : 90 ,
168+ durationMs : 1000 ,
169+ text : "Downloading user data..." ,
170+ } ,
171+ ] ;
172+
173+ if (
174+ window . location . pathname === "/account" ||
175+ window . location . pathname === "/login"
176+ ) {
177+ keyframes = [
178+ {
179+ percentage : 40 ,
180+ durationMs : 1000 ,
181+ text : "Downloading user data..." ,
182+ } ,
183+ {
184+ percentage : 90 ,
185+ durationMs : 1000 ,
186+ text : "Downloading results..." ,
187+ } ,
188+ ] ;
189+ }
190+
191+ //undefined means navigate to whatever the current window.location.pathname is
192+ await navigate ( undefined , {
193+ force : true ,
194+ overrideLoadingOptions : {
195+ shouldLoad : ( ) => {
196+ return user !== null ;
197+ } ,
198+ waitFor : async ( ) => {
199+ await userPromise ;
200+ } ,
201+ style : "bar" ,
202+ keyframes : keyframes ,
203+ } ,
204+ } ) ;
205+
208206 AuthEvent . dispatch ( {
209207 type : "authStateChanged" ,
210208 data : { isUserSignedIn : user !== null } ,
0 commit comments