Skip to content

Commit 32be7df

Browse files
Mutugiiidogi
andauthored
community: smoother center landing (fixes #9077) (#9204)
Co-authored-by: dogi <[email protected]>
1 parent d4b11cd commit 32be7df

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.50",
4+
"version": "0.20.51",
55
"myplanet": {
6-
"latest": "v0.34.54",
7-
"min": "v0.33.54"
6+
"latest": "v0.34.90",
7+
"min": "v0.33.90"
88
},
99
"scripts": {
1010
"ng": "ng",

src/app/home/home-router.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const routes: Routes = [
8181
{
8282
path: '',
8383
component: CommunityComponent,
84+
canActivate: [ AuthService.centerLandingGuard ],
8485
children: [ { path: 'voices/:id', component: NewsListComponent } ]
8586
},
8687
{

src/app/home/home.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class HomeComponent implements OnInit, DoCheck, AfterViewChecked, OnDestr
205205
catchError(errorCatch)
206206
).subscribe((response: any) => {
207207
this.userService.unset();
208-
this.router.navigate([ '/' ], {});
208+
this.router.navigate([ this.stateService.configuration.planetType === 'center' ? '/login' : '/' ], {});
209209
});
210210
}
211211

src/app/shared/auth-guard.service.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { UserService } from './user.service';
33
import { Observable, of } from 'rxjs';
44
import { switchMap, map } from 'rxjs/operators';
5-
import { Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
5+
import { Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateFn } from '@angular/router';
66
import { PouchAuthService } from './database/pouch-auth.service';
77
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
88
import { LoginDialogComponent } from '../login/login-dialog.component';
9+
import { StateService } from './state.service';
910

1011
@Injectable({
1112
providedIn: 'root'
@@ -16,7 +17,8 @@ export class AuthService {
1617
private userService: UserService,
1718
private router: Router,
1819
private pouchAuthService: PouchAuthService,
19-
private dialog: MatDialog
20+
private dialog: MatDialog,
21+
private stateService: StateService
2022
) { }
2123

2224
private getSession$() {
@@ -42,10 +44,10 @@ export class AuthService {
4244
return dialogRef.afterClosed().pipe(switchMap(loginState => {
4345
if (loginState === undefined) {
4446
// If the current routerState snapshot url is a blank string, the user got here via
45-
// directly pasting in a link to a guarded route. Need to reroute to the community page
47+
// directly pasting in a link to a guarded route. Need to reroute to the appropriate default page
4648
// before closing the dialog.
4749
if (this.router.routerState.snapshot.url === '') {
48-
this.router.navigate([ '/' ]);
50+
this.router.navigate([ this.stateService.configuration.planetType === 'center' ? '/login' : '/' ]);
4951
}
5052
return of(false);
5153
}
@@ -74,7 +76,7 @@ export class AuthService {
7476
return this.getSession$().pipe(
7577
map((sessionInfo) => {
7678
if (sessionInfo.userCtx.name) {
77-
this.router.navigate([ '' ]);
79+
this.router.navigate([ this.stateService.configuration.planetType === 'center' ? '/myDashboard' : '' ]);
7880
return false;
7981
}
8082
return true;
@@ -93,4 +95,16 @@ export class AuthService {
9395
);
9496
}
9597

98+
static centerLandingGuard: CanActivateFn = () => {
99+
const router = inject(Router);
100+
const stateService = inject(StateService);
101+
102+
// Only redirect on first navigation for center planets
103+
if (!router.navigated && stateService.configuration.planetType === 'center') {
104+
router.navigate(['/login']);
105+
return false;
106+
}
107+
return true;
108+
};
109+
96110
}

src/app/shared/state.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export class StateService {
1414
private inProgress = { local: new Map(), parent: new Map() };
1515

1616
get configuration(): any {
17-
const config = this.state.local.configurations.docs[0] || {};
17+
const config = this.state.local.configurations?.docs[0] || {};
1818
const { keys, ...safeConfig } = config;
1919
return safeConfig;
2020
}
2121

2222
get keys(): any {
23-
return this.state.local.configurations.docs[0]?.keys || {};
23+
return this.state.local.configurations?.docs[0]?.keys || {};
2424
}
2525

2626
constructor(

0 commit comments

Comments
 (0)