Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(front): remove /profile page, always use /profile/{userID} #850

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/frontend/src/app/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export class HeaderComponent implements OnInit, OnDestroy {
userMenu: NbMenuItem[] = [
{
title: 'Profile',
link: '/dashboard/profile'
// If `user` hasn't been fetched yet, just navigate to ProfileRedirect
// component, which will await the user result then redirect to relatived URL.
link: this.user?.id
? `/dashboard/profile/${this.user.id}`
: '/dashboard/profile'
},
{
title: 'Edit Profile',
Expand All @@ -29,7 +33,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
}
];

user: User;
user?: User;
notifications: Notification[];
numUnreadNotifs: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ export class ProfileEditComponent implements OnInit, OnDestroy {
}

returnToProfile() {
this.router.navigate([
`/dashboard/profile${this.isLocal ? '' : '/' + this.user.id}`
]);
this.router.navigate([`/dashboard/profile/${this.user.id}`]);
}

deleteUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { LocalUserService } from '@momentum/frontend/data';
import { firstValueFrom } from 'rxjs';

/**
* Redirects `/profile` to `/profile/<logged-in-ID>` if has a logged in user,
* otherwise to home page.
*/
@Component({ selector: 'mom-profile-redirect-local', template: '' })
export class ProfileRedirectComponent implements OnInit {
constructor(
private readonly router: Router,
private readonly localUserService: LocalUserService
) {}

async ngOnInit(): Promise<void> {
const localUser = await firstValueFrom(this.localUserService.getLocal());

await this.router.navigate([
localUser?.id ? `/dashboard/profile/${localUser.id}` : '/dashboard'
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NotFoundDashboardComponent } from '../../not-found/dashboard/not-found-
import { NgModule } from '@angular/core';
import { ProfileComponent } from './profile.component';
import { Role } from '@momentum/constants';
import { ProfileRedirectComponent } from './profile-redirect.component';

@NgModule({
imports: [
Expand All @@ -25,7 +26,7 @@ import { Role } from '@momentum/constants';
}
]
},
{ path: '', component: UserProfileComponent },
{ path: '', component: ProfileRedirectComponent },
{ path: '**', component: NotFoundDashboardComponent }
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { ProfileRoutingModule } from './profile-routing.module';
import { ProfileComponent } from './profile.component';
import { ProfileNotifyEditComponent } from './profile-follow/profile-notify-edit/profile-notify-edit.component';
import { SharedModule } from '../../../shared.module';
import { ProfileRedirectComponent } from './profile-redirect.component';

@NgModule({
imports: [SharedModule, ProfileRoutingModule],
declarations: [
ProfileComponent,
ProfileRedirectComponent,
UserProfileComponent,
ProfileEditComponent,
ProfileFollowComponent,
Expand Down