Skip to content

Commit a04cd68

Browse files
Add Navigation Bar (#48)
* Init nav bar component * Add navigation bar * Add logo * Fix spacing issue caused by nav bar * Update on login * Fix nav bar not updating on login * Add access to questions and matching * oops --------- Co-authored-by: Samuel Lim <[email protected]>
1 parent fa522fd commit a04cd68

13 files changed

+210
-31
lines changed

frontend/public/logo.png

125 KB
Loading

frontend/src/_services/authentication.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ export class AuthenticationService extends ApiService {
2121
) {
2222
super();
2323
const userData = localStorage.getItem('user');
24-
this.userSubject = new BehaviorSubject(userData ? JSON.parse(userData) : null);
24+
const user: User | null = userData ? JSON.parse(userData) : null;
25+
this.userSubject = new BehaviorSubject(user);
2526
this.user$ = this.userSubject.asObservable();
2627
}
2728

2829
public get userValue() {
2930
return this.userSubject.value;
3031
}
3132

33+
public get isLoggedIn(): boolean {
34+
return !!this.userSubject.value;
35+
}
36+
3237
login(username: string, password: string) {
33-
console.log('login', `${this.apiUrl}/auth/login`);
3438
return this.http
3539
.post<UServRes>(
3640
`${this.apiUrl}/auth/login`,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="flex flex-column h-full w-full justify-content-center align-items-center p-2">
1+
<div class="flex flex-column h-full w-full justify-content-center align-items-center p-2" style="margin-top: -80px">
22
<h2 class="mb-2">Welcome to PeerPrep</h2>
33
<router-outlet></router-outlet>
44
</div>

frontend/src/app/account/login.component.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { AuthenticationService } from '../../_services/authentication.service';
1313
selector: 'app-login',
1414
standalone: true,
1515
imports: [RouterLink, FormsModule, InputTextModule, ButtonModule, SelectButtonModule, PasswordModule, ToastModule],
16-
providers: [MessageService, AuthenticationService],
16+
providers: [MessageService],
1717
templateUrl: './login.component.html',
1818
styleUrl: './account.component.css',
1919
})
@@ -42,29 +42,26 @@ export class LoginComponent {
4242
this.isProcessingLogin = true;
4343

4444
// authenticationService returns an observable that we can subscribe to
45-
this.authenticationService
46-
.login(this.userForm.username, this.userForm.password)
47-
.pipe()
48-
.subscribe({
49-
next: () => {
50-
// get return url from route parameters or default to '/'
51-
const returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
52-
this.router.navigate([returnUrl]);
53-
},
54-
error: error => {
55-
this.isProcessingLogin = false;
56-
const status = error.cause.status;
57-
let errorMessage = 'An unknown error occurred';
58-
if (status === 400) {
59-
errorMessage = 'Missing Fields';
60-
} else if (status === 401) {
61-
errorMessage = 'Invalid username or password';
62-
} else if (status === 500) {
63-
errorMessage = 'Internal Server Error';
64-
}
65-
this.messageService.add({ severity: 'error', summary: 'Log In Error', detail: errorMessage });
66-
},
67-
});
45+
this.authenticationService.login(this.userForm.username, this.userForm.password).subscribe({
46+
next: () => {
47+
// get return url from route parameters or default to '/'
48+
const returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
49+
this.router.navigate([returnUrl]);
50+
},
51+
error: error => {
52+
this.isProcessingLogin = false;
53+
const status = error.cause.status;
54+
let errorMessage = 'An unknown error occurred';
55+
if (status === 400) {
56+
errorMessage = 'Missing Fields';
57+
} else if (status === 401) {
58+
errorMessage = 'Invalid username or password';
59+
} else if (status === 500) {
60+
errorMessage = 'Internal Server Error';
61+
}
62+
this.messageService.add({ severity: 'error', summary: 'Log In Error', detail: errorMessage });
63+
},
64+
});
6865
} else {
6966
console.log('Invalid form');
7067
}

frontend/src/app/account/register.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { AuthenticationService } from '../../_services/authentication.service';
2828
ToastModule,
2929
ReactiveFormsModule,
3030
],
31-
providers: [MessageService, AuthenticationService],
31+
providers: [MessageService],
3232
templateUrl: './register.component.html',
3333
styleUrl: './account.component.css',
3434
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
<app-navigation-bar />
2+
13
<router-outlet />

frontend/src/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Component } from '@angular/core';
22
import { RouterOutlet } from '@angular/router';
33
import { ButtonModule } from 'primeng/button';
44
import { PasswordModule } from 'primeng/password';
5+
import { NavigationBarComponent } from './navigation-bar/navigation-bar.component';
56

67
@Component({
78
selector: 'app-root',
89
standalone: true,
9-
imports: [RouterOutlet, ButtonModule, PasswordModule],
10+
imports: [NavigationBarComponent, RouterOutlet, ButtonModule, PasswordModule],
1011
templateUrl: './app.component.html',
1112
styleUrl: './app.component.css',
1213
})
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
::ng-deep .p-menubar {
2+
border-radius: 0;
3+
border-style: none;
4+
position: sticky;
5+
background-color: rgba(9, 9, 11, 0.8);
6+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
7+
top: 0;
8+
z-index: 100;
9+
backdrop-filter: blur(10px);
10+
justify-content: center;
11+
height: 80px;
12+
}
13+
14+
:host ::ng-deep p-menubarsub {
15+
width: 100%;
16+
}
17+
18+
::ng-deep .p-submenu-list {
19+
right: 0%;
20+
left: unset;
21+
}
22+
23+
a.fill-div {
24+
display: block;
25+
height: 100%;
26+
width: 100%;
27+
text-decoration: none;
28+
}
29+
30+
/* fonts */
31+
.poppins-thin {
32+
font-family: "Poppins", sans-serif;
33+
font-weight: 100;
34+
font-style: normal;
35+
}
36+
37+
.poppins-bold {
38+
font-family: "Poppins", sans-serif;
39+
font-weight: 700;
40+
font-style: normal;
41+
}
42+
43+
p.logo-font-size {
44+
font-size: 28px;
45+
}
46+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<link rel="preconnect" href="https://fonts.googleapis.com" />
2+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
3+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;700&display=swap" rel="stylesheet" />
4+
5+
<p-menubar [model]="items">
6+
<ng-template pTemplate="start">
7+
<div class="pl-2 flex align-items-center" style="cursor: pointer" [routerLink]="['/matching']">
8+
<img src="/logo.png" alt="logo" style="width: auto; height: 55px" />
9+
<p class="pl-2 mr-3 poppins-bold logo-font-size">PeerPrep</p>
10+
</div>
11+
</ng-template>
12+
<ng-template pTemplate="item" let-item>
13+
<a [routerLink]="item.route" class="p-menuitem-link">
14+
<span [class]="item.icon"></span>
15+
<span class="ml-2">{{ item.label }}</span>
16+
</a>
17+
</ng-template>
18+
</p-menubar>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { NavigationBarComponent } from './navigation-bar.component';
4+
5+
describe('NavigationBarComponent', () => {
6+
let component: NavigationBarComponent;
7+
let fixture: ComponentFixture<NavigationBarComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [NavigationBarComponent],
12+
}).compileComponents();
13+
14+
fixture = TestBed.createComponent(NavigationBarComponent);
15+
component = fixture.componentInstance;
16+
fixture.detectChanges();
17+
});
18+
19+
it('should create', () => {
20+
expect(component).toBeTruthy();
21+
});
22+
});

0 commit comments

Comments
 (0)