@@ -3,60 +3,100 @@ import './Question.css'
3
3
import delete_icon from '../Assets/bin.png'
4
4
import edit_icon from '../Assets/pencil.png'
5
5
6
- export const Question = ( { question, i} ) => {
6
+ export const Question = ( { question, i, deleteQuestion , updateQuestion } ) => {
7
7
const [ selected , setSelected ] = useState ( null ) ;
8
+ const [ title , setTitle ] = useState ( question . title ) ;
9
+ const [ difficulty , setDifficulty ] = useState ( question . complexity ) ;
10
+ const [ topic , setTopic ] = useState ( question . category ) ;
11
+ const [ description , setDescription ] = useState ( question . description )
12
+
8
13
const toggle = ( i ) => {
9
- if ( selected === i ) {
10
- return setSelected ( null )
14
+ if ( ! isEdit ) {
15
+ if ( selected === i ) {
16
+ return setSelected ( null )
17
+ }
18
+ setSelected ( i )
11
19
}
12
- setSelected ( i )
13
20
} ;
21
+ const [ isEdit , setEdit ] = useState ( false ) ;
14
22
let tagClass = "q-tag" ;
15
23
16
- if ( question . difficulty . toLowerCase ( ) === "easy" ) {
24
+ if ( question . complexity . toLowerCase ( ) === "easy" ) {
17
25
tagClass += " q-tag-green"
18
- } else if ( question . difficulty . toLowerCase ( ) === "medium" ) {
26
+ } else if ( question . complexity . toLowerCase ( ) === "medium" ) {
19
27
tagClass += " q-tag-orange"
20
- } else if ( question . difficulty . toLowerCase ( ) === "hard" ) {
28
+ } else if ( question . complexity . toLowerCase ( ) === "hard" ) {
21
29
tagClass += " q-tag-red"
22
30
} else {
23
31
tagClass += " q-tag-white"
24
32
}
25
33
return (
26
- < div className = "question-container" >
27
- < div className = "question" >
28
- < div className = "q-header" onClick = { ( ) => toggle ( i ) } >
29
- < div className = "q-name" >
30
- < div className = "q-id" > #{ question . id } </ div >
31
- < div className = "q-title" > { question . title } </ div >
32
- </ div >
33
- < span > { selected === i ? "-" : "+" } </ span >
34
- </ div >
35
- < div className = { selected === i ? "q-content-show" : "q-content" } >
36
- < << << << HEAD
37
- < div className = "q-tag-container" >
38
- < div className = "q-tags" >
39
- < div className = { tagClass } > { question . difficulty } </ div >
40
- < div className = "q-tag" > { question . topic } </ div >
34
+ < div className = { isEdit ? "form-container" : "question-container" } >
35
+ < div className = { isEdit ? "container" : "question" } >
36
+ < div className = "q-header" onClick = { ( ) => toggle ( i ) } >
37
+ < div className = "q-name" >
38
+ < div className = { isEdit ? "q-form-id" : "q-id" } > #{ question . id } </ div >
39
+ { isEdit === true ? < input type = "text" className = "q-form-title q-form-input" defaultValue = { question . title }
40
+ onChange = { ( e ) => { setTitle ( e . target . value ) } } /> :
41
+ < div className = "q-title" > { question . title } </ div > }
41
42
</ div >
42
- < div className = "q-edit" >
43
- < img src = { edit_icon } alt = "" />
44
- </ div >
45
- =======
46
- < div className = "q-tags" >
47
- < div className = "q-tag" > { question . complexity } </ div >
48
- < div className = "q-tag" > { question . category } </ div >
49
- >>> >>> > 2 d10aa60338d872e3fe12c04076ef7f7dbda4179
43
+ < span > { selected === i ? "-" : "+" } </ span >
50
44
</ div >
51
45
52
- < div className = "q-description" > { question . description } </ div >
46
+ { ! isEdit
47
+ ?
48
+ < div className = { selected === i ? "q-content-show" : "q-content" } >
49
+ < div className = "q-tag-container" >
50
+ < div className = { isEdit ? "q-form-tags" : "q-tags" } >
51
+ { isEdit === true ? < input type = "text" className = "q-form-tag q-form-input" defaultValue = { question . complexity }
52
+ onChange = { ( e ) => { setDifficulty ( e . target . value ) } } /> :
53
+ < div className = { tagClass } > { question . complexity } </ div > }
54
+ { isEdit === true ? < input type = "text" className = "q-form-tag q-form-input" defaultValue = { question . category }
55
+ onChange = { ( e ) => { setTopic ( e . target . value ) } } /> :
56
+ < div className = "q-tag" > { question . category } </ div > }
57
+ </ div >
58
+ < div className = "q-edit" onClick = { ( ) => setEdit ( true ) } >
59
+ < img src = { edit_icon } alt = "" />
60
+ </ div >
61
+ </ div >
62
+
63
+ { isEdit === true ? < textarea type = "text" className = "q-form-description q-form-input" defaultValue = { question . description }
64
+ onChange = { ( e ) => { setDescription ( e . target . value ) } } /> :
65
+ < div className = "q-description" > { question . description } </ div > }
66
+
67
+ { isEdit === true ? < button className = "submit-btn"
68
+ onClick = { ( e ) => {
69
+ setEdit ( false ) ;
70
+ updateQuestion ( question . id , title , description , difficulty , topic )
71
+ } } > Submit</ button > : < div > </ div > }
72
+ </ div >
73
+ :
74
+ < div className = "q-tag-container" >
75
+ < div className = { isEdit ? "q-form-tags" : "q-tags" } >
76
+ { isEdit === true ? < input type = "text" className = "q-form-tag q-form-input" defaultValue = { question . complexity }
77
+ onChange = { ( e ) => { setDifficulty ( e . target . value ) } } /> :
78
+ < div className = { tagClass } > { question . complexity } </ div > }
79
+ { isEdit === true ? < input type = "text" className = "q-form-tag q-form-input" defaultValue = { question . category }
80
+ onChange = { ( e ) => { setTopic ( e . target . value ) } } /> :
81
+ < div className = "q-tag" > { question . category } </ div > }
82
+ </ div >
83
+ </ div > }
84
+
85
+ { isEdit === true ? < textarea type = "text" className = "q-form-description q-form-input" defaultValue = { question . description }
86
+ onChange = { ( e ) => { setDescription ( e . target . value ) } } /> : null }
87
+
88
+ { isEdit === true ?
89
+ < div className = "btn-container" >
90
+ < button className = "submit-btn"
91
+ onClick = { ( e ) => {
92
+ setEdit ( false ) ;
93
+ updateQuestion ( question . id , title , description , difficulty , topic )
94
+ } } > Submit</ button > </ div > : null }
95
+
96
+ </ div >
97
+ < div className = "delete-btn" onClick = { ( e ) => deleteQuestion ( i ) } >
98
+ < img src = { delete_icon } alt = "" />
53
99
</ div >
54
-
55
-
56
- </ div >
57
- < div className = "delete-btn" >
58
- < img src = { delete_icon } alt = "" />
59
- </ div >
60
100
</ div >
61
101
62
102
)
0 commit comments