From f0b78f93ce17c983449e7b98713809492c2243db Mon Sep 17 00:00:00 2001 From: Kevin Tjan Date: Sun, 10 Nov 2024 02:17:05 +0800 Subject: [PATCH 1/2] Add Disabling of Rejoin Room if Room is Expired --- .../components/RecentAttemptsTable.tsx | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/frontend/src/presentation/components/RecentAttemptsTable.tsx b/frontend/src/presentation/components/RecentAttemptsTable.tsx index 07ea1252da..ef7510da43 100644 --- a/frontend/src/presentation/components/RecentAttemptsTable.tsx +++ b/frontend/src/presentation/components/RecentAttemptsTable.tsx @@ -208,26 +208,36 @@ export const RecentAttemptsTable: React.FC = () => { { title: 'Actions', key: 'action', - render: (_text, record) => ( - - - - - ), + render: (_text, record) => { + const attemptStartDate = new Date(record.attemptStartedAt); + const now = new Date(); + const timeDiffMs = now.getTime() - attemptStartDate.getTime(); + + const isWithin24Hours = timeDiffMs < 86400000; // Should be same as ROOM_LIFESPAN in MatchingService + + return ( + + + {isWithin24Hours && ( + + )} + + ); + }, }, ]; From 9fc3096ee34d5a4bc1d43fd043ef7db7d99abd72 Mon Sep 17 00:00:00 2001 From: Kevin Tjan Date: Sun, 10 Nov 2024 13:04:02 +0800 Subject: [PATCH 2/2] Move Responsibility of Checking Room Expiry to Question Service --- .../controllers/historyController.ts | 7 ++- frontend/src/domain/entities/HistoryEntry.ts | 2 +- .../components/RecentAttemptsTable.tsx | 44 ++++++++----------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/backend/question-service/controllers/historyController.ts b/backend/question-service/controllers/historyController.ts index adc529af47..330f99ae1d 100644 --- a/backend/question-service/controllers/historyController.ts +++ b/backend/question-service/controllers/historyController.ts @@ -18,10 +18,15 @@ export const getUserHistoryEntries = async (req: any, res: Response) => { }, }); const historyViewModels = historyEntries.map((entry) => { + const attemptStartDate = new Date(entry.attemptStartedAt); + const timeDiffMs = Date.now() - attemptStartDate.getTime(); + + const isWithin24Hours = timeDiffMs < 86400000; // 1 Day; Same as ROOM_LIFESPAN in MatchingService. Can be different if desired. + return { id: entry._id, key: entry._id, - roomId: entry.roomId, + roomId: isWithin24Hours ? entry.roomId : null, attemptStartedAt: entry.attemptStartedAt.getTime(), lastAttemptSubmittedAt: entry.lastAttemptSubmittedAt.getTime(), title: entry.question.title, diff --git a/frontend/src/domain/entities/HistoryEntry.ts b/frontend/src/domain/entities/HistoryEntry.ts index 83320b2a41..3c441d292f 100644 --- a/frontend/src/domain/entities/HistoryEntry.ts +++ b/frontend/src/domain/entities/HistoryEntry.ts @@ -1,7 +1,7 @@ export interface HistoryEntry { _id: string; key: string; - roomId: string; + roomId?: string; // If null, room is expired attemptStartedAt: string; lastAttemptSubmittedAt: string; title: string; diff --git a/frontend/src/presentation/components/RecentAttemptsTable.tsx b/frontend/src/presentation/components/RecentAttemptsTable.tsx index ef7510da43..7cbb12ebe1 100644 --- a/frontend/src/presentation/components/RecentAttemptsTable.tsx +++ b/frontend/src/presentation/components/RecentAttemptsTable.tsx @@ -208,36 +208,28 @@ export const RecentAttemptsTable: React.FC = () => { { title: 'Actions', key: 'action', - render: (_text, record) => { - const attemptStartDate = new Date(record.attemptStartedAt); - const now = new Date(); - const timeDiffMs = now.getTime() - attemptStartDate.getTime(); - - const isWithin24Hours = timeDiffMs < 86400000; // Should be same as ROOM_LIFESPAN in MatchingService - - return ( - + render: (_text, record) => ( + + + {record.roomId && ( - {isWithin24Hours && ( - - )} - - ); - }, + )} + + ), }, ];