Skip to content

Commit 44aaf03

Browse files
committed
reuse question description component
1 parent fc0dabf commit 44aaf03

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

peerprep-fe/src/components/dialogs/ActionDialog.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { ReactElement } from 'react';
22
import {
33
Dialog,
44
DialogContent,
@@ -16,6 +16,7 @@ type Props = {
1616
description: string;
1717
callback?: () => void;
1818
callbackTitle?: string;
19+
children?: ReactElement;
1920
};
2021

2122
const ActionDialog = ({
@@ -26,18 +27,23 @@ const ActionDialog = ({
2627
description,
2728
callback,
2829
callbackTitle,
30+
children,
2931
}: Props) => {
3032
return (
3133
<Dialog open={isOpen} onOpenChange={onClose}>
32-
<DialogContent className="bg-black">
34+
<DialogContent className="max-h-[80%] overflow-auto bg-black">
3335
<DialogHeader>
3436
<DialogTitle>{title}</DialogTitle>
3537
<DialogDescription>{subtitle}</DialogDescription>
3638
</DialogHeader>
37-
<div className="mt-4">
38-
<h3 className="mb-2 text-lg font-semibold">Description:</h3>
39-
<p>{description}</p>
40-
</div>
39+
{children ? (
40+
children
41+
) : (
42+
<div className="mt-4">
43+
<h3 className="mb-2 text-lg font-semibold">Description:</h3>
44+
<p>{description}</p>
45+
</div>
46+
)}
4147
<div className="mt-6 flex justify-end">
4248
<Button variant="secondary" onClick={callback}>
4349
{callbackTitle}

peerprep-fe/src/components/problems/ProblemDescriptionPanel.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,29 @@ import { Button } from '../ui/button';
55
type Props = {
66
problem: Problem;
77
resetQuestion: () => void; // replace with something more generic
8+
hasHeader?: boolean;
89
};
910

10-
const ProblemDescriptionPanel = ({ problem, resetQuestion }: Props) => {
11+
const ProblemDescriptionPanel = ({
12+
problem,
13+
resetQuestion,
14+
hasHeader = true,
15+
}: Props) => {
1116
return (
1217
<>
13-
<div className="flex justify-between">
14-
<h2 className="mb-4 text-2xl font-bold">{problem.title}</h2>
15-
<Button
16-
variant="outline"
17-
className="border-gray-700 bg-gray-800"
18-
onClick={() => resetQuestion()}
19-
>
20-
Reset
21-
</Button>
22-
</div>
18+
{hasHeader && (
19+
<div className="flex justify-between">
20+
<h2 className="mb-4 text-2xl font-bold">{problem.title}</h2>
21+
<Button
22+
variant="outline"
23+
className="border-gray-700 bg-gray-800"
24+
onClick={() => resetQuestion()}
25+
>
26+
Reset
27+
</Button>
28+
</div>
29+
)}
30+
2331
<p className="mb-4">{problem.description}</p>
2432
{problem.examples.map((example, index) => (
2533
<React.Fragment key={index}>

peerprep-fe/src/components/problems/ProblemRow.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import InformationDialog from '../dialogs/InformationDialog';
1010
import ActionDialog from '../dialogs/ActionDialog';
1111
import { useRouter } from 'next/navigation';
1212
import { axiosClient } from '@/network/axiosClient';
13+
import ProblemDescriptionPanel from './ProblemDescriptionPanel';
1314

1415
function ProblemStatus({ status }: { status: string }) {
1516
if (status === 'solved') {
@@ -156,7 +157,14 @@ export default function ProblemRow({
156157
description={problem.description}
157158
callback={handleMatch}
158159
callbackTitle="Match"
159-
/>
160+
>
161+
<ProblemDescriptionPanel
162+
problem={problem}
163+
resetQuestion={() => {}}
164+
hasHeader={false}
165+
/>
166+
</ActionDialog>
167+
160168
{/* Dialog for deleting question */}
161169
<ActionDialog
162170
isOpen={isDeleteDialogOpen}

0 commit comments

Comments
 (0)