Wait config before loading login/signup
authorChocobozzz <me@florianbigard.com>
Thu, 25 Apr 2019 08:40:01 +0000 (10:40 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 25 Apr 2019 08:40:01 +0000 (10:40 +0200)
client/src/app/core/core.module.ts
client/src/app/core/routing/server-config-resolver.service.ts [new file with mode: 0644]
client/src/app/login/login-routing.module.ts
client/src/app/signup/signup-routing.module.ts

index 4ef3b1e735dda920d20469332fd16171303a53dd..d3e72afb4d2ce6f71d19af408022e5e46b96c808 100644 (file)
@@ -19,6 +19,7 @@ import { ToastModule } from 'primeng/toast'
 import { Notifier } from './notification'
 import { MessageService } from 'primeng/api'
 import { UserNotificationSocket } from '@app/core/notification/user-notification-socket.service'
+import { ServerConfigResolver } from './routing/server-config-resolver.service'
 
 @NgModule({
   imports: [
@@ -60,7 +61,8 @@ import { UserNotificationSocket } from '@app/core/notification/user-notification
     RedirectService,
     Notifier,
     MessageService,
-    UserNotificationSocket
+    UserNotificationSocket,
+    ServerConfigResolver
   ]
 })
 export class CoreModule {
diff --git a/client/src/app/core/routing/server-config-resolver.service.ts b/client/src/app/core/routing/server-config-resolver.service.ts
new file mode 100644 (file)
index 0000000..ec7d642
--- /dev/null
@@ -0,0 +1,17 @@
+import { Injectable } from '@angular/core'
+import { Resolve } from '@angular/router'
+import { ServerService } from '@app/core/server'
+
+@Injectable()
+export class ServerConfigResolver implements Resolve<boolean> {
+  constructor (
+    private server: ServerService
+  ) {}
+
+  resolve () {
+    // FIXME: directly returning this.server.configLoaded does not seem to work
+    return new Promise<boolean>(res => {
+      return this.server.configLoaded.subscribe(() => res(true))
+    })
+  }
+}
index 4d89130418526c72cd99f8296228dc08e6715c7e..5a41f4e7eeb460a11da3568916b3fa1e2ffaf3fd 100644 (file)
@@ -1,9 +1,8 @@
 import { NgModule } from '@angular/core'
 import { RouterModule, Routes } from '@angular/router'
-
 import { MetaGuard } from '@ngx-meta/core'
-
 import { LoginComponent } from './login.component'
+import { ServerConfigResolver } from '@app/core/routing/server-config-resolver.service'
 
 const loginRoutes: Routes = [
   {
@@ -14,6 +13,9 @@ const loginRoutes: Routes = [
       meta: {
         title: 'Login'
       }
+    },
+    resolve: {
+      serverConfigLoaded: ServerConfigResolver
     }
   }
 ]
index b7ac69b535e909ce326883460a0e18277306b7f5..820d16d4d7f7b1af6fae0ba3e30ee0789a66964d 100644 (file)
@@ -1,9 +1,8 @@
 import { NgModule } from '@angular/core'
 import { RouterModule, Routes } from '@angular/router'
-
 import { MetaGuard } from '@ngx-meta/core'
-
 import { SignupComponent } from './signup.component'
+import { ServerConfigResolver } from '@app/core/routing/server-config-resolver.service'
 
 const signupRoutes: Routes = [
   {
@@ -14,6 +13,9 @@ const signupRoutes: Routes = [
       meta: {
         title: 'Signup'
       }
+    },
+    resolve: {
+      serverConfigLoaded: ServerConfigResolver
     }
   }
 ]