Skip to content

Commit dae472d

Browse files
authored
Merge pull request #114 from CS3219-AY2425S1/disable-rejoin-room-frontend
Add Disabling of Rejoin Room if Room is Expired
2 parents b2a0969 + 48fa42c commit dae472d

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

backend/question-service/controllers/historyController.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@ export const getUserHistoryEntries = async (req: any, res: Response) => {
1717
model: "category",
1818
},
1919
});
20-
20+
2121
historyEntries.forEach(async (entry) => {
2222
if (entry.question === null) {
2323
await historyEntryModel.findByIdAndDelete({_id: entry._id});
2424
}
2525
})
26+
2627
const historyViewModels = historyEntries
2728
.filter((entry) => !(entry.question === null))
2829
.map((entry) => {
30+
const attemptStartDate = new Date(entry.attemptStartedAt);
31+
const timeDiffMs = Date.now() - attemptStartDate.getTime();
32+
const isWithin24Hours = timeDiffMs < 86400000; // 1 Day; Same as ROOM_LIFESPAN in MatchingService. Can be different if desired.
33+
2934
return {
3035
id: entry._id,
3136
key: entry._id,
32-
roomId: entry.roomId,
37+
roomId: isWithin24Hours ? entry.roomId : null,
3338
attemptStartedAt: entry.attemptStartedAt.getTime(),
3439
lastAttemptSubmittedAt: entry.lastAttemptSubmittedAt.getTime(),
3540
title: entry.question.title,

frontend/src/domain/entities/HistoryEntry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface HistoryEntry {
22
_id: string;
33
key: string;
4-
roomId: string;
4+
roomId?: string; // If null, room is expired
55
attemptStartedAt: string;
66
lastAttemptSubmittedAt: string;
77
title: string;

frontend/src/presentation/components/RecentAttemptsTable.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,16 @@ export const RecentAttemptsTable: React.FC = () => {
238238
>
239239
View Past Code
240240
</Button>
241-
<Button
242-
type="link"
243-
onClick={() => navigate(`/room/${record.roomId}`)}
244-
icon={<TeamOutlined />}
245-
aria-label={`Rejoin room ${record.roomId}`}
246-
>
247-
Rejoin
248-
</Button>
241+
{record.roomId && (
242+
<Button
243+
type="link"
244+
onClick={() => navigate(`/room/${record.roomId}`)}
245+
icon={<TeamOutlined />}
246+
aria-label={`Rejoin room ${record.roomId}`}
247+
>
248+
Rejoin
249+
</Button>
250+
)}
249251
</Space>
250252
),
251253
},

0 commit comments

Comments
 (0)