Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/question-service/controllers/historyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const getUserHistoryEntries = async (req: any, res: Response) => {
title: entry.question.title,
difficulty: entry.question.difficulty,
topics: entry.question.categories.map((cat: any) => cat.name),
description: entry.question.description,
attemptCodes: entry.attemptCodes.filter((attemptCode) => attemptCode && attemptCode !== ""),
};
});
Expand Down
1 change: 1 addition & 0 deletions frontend/src/domain/entities/HistoryEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export interface HistoryEntry {
title: string;
difficulty: 'Easy' | 'Medium' | 'Hard';
topics: string[];
description: string;
attemptCodes: string[];
}
38 changes: 35 additions & 3 deletions frontend/src/presentation/components/RecentAttemptsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { historyUseCases } from "domain/usecases/HistoryUseCases";
import { ReactMarkdown } from "./common/ReactMarkdown";
import TabPane from "antd/es/tabs/TabPane";
import { useNavigate } from "react-router-dom";
import { EyeOutlined, TeamOutlined } from "@ant-design/icons"; // Importing additional icons
import { EyeOutlined, TeamOutlined } from "@ant-design/icons";

const formatDate = (dateString: string): string => {
const options: Intl.DateTimeFormatOptions = {
Expand Down Expand Up @@ -42,7 +42,7 @@ const calculateDuration = (start: string, end: string): string => {
};

export const RecentAttemptsTable: React.FC = () => {
const navigate = useNavigate(); // Initialized navigate
const navigate = useNavigate();

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

// Modal State for Viewing Description
const [isDescriptionModalVisible, setIsDescriptionModalVisible] = useState<boolean>(false);
const [currentDescription, setCurrentDescription] = useState<string>('');

// Fetch Recent Attempts on Component Mount
useEffect(() => {
fetchRecentAttempts();
Expand Down Expand Up @@ -130,6 +134,18 @@ export const RecentAttemptsTable: React.FC = () => {
setCurrentCodes([]);
};

// Function to Show Description Modal
const showDescriptionModal = (description: string) => {
setCurrentDescription(description);
setIsDescriptionModalVisible(true);
};

// Function to Close Description Modal
const handleDescriptionModalClose = () => {
setIsDescriptionModalVisible(false);
setCurrentDescription('');
};

// Define Columns for the Table
const columns: ColumnsType<HistoryEntry> = [
{
Expand Down Expand Up @@ -169,7 +185,11 @@ export const RecentAttemptsTable: React.FC = () => {
title: 'Title',
dataIndex: 'title',
key: 'title',
render: (text: string) => <Typography.Text>{text}</Typography.Text>,
render: (text: string, record: HistoryEntry) => (
<Typography.Link onClick={() => showDescriptionModal(record.description)}>
{text}
</Typography.Link>
),
},
{
title: 'Difficulty',
Expand Down Expand Up @@ -306,6 +326,18 @@ export const RecentAttemptsTable: React.FC = () => {
<Empty description="No code available" />
)}
</Modal>

<Modal
title="Question Description"
open={isDescriptionModalVisible}
onCancel={handleDescriptionModalClose}
footer={null}
width={800}
>
<div style={{ height: '100%', overflow: 'auto', padding: '16px' }}>
<ReactMarkdown isReadOnly value={currentDescription} />
</div>
</Modal>
</div>
);
};
Expand Down
Loading