Skip to content

Commit

Permalink
Update routing to direct to /home
Browse files Browse the repository at this point in the history
  • Loading branch information
limcaaarl committed Nov 1, 2024
1 parent 0d02d28 commit bf6dd5e
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 75 deletions.
Binary file removed frontend/public/coding_image.png
Binary file not shown.
1 change: 0 additions & 1 deletion frontend/public/pair-programming-animate.svg

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/_services/collab.guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CollabGuardService implements CanActivate {
return combineLatest([roomId$, user$]).pipe(
switchMap(([roomId, user]) => {
if (!roomId || !user) {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
return of(false);
}

Expand All @@ -33,13 +33,13 @@ export class CollabGuardService implements CanActivate {
const isForfeit = response.data.users.find(roomUser => roomUser?.id === user.id)?.isForfeit;

if (!isFound || !isOpen || isForfeit) {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
return false;
}
return true;
}),
catchError(() => {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
return of(false);
}),
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/account/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class LoginComponent {
) {
//redirect to home if already logged in
if (this.authenticationService.userValue) {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
}
}

Expand All @@ -44,7 +44,7 @@ export class LoginComponent {
// authenticationService returns an observable that we can subscribe to
this.authenticationService.login(this.userForm.username, this.userForm.password).subscribe({
next: () => {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
},
error: error => {
this.isProcessingLogin = false;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/account/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class RegisterComponent {
) {
// redirect to home if already logged in
if (this.authenticationService.userValue) {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ export class RegisterComponent {
.pipe()
.subscribe({
next: () => {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
},
// error handling for registration because we assume there will be no errors with auto login
error: error => {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ export const routes: Routes = [
component: HomeComponent,
canActivate: [AuthGuardService],
},
{
path: '**',
redirectTo: '/home',
},
{
path: '',
redirectTo: '/home',
pathMatch: 'full',
},
];
2 changes: 1 addition & 1 deletion frontend/src/app/collaboration/collaboration.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class CollaborationComponent implements OnInit, OnDestroy {
this.wsProvider.ws!.onclose = (event: { code: number; reason: string }) => {
if (event.code === WebSocketCode.AUTH_FAILED || event.code === WebSocketCode.ROOM_CLOSED) {
console.error('WebSocket authorization failed:', event.reason);
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ForfeitDialogComponent implements OnInit {
this.isForfeit = true;
this.hideButtons = true;
setTimeout(() => {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
}, 1500);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export class SubmitDialogComponent implements AfterViewInit {
next: () => {
this.message = 'Successfully submitted. \n\n Redirecting you to homepage...';
setTimeout(() => {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
}, 1500);
},
});
}

setTimeout(() => {
this.router.navigate(['/matching']);
this.router.navigate(['/home']);
}, 1500);
}

Expand Down
92 changes: 46 additions & 46 deletions frontend/src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,62 @@ <h1 class="title">Welcome to PeerPrep!</h1>
<div class="col-12 container p-2">
<p-table
[value]="activeSessions"
[alwaysShowPaginator]="false"
[paginator]="true"
[rows]="5"
[rowsPerPageOptions]="[5, 10, 20]"
class="w-full">
<ng-template pTemplate="caption">
<div class="flex">
<h3 class="m-0">Active Sessions</h3>
</div>
</ng-template>
<!-- @if (activeSessions.length > 0) { -->
<ng-template pTemplate="header">
<tr>
<th style="width: 35%">Question</th>
<th style="width: 20%">Difficulty</th>
<th style="width: 20%">Peer</th>
<th style="width: 25%"></th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-session>
<tr>
<td>{{ session.question.title }}</td>
<td>
@switch (session.question.difficulty) {
@case (difficultyLevels.EASY) {
<p-chip class="easy-chip"> {{ session.question.difficulty }} </p-chip>
}
@case (difficultyLevels.MEDIUM) {
<p-chip class="medium-chip"> {{ session.question.difficulty }} </p-chip>
}
@case (difficultyLevels.HARD) {
<p-chip class="hard-chip"> {{ session.question.difficulty }} </p-chip>
@if (activeSessions.length > 0) {
<ng-template pTemplate="header">
<tr>
<th style="width: 35%">Question</th>
<th style="width: 20%">Difficulty</th>
<th style="width: 20%">Peer</th>
<th style="width: 25%"></th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-session>
<tr>
<td>{{ session.question.title }}</td>
<td>
@switch (session.question.difficulty) {
@case (difficultyLevels.EASY) {
<p-chip class="easy-chip"> {{ session.question.difficulty }} </p-chip>
}
@case (difficultyLevels.MEDIUM) {
<p-chip class="medium-chip"> {{ session.question.difficulty }} </p-chip>
}
@case (difficultyLevels.HARD) {
<p-chip class="hard-chip"> {{ session.question.difficulty }} </p-chip>
}
@default {
<p-chip class="easy-chip"> {{ session.question.difficulty }} </p-chip>
}
}
@default {
<p-chip class="easy-chip"> {{ session.question.difficulty }} </p-chip>
}
}
</td>
<td>{{ getPeer(session.users) }}</td>
<td>
<p-button
label="Join"
severity="success"
[outlined]="true"
styleClass="w-full"
[text]="true"
(onClick)="goToCollab(session.room_id)" />
</td>
</tr>
</ng-template>
</td>
<td>{{ getPeer(session.users) }}</td>
<td>
<p-button
label="Join"
severity="success"
[outlined]="true"
styleClass="w-full"
[text]="true"
(onClick)="goToCollab(session.room_id)" />
</td>
</tr>
</ng-template>
}
<ng-template pTemplate="footer">
<div class="flex flex-column w-full align-items-center justify-content-center px-4 pb-2">
@if (activeSessions.length === 0) {
<div>
<p>You currently have no active sessions.</p>
</div>
}
<div class="flex flex-column w-full align-items-center justify-content-center px-4 pb-0 pt-2">
<!-- @if (activeSessions.length === 0) { -->
<div>
<p>You currently have no active sessions.</p>
</div>
</div>
</ng-template>
</p-table>
Expand Down
32 changes: 16 additions & 16 deletions frontend/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ export class HomeComponent implements OnInit {
}

getActiveSessions() {
this.collabService.getRoomsWithQuery(true).subscribe({
next: response => {
this.activeSessions = response.data;
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Error',
detail: 'Failed to retrieve room data',
life: 3000,
});
},
complete: () => {
this.loading = false;
},
});
// this.collabService.getRoomsWithQuery(true).subscribe({
// next: response => {
// this.activeSessions = response.data;
// },
// error: () => {
// this.messageService.add({
// severity: 'error',
// summary: 'Error',
// detail: 'Failed to retrieve room data',
// life: 3000,
// });
// },
// complete: () => {
// this.loading = false;
// },
// });
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p-menubar>
<ng-template pTemplate="start">
<div class="pl-2 flex align-items-center" style="cursor: pointer" [routerLink]="['/matching']">
<div class="pl-2 flex align-items-center" style="cursor: pointer" [routerLink]="['/home']">
<img src="/logo.png" alt="logo" style="width: auto; height: 35px" />
<p class="pl-2 mr-3 poppins-bold logo-font-size">PeerPrep</p>
</div>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/navigation-bar/navigation-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export class NavigationBarComponent implements OnInit {
setMenuItems() {
if (this.authService.isLoggedIn) {
this.items = [
{
label: 'Home',
icon: 'pi pi-home',
routerLink: '/home',
class: 'p-submenu-list',
},
{
label: 'Find Match',
icon: 'pi pi-users',
Expand Down

0 comments on commit bf6dd5e

Please sign in to comment.