@@ -29,13 +29,16 @@ import {
29
29
DeleteQuestion as DeleteQuestionByDocref ,
30
30
GetQuestions ,
31
31
Question ,
32
+ CreateQuestion ,
33
+ NewQuestion
32
34
} from "./services/question" ;
33
35
import {
34
36
CategoriesOption ,
35
37
DifficultyOption ,
36
38
OrderOption ,
37
39
} from "../utils/SelectOptions" ;
38
40
import Link from "next/link" ;
41
+ import TextArea from "antd/es/input/TextArea" ;
39
42
40
43
/**
41
44
* defines the State of the page whe a user is deleing an object. Has 3 general states:
@@ -98,6 +101,51 @@ export default function Home() {
98
101
// Message States
99
102
const [ messageApi , contextHolder ] = message . useMessage ( ) ;
100
103
104
+ // States for Create New Problem Modal
105
+ const [ isNewProblemModalOpen , setIsNewProblemModelOpen ] = useState ( false ) ;
106
+ const [ newProblemCategories , setNewProblemCategories ] = useState < string [ ] > ( [ ] ) ;
107
+ const [ newProblemDifficulty , setNewProblemDifficulty ] = useState < string [ ] > ( [ ] ) ; // Store the selected difficulty level
108
+
109
+ const [ newTitle , setNewTitle ] = useState ( 'sampleTitle' ) ;
110
+ const [ newDescription , setNewDescription ] = useState ( 'sampleDescription' ) ;
111
+ const [ newCategories , setNewCategories ] = useState < string [ ] > ( [ 'Algorithms' ] ) ;
112
+ const [ newComplexity , setNewComplexity ] = useState ( 1 ) ;
113
+ const [ newProblemError , setNewProblemError ] = useState < string | null > ( null ) ;
114
+
115
+ const handleCreateQuestion = async ( ) => {
116
+ const newQuestion : NewQuestion = {
117
+ newTitle,
118
+ newDescription,
119
+ newCategories,
120
+ newComplexity,
121
+ // Add assets and testCases if needed
122
+ } ;
123
+ try {
124
+ const createdQuestion : Question = await CreateQuestion ( newQuestion ) ;
125
+ console . log ( "Question created successfully:" , createdQuestion ) ;
126
+ // Reset form or update UI as needed
127
+ } catch ( err : any ) {
128
+ setNewProblemError ( err . message ) ;
129
+ }
130
+ } ;
131
+
132
+ const showNewProblemModal = ( ) => {
133
+ setIsNewProblemModelOpen ( true ) ;
134
+ } ;
135
+
136
+ const handleNewProblemSubmit = ( ) => {
137
+ setIsNewProblemModelOpen ( false ) ;
138
+ } ;
139
+
140
+ const handleNewProblemReturn = ( ) => {
141
+ setIsNewProblemModelOpen ( false ) ;
142
+ } ;
143
+
144
+ // Handler for change in multi-select categories option
145
+ const handleNewProblemCategoriesChange = ( value : string [ ] ) => {
146
+ setNewProblemCategories ( value ) ;
147
+ } ;
148
+
101
149
const success = ( message : string ) => {
102
150
messageApi . open ( {
103
151
type : "success" ,
@@ -174,7 +222,7 @@ export default function Home() {
174
222
>
175
223
< Button type = "link" > { text } </ Button >
176
224
</ Link >
177
- ) , // TODO (Sean): Onclick links to the individual question page
225
+ ) ,
178
226
} ,
179
227
{
180
228
title : "Categories" ,
@@ -210,6 +258,7 @@ export default function Home() {
210
258
render : ( _ : number , question : Question ) => (
211
259
< div >
212
260
{ /* TODO (Sean): Include Logic to handle retrieving of editable data here and display in a modal component */ }
261
+
213
262
< Button className = "edit-button" icon = { < EditOutlined /> } > </ Button >
214
263
{ /* TODO (Ryan): Include Pop-up confirmation for delete when clicked and link to delete API --> can also explore success notification or look into react-toast*/ }
215
264
< Button
@@ -296,9 +345,71 @@ export default function Home() {
296
345
< div className = "content-title" > Problems</ div >
297
346
< div className = "create-button" >
298
347
{ /* TODO (Sean): Launch a popup modal that links to the backend api to create a new entry in db, --> look into success/error notification/react toast */ }
299
- < Button type = "primary" icon = { < PlusCircleOutlined /> } >
348
+ < Button type = "primary" icon = { < PlusCircleOutlined /> } onClick = { showNewProblemModal } >
300
349
Create New Problem
301
350
</ Button >
351
+ < Modal
352
+
353
+ title = "Create New Problem"
354
+ open = { isNewProblemModalOpen }
355
+ onOk = { handleNewProblemSubmit }
356
+ onCancel = { handleNewProblemReturn }
357
+ // footer={[
358
+ // <Button key="back" onClick={handleNewProblemReturn}>
359
+ // Return
360
+ // </Button>,
361
+ // <Button key="submit" type="primary" onClick={handleNewProblemSubmit}>
362
+ // Submit
363
+ // </Button>,
364
+ // ]}
365
+ >
366
+ < input
367
+ type = "text"
368
+ placeholder = "Title"
369
+ value = { newTitle }
370
+ onChange = { ( e ) => setNewTitle ( e . target . value ) }
371
+ />
372
+ { /* Add other input fields for description, categories, complexity, etc. */ }
373
+ < button onClick = { handleCreateQuestion } > Create Question</ button >
374
+
375
+ </ Modal >
376
+ { /* <Modal
377
+ title="Create New Problem"
378
+ open={isNewProblemModalOpen}
379
+ onOk={handleNewProblemSubmit}
380
+ onCancel={handleNewProblemReturn}
381
+ footer={[
382
+ <Button key="back" onClick={handleNewProblemReturn}>
383
+ Return
384
+ </Button>,
385
+ <Button key="submit" type="primary" onClick={handleNewProblemSubmit}>
386
+ Submit
387
+ </Button>,
388
+ ]}
389
+ >
390
+ <TextArea className="create-title" placeholder="Problem Title" rows={1} maxLength={1}></TextArea>
391
+ <Select
392
+ allowClear
393
+ placeholder="Difficulty"
394
+ onChange={(value: string[]) => {
395
+ setNewProblemDifficulty(value);
396
+ }}
397
+ options={DifficultyOption}
398
+ className="new-problem-difficulty-select"
399
+ value={newProblemDifficulty}
400
+ />
401
+ <Select
402
+ mode="multiple"
403
+ allowClear
404
+ placeholder="Categories"
405
+ onChange={handleNewProblemCategoriesChange}
406
+ options={CategoriesOption}
407
+ className="new-problem-categories-multi-select"
408
+ value={newProblemCategories}
409
+ />
410
+ <TextArea className="create-description" placeholder="Description"></TextArea>
411
+ <TextArea className="create-problem-id" placeholder="Problem ID"></TextArea>
412
+ </Modal> */ }
302
413
</ div >
303
414
</ div >
304
415
{ /* TODO (Ben/Ryan): Include and link search & filter parameters */ }
0 commit comments