1
- // InterviewQuestionsTable.tsx
2
-
3
1
import React , { useEffect , useState } from "react" ;
4
2
import { Link } from "react-router-dom" ;
5
3
import {
@@ -14,6 +12,12 @@ import {
14
12
MenuItem ,
15
13
TablePagination ,
16
14
SelectChangeEvent ,
15
+ Button ,
16
+ Dialog ,
17
+ DialogTitle ,
18
+ DialogContent ,
19
+ DialogActions ,
20
+ Typography ,
17
21
} from "@mui/material" ;
18
22
import { useData } from "../../data/data.context" ;
19
23
@@ -37,32 +41,36 @@ const InterviewQuestionsTable: React.FC = () => {
37
41
const [ itemsPerPage , setItemsPerPage ] = useState < number > (
38
42
ITEMS_PER_PAGE_OPTIONS [ 0 ]
39
43
) ;
44
+ const [ selectedQuestion , setSelectedQuestion ] = useState < Question | null > (
45
+ null
46
+ ) ;
47
+ const [ isQuestionModalOpen , setIsQuestionModalOpen ] = useState ( false ) ;
40
48
const { questions, getQuestions } = useData ( ) ;
41
49
42
50
useEffect ( ( ) => {
43
51
async function getInterviewQuestions ( ) {
44
52
getQuestions ( ) ;
45
53
}
46
54
getInterviewQuestions ( ) ;
47
- // console.log("here");
48
- // eslint-disable-next-line react-hooks/exhaustive-deps
49
55
} , [ ] ) ;
50
56
51
57
useEffect ( ( ) => {
52
58
setQuestions ( questions ) ;
53
- //console.log(questionsData);
54
59
} , [ questions ] ) ;
55
60
56
61
const handleCategoriesChange = ( event : SelectChangeEvent < unknown > ) => {
57
62
setSelectedCategories ( event . target . value as string [ ] ) ;
58
- } ;
63
+ } ;
59
64
60
- const uniqueCategories = Array . from ( new Set ( questionsData . flatMap ( question => question . categories ) ) ) ;
65
+ const uniqueCategories = Array . from (
66
+ new Set ( questionsData . flatMap ( ( question ) => question . categories ) )
67
+ ) ;
61
68
62
- const filteredQuestions = questionsData . filter ( question =>
63
- selectedCategories . length === 0 ||
64
- selectedCategories . some ( cat => question . categories . includes ( cat ) )
65
- ) ;
69
+ const filteredQuestions = questionsData . filter ( ( question ) =>
70
+ selectedCategories . length === 0
71
+ ? true
72
+ : selectedCategories . some ( ( cat ) => question . categories . includes ( cat ) )
73
+ ) ;
66
74
67
75
const handlePageChange = ( event : unknown , newPage : number ) => {
68
76
setCurrentPage ( newPage ) ;
@@ -80,6 +88,16 @@ const filteredQuestions = questionsData.filter(question =>
80
88
indexOfLastQuestion
81
89
) ;
82
90
91
+ const openQuestionModal = ( question : Question ) => {
92
+ setSelectedQuestion ( question ) ;
93
+ setIsQuestionModalOpen ( true ) ;
94
+ } ;
95
+
96
+ const closeQuestionModal = ( ) => {
97
+ setSelectedQuestion ( null ) ;
98
+ setIsQuestionModalOpen ( false ) ;
99
+ } ;
100
+
83
101
return (
84
102
< >
85
103
{ /* Category Filter */ }
@@ -107,32 +125,29 @@ const filteredQuestions = questionsData.filter(question =>
107
125
< TableCell > Title</ TableCell >
108
126
< TableCell > Tags</ TableCell >
109
127
< TableCell > Categories</ TableCell >
110
- { /* <TableCell>Constraints</TableCell> */ }
111
128
< TableCell > Difficulty</ TableCell >
112
- { /* <TableCell>Description</TableCell> */ }
113
129
</ TableRow >
114
130
</ TableHead >
115
131
< TableBody >
116
132
{ currentQuestions . map ( ( question : Question , index : number ) => (
117
133
< TableRow key = { index } >
118
134
< TableCell >
119
- < Link
120
- to = { `/ question/ ${ question . id } ` }
135
+ < Button
136
+ onClick = { ( ) => openQuestionModal ( question ) }
121
137
style = { {
122
138
textDecoration : "none" ,
123
139
color : "inherit" ,
124
- fontSize : "16px" , // Adjust to your preference
140
+ fontSize : "16px" ,
125
141
fontWeight : "bold" ,
142
+ textTransform : "initial"
126
143
} }
127
144
>
128
145
{ question . title }
129
- </ Link >
146
+ </ Button >
130
147
</ TableCell >
131
148
< TableCell > { question . tags . join ( ", " ) } </ TableCell >
132
149
< TableCell > { question . categories . join ( ", " ) } </ TableCell >
133
- { /* <TableCell>{question.constraints.join(', ')}</TableCell> */ }
134
150
< TableCell > { question . difficulty } </ TableCell >
135
- { /* <TableCell>{question.description}</TableCell> */ }
136
151
</ TableRow >
137
152
) ) }
138
153
</ TableBody >
@@ -161,6 +176,42 @@ const filteredQuestions = questionsData.filter(question =>
161
176
onPageChange = { handlePageChange }
162
177
/>
163
178
</ div >
179
+ < Dialog
180
+ open = { isQuestionModalOpen }
181
+ onClose = { closeQuestionModal }
182
+ fullWidth
183
+ maxWidth = "md"
184
+ >
185
+ { selectedQuestion && (
186
+ < >
187
+ < DialogTitle > { selectedQuestion . title } </ DialogTitle >
188
+ < DialogContent >
189
+ < Typography variant = "body2" style = { { padding : "5px" } } >
190
+ < b > Categories:</ b > { selectedQuestion . categories . join ( ", " ) }
191
+ </ Typography >
192
+ < Typography variant = "body2" style = { { padding : "5px" } } >
193
+ < b > Difficulty:</ b > { selectedQuestion . difficulty }
194
+ </ Typography >
195
+ < Typography variant = "body2" style = { { padding : "5px" } } >
196
+ < b > Description</ b > : { selectedQuestion . description }
197
+ </ Typography >
198
+ </ DialogContent >
199
+ < DialogActions >
200
+ < Button onClick = { closeQuestionModal } color = "primary" >
201
+ Close
202
+ </ Button >
203
+ < Link
204
+ to = { `/question/${ selectedQuestion . id } ` }
205
+ style = { { textDecoration : "none" } }
206
+ >
207
+ < Button color = "primary" variant = "contained" >
208
+ Solve Question
209
+ </ Button >
210
+ </ Link >
211
+ </ DialogActions >
212
+ </ >
213
+ ) }
214
+ </ Dialog >
164
215
</ >
165
216
) ;
166
217
} ;
0 commit comments