Skip to content

Commit 407d3e8

Browse files
committed
Working History page
Bugs fixed: Imported PInputText so editing profile page looks normal. The behaviour for 'Enter' to submit form is restored for profile page. Not Fixed: Linting.
1 parent 81dc5dc commit 407d3e8

File tree

10 files changed

+335
-313
lines changed

10 files changed

+335
-313
lines changed

compose.dev.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ services:
5252
ports:
5353
- 27020:27017
5454

55-
collaboration-db:
56-
ports:
57-
- 27020:27017
58-
5955
history:
6056
command: npm run dev
6157
ports:

frontend/src/_services/form.utils.service.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,43 @@ export class FormUtilsService {
3737
}
3838

3939
get passwordHasNoLowercase(): (form: FormGroup) => boolean {
40-
return (form: FormGroup) => this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_LOWERCASE);
40+
return (form: FormGroup) =>
41+
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_LOWERCASE);
4142
}
4243

4344
get passwordHasNoUppercase(): (form: FormGroup) => boolean {
44-
return (form: FormGroup) => this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_UPPERCASE);
45+
return (form: FormGroup) =>
46+
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_UPPERCASE);
4547
}
4648

4749
get passwordHasNoNumeric(): (form: FormGroup) => boolean {
48-
return (form: FormGroup) => this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_NUMERIC);
50+
return (form: FormGroup) =>
51+
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_NUMERIC);
4952
}
5053

5154
get passwordHasNoSpecial(): (form: FormGroup) => boolean {
52-
return (form: FormGroup) => this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_SPECIAL);
55+
return (form: FormGroup) =>
56+
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_SPECIAL);
5357
}
5458

5559
get isPasswordShort(): (form: FormGroup) => boolean {
56-
return (form: FormGroup) => this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_SHORT);
60+
return (form: FormGroup) =>
61+
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_SHORT);
5762
}
5863

5964
get isPasswordWeak(): (form: FormGroup) => boolean {
60-
return (form: FormGroup) => this.passwordControl(form).dirty && this.passwordControl(form).hasError(PASSWORD_WEAK);
65+
return (form: FormGroup) =>
66+
this.passwordControl(form).dirty && this.passwordControl(form).hasError(PASSWORD_WEAK);
6167
}
6268

6369
get isPasswordStrong(): (form: FormGroup) => boolean {
64-
return (form: FormGroup) => this.passwordControl(form).dirty && !this.passwordControl(form).hasError(PASSWORD_WEAK);
70+
return (form: FormGroup) =>
71+
this.passwordControl(form).dirty && !this.passwordControl(form).hasError(PASSWORD_WEAK);
6572
}
6673

6774
get isPasswordInvalid(): (form: FormGroup) => boolean {
68-
return (form: FormGroup) => this.passwordControl(form).dirty && this.passwordControl(form).hasError(PASSWORD_INVALID);
75+
return (form: FormGroup) =>
76+
this.passwordControl(form).dirty && this.passwordControl(form).hasError(PASSWORD_INVALID);
6977
}
7078

7179
get hasPasswordMismatch(): (form: FormGroup) => boolean {
@@ -74,4 +82,4 @@ export class FormUtilsService {
7482
return this.passwordControl(form).valid && confirmPasswordControl.dirty && form.hasError(PASSWORD_MISMATCH);
7583
};
7684
}
77-
}
85+
}

frontend/src/_services/history.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ export class HistoryService extends ApiService {
1616
}
1717

1818
getHistories(): Observable<MatchingHistory[]> {
19-
return this.http
20-
.get<{ status: string; message: string; data: any[] }>(`${this.apiUrl}`)
21-
.pipe(
22-
map(response => response.data.map(item => ({
19+
return this.http.get<{ status: string; message: string; data: any[] }>(`${this.apiUrl}`).pipe(
20+
map(response =>
21+
response.data.map(item => ({
2322
id: item._id,
2423
collaborator: item.collaborator.username,
2524
question: item.question.title,
2625
topics: item.question.topics,
2726
difficulty: item.question.difficulty,
2827
status: item.status,
2928
time: item.createdAt,
30-
})))
31-
);
29+
})),
30+
),
31+
);
3232
}
33-
}
33+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const routes: Routes = [
1616
{ path: 'login', component: LoginComponent },
1717
{ path: 'register', component: RegisterComponent },
1818
{ path: 'profile', component: ProfileComponent },
19-
{path: 'history', component: HistoryComponent},
19+
{ path: 'history', component: HistoryComponent },
2020
],
2121
},
2222
];

frontend/src/app/account/history/history.component.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ <h3 class="m-0">Matching History</h3>
3131
<td>{{ history.topics.join(', ') }}</td>
3232
<td>{{ history.collaborator }}</td>
3333
<td>
34-
<i *ngIf="history.status === 'COMPLETED'" class="pi pi-check" style="color: green;"></i>
35-
<i *ngIf="history.status === 'FORFEITED'" class="pi pi-times" style="color: red;"></i>
34+
@if (history.status === 'COMPLETED') {
35+
<i class="pi pi-check" style="color: green; font-size: large"></i>
36+
} @else if (history.status === 'FORFEITED') {
37+
<i class="pi pi-times" style="color: red; font-size: large"></i>
38+
} @else if (history.status === 'IN_PROGRESS') {
39+
<i class="pi pi-spin pi-spinner" style="color: white; font-size: large"></i>
40+
}
3641
</td>
37-
<td>{{ history.time | date:'short' }}</td>
42+
<td>{{ history.time | date: 'short' }}</td>
3843
</tr>
3944
</ng-template>
4045
</p-table>
41-
</div>
46+
</div>

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

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { MessageService } from 'primeng/api';
77

88
@Component({
99
standalone: true,
10-
imports: [
11-
TableModule,
12-
CommonModule,
13-
],
10+
imports: [TableModule, CommonModule],
1411
providers: [MessageService],
1512
templateUrl: './history.component.html',
1613
styleUrl: './history.component.css',
@@ -19,58 +16,27 @@ export class HistoryComponent implements OnInit {
1916
histories: MatchingHistory[] = [];
2017
loading = true;
2118

22-
dummyHistories: MatchingHistory[] = [
23-
{
24-
id: 1,
25-
collaborator: 'userabc',
26-
question: 'Roman to Integer',
27-
difficulty: 'Easy',
28-
topics: ['Algorithms', 'Data Structures', 'Strings', 'Arrays'],
29-
status: 'COMPLETED',
30-
time: '2024-10-31T09:26:01.743Z',
31-
},
32-
{
33-
id: 2,
34-
collaborator: 'userdef',
35-
question: 'Two Sum',
36-
difficulty: 'Medium',
37-
topics: ['Data Structures'],
38-
status: 'FORFEITED',
39-
time: '2024-11-01T10:15:30.123Z',
40-
},
41-
{
42-
id: 3,
43-
collaborator: 'userghi',
44-
question: 'Longest Substring Without Repeating Characters',
45-
difficulty: 'Hard',
46-
topics: ['Strings'],
47-
status: 'COMPLETED',
48-
time: '2023-11-02T11:45:00.789Z',
49-
},
50-
];
51-
5219
constructor(
5320
private historyService: HistoryService,
5421
private messageService: MessageService,
5522
) {}
5623

5724
ngOnInit() {
58-
this.histories = this.dummyHistories;
59-
// this.historyService.getHistories().subscribe({
60-
// next: (data) => {
61-
// this.histories = data;
62-
// this.loading = false;
63-
// },
64-
// error: () => {
65-
// this.histories = [];
66-
// this.loading = false;
67-
// this.messageService.add({
68-
// severity: 'error',
69-
// summary: 'Error',
70-
// detail: 'Failed to load data. Please try again later.',
71-
// life: 3000,
72-
// });
73-
// },
74-
// });
25+
this.historyService.getHistories().subscribe({
26+
next: data => {
27+
this.histories = data;
28+
this.loading = false;
29+
},
30+
error: () => {
31+
this.histories = [];
32+
this.loading = false;
33+
this.messageService.add({
34+
severity: 'error',
35+
summary: 'Error',
36+
detail: 'Failed to load data. Please try again later.',
37+
life: 3000,
38+
});
39+
},
40+
});
7541
}
7642
}

frontend/src/app/account/history/history.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export interface MatchingHistory {
66
topics: string[]; // question topics
77
status: string; // status of the session
88
time: string; // time of the session
9-
}
9+
}

0 commit comments

Comments
 (0)