From e1218ccf7f763d9050976f2c257f46d61d858957 Mon Sep 17 00:00:00 2001 From: LimZiJia Date: Tue, 12 Nov 2024 15:21:38 +0800 Subject: [PATCH] Fix bug where histories cannot be loaded during colab session Fix interfaces to be more correct. --- frontend/src/_services/history.service.ts | 4 ++-- .../src/app/account/history/history.component.html | 1 + .../src/app/account/history/history.component.ts | 12 ++++++++++-- frontend/src/app/account/history/history.model.ts | 10 +++++----- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/src/_services/history.service.ts b/frontend/src/_services/history.service.ts index 189967dc00..1ef0d38cac 100644 --- a/frontend/src/_services/history.service.ts +++ b/frontend/src/_services/history.service.ts @@ -26,8 +26,8 @@ export class HistoryService extends ApiService { difficulty: item.question.difficulty, status: item.status, time: item.createdAt, - language: item.snapshot.language, - code: item.snapshot.code, + language: item.snapshot?.language, + code: item.snapshot?.code, })), ), ); diff --git a/frontend/src/app/account/history/history.component.html b/frontend/src/app/account/history/history.component.html index eb4fe719c4..ea39c8cf40 100644 --- a/frontend/src/app/account/history/history.component.html +++ b/frontend/src/app/account/history/history.component.html @@ -80,3 +80,4 @@

{{ history?.question }}

+ diff --git a/frontend/src/app/account/history/history.component.ts b/frontend/src/app/account/history/history.component.ts index 77504efcab..1dc89a63e5 100644 --- a/frontend/src/app/account/history/history.component.ts +++ b/frontend/src/app/account/history/history.component.ts @@ -12,10 +12,11 @@ import { oneDark } from '@codemirror/theme-one-dark'; import { EditorState } from '@codemirror/state'; import { EditorView, basicSetup } from 'codemirror'; import { languageMap } from '../../collaboration/editor/languages'; +import { ToastModule } from 'primeng/toast'; @Component({ standalone: true, - imports: [TableModule, CommonModule, InputTextModule, ButtonModule, IconFieldModule, InputIconModule], + imports: [TableModule, CommonModule, InputTextModule, ButtonModule, IconFieldModule, InputIconModule, ToastModule], providers: [MessageService, DatePipe], templateUrl: './history.component.html', styleUrl: './history.component.css', @@ -43,7 +44,6 @@ export class HistoryComponent implements OnInit { time: this.datePipe.transform(history.time, 'short'), // Pipe to format date for searching })); this.loading = false; - console.log(this.histories); }, error: () => { this.histories = []; @@ -63,6 +63,14 @@ export class HistoryComponent implements OnInit { this.isPanelVisible = true; if (history.code && history.language) { this.initializeEditor(history.code, history.language); + } else { + console.log("why no message?") + this.messageService.add({ + severity: 'warn', + summary: 'Code Not Found', + detail: 'Your colaboration session might not have ended', + life: 3000, + }); } } diff --git a/frontend/src/app/account/history/history.model.ts b/frontend/src/app/account/history/history.model.ts index 85d083f73c..e09ed018c2 100644 --- a/frontend/src/app/account/history/history.model.ts +++ b/frontend/src/app/account/history/history.model.ts @@ -14,8 +14,8 @@ export interface MatchingHistory { topics: string[]; // question topics status: statusValues; // status of the session time: string | null; // time of the session - language: string | null; // language used during the session - code: string | null; // code written during the session + language: string | undefined; // language used during the session + code: string | undefined; // code written during the session } export interface User { @@ -33,8 +33,8 @@ export interface Question { } export interface Snapshot { - language: string | null; - code: string | null; + language: string; + code: string; } export interface sessionHistory { @@ -46,7 +46,7 @@ export interface sessionHistory { status: statusValues; createdAt: string; updatedAt: string; - snapshot: Snapshot; + snapshot?: Snapshot; } export interface historyResponse {