Skip to content

Commit 60dcd7d

Browse files
authored
Merge pull request #115 from CS3219-AY2425S1/add-question-description-view
Add Question Description Modal in User History
2 parents e940674 + 1bbb7d1 commit 60dcd7d

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

backend/question-service/controllers/historyController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const getUserHistoryEntries = async (req: any, res: Response) => {
3535
title: entry.question.title,
3636
difficulty: entry.question.difficulty,
3737
topics: entry.question.categories.map((cat: any) => cat.name),
38+
description: entry.question.description,
3839
attemptCodes: entry.attemptCodes.filter((attemptCode) => attemptCode && attemptCode !== ""),
3940
};
4041
});

frontend/src/domain/entities/HistoryEntry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export interface HistoryEntry {
77
title: string;
88
difficulty: 'Easy' | 'Medium' | 'Hard';
99
topics: string[];
10+
description: string;
1011
attemptCodes: string[];
1112
}

frontend/src/presentation/components/RecentAttemptsTable.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { historyUseCases } from "domain/usecases/HistoryUseCases";
88
import { ReactMarkdown } from "./common/ReactMarkdown";
99
import TabPane from "antd/es/tabs/TabPane";
1010
import { useNavigate } from "react-router-dom";
11-
import { EyeOutlined, TeamOutlined } from "@ant-design/icons"; // Importing additional icons
11+
import { EyeOutlined, TeamOutlined } from "@ant-design/icons";
1212

1313
const formatDate = (dateString: string): string => {
1414
const options: Intl.DateTimeFormatOptions = {
@@ -42,7 +42,7 @@ const calculateDuration = (start: string, end: string): string => {
4242
};
4343

4444
export const RecentAttemptsTable: React.FC = () => {
45-
const navigate = useNavigate(); // Initialized navigate
45+
const navigate = useNavigate();
4646

4747
// State Definitions
4848
const [recentAttemptsData, setRecentAttemptsData] = useState<HistoryEntry[]>([]);
@@ -53,6 +53,10 @@ export const RecentAttemptsTable: React.FC = () => {
5353
const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
5454
const [currentCodes, setCurrentCodes] = useState<string[]>([]);
5555

56+
// Modal State for Viewing Description
57+
const [isDescriptionModalVisible, setIsDescriptionModalVisible] = useState<boolean>(false);
58+
const [currentDescription, setCurrentDescription] = useState<string>('');
59+
5660
// Fetch Recent Attempts on Component Mount
5761
useEffect(() => {
5862
fetchRecentAttempts();
@@ -130,6 +134,18 @@ export const RecentAttemptsTable: React.FC = () => {
130134
setCurrentCodes([]);
131135
};
132136

137+
// Function to Show Description Modal
138+
const showDescriptionModal = (description: string) => {
139+
setCurrentDescription(description);
140+
setIsDescriptionModalVisible(true);
141+
};
142+
143+
// Function to Close Description Modal
144+
const handleDescriptionModalClose = () => {
145+
setIsDescriptionModalVisible(false);
146+
setCurrentDescription('');
147+
};
148+
133149
// Define Columns for the Table
134150
const columns: ColumnsType<HistoryEntry> = [
135151
{
@@ -169,7 +185,11 @@ export const RecentAttemptsTable: React.FC = () => {
169185
title: 'Title',
170186
dataIndex: 'title',
171187
key: 'title',
172-
render: (text: string) => <Typography.Text>{text}</Typography.Text>,
188+
render: (text: string, record: HistoryEntry) => (
189+
<Typography.Link onClick={() => showDescriptionModal(record.description)}>
190+
{text}
191+
</Typography.Link>
192+
),
173193
},
174194
{
175195
title: 'Difficulty',
@@ -306,6 +326,18 @@ export const RecentAttemptsTable: React.FC = () => {
306326
<Empty description="No code available" />
307327
)}
308328
</Modal>
329+
330+
<Modal
331+
title="Question Description"
332+
open={isDescriptionModalVisible}
333+
onCancel={handleDescriptionModalClose}
334+
footer={null}
335+
width={800}
336+
>
337+
<div style={{ height: '100%', overflow: 'auto', padding: '16px' }}>
338+
<ReactMarkdown isReadOnly value={currentDescription} />
339+
</div>
340+
</Modal>
309341
</div>
310342
);
311343
};

0 commit comments

Comments
 (0)