1
- import React , { Component } from ' react' ;
2
- import ' ../stylesheets/App.css' ;
3
- import Question from ' ./Question' ;
4
- import Search from ' ./Search' ;
5
- import $ from ' jquery' ;
1
+ import React , { Component } from " react" ;
2
+ import " ../stylesheets/App.css" ;
3
+ import Question from " ./Question" ;
4
+ import Search from " ./Search" ;
5
+ import $ from " jquery" ;
6
6
7
7
class QuestionView extends Component {
8
8
constructor ( ) {
@@ -23,18 +23,18 @@ class QuestionView extends Component {
23
23
getQuestions = ( ) => {
24
24
$ . ajax ( {
25
25
url : `/questions?page=${ this . state . page } ` , //TODO: update request URL
26
- type : ' GET' ,
26
+ type : " GET" ,
27
27
success : ( result ) => {
28
28
this . setState ( {
29
29
questions : result . questions ,
30
30
totalQuestions : result . total_questions ,
31
31
categories : result . categories ,
32
- currentCategory : result . current_category ,
32
+ // currentCategory: result.current_category,
33
33
} ) ;
34
34
return ;
35
35
} ,
36
36
error : ( error ) => {
37
- alert ( ' Unable to load questions. Please try your request again' ) ;
37
+ alert ( " Unable to load questions. Please try your request again" ) ;
38
38
return ;
39
39
} ,
40
40
} ) ;
@@ -51,7 +51,7 @@ class QuestionView extends Component {
51
51
pageNumbers . push (
52
52
< span
53
53
key = { i }
54
- className = { `page-num ${ i === this . state . page ? ' active' : '' } ` }
54
+ className = { `page-num ${ i === this . state . page ? " active" : "" } ` }
55
55
onClick = { ( ) => {
56
56
this . selectPage ( i ) ;
57
57
} }
@@ -66,7 +66,7 @@ class QuestionView extends Component {
66
66
getByCategory = ( id ) => {
67
67
$ . ajax ( {
68
68
url : `/categories/${ id } /questions` , //TODO: update request URL
69
- type : ' GET' ,
69
+ type : " GET" ,
70
70
success : ( result ) => {
71
71
this . setState ( {
72
72
questions : result . questions ,
@@ -76,7 +76,7 @@ class QuestionView extends Component {
76
76
return ;
77
77
} ,
78
78
error : ( error ) => {
79
- alert ( ' Unable to load questions. Please try your request again' ) ;
79
+ alert ( " Unable to load questions. Please try your request again" ) ;
80
80
return ;
81
81
} ,
82
82
} ) ;
@@ -85,9 +85,9 @@ class QuestionView extends Component {
85
85
submitSearch = ( searchTerm ) => {
86
86
$ . ajax ( {
87
87
url : `/questions` , //TODO: update request URL
88
- type : ' POST' ,
89
- dataType : ' json' ,
90
- contentType : ' application/json' ,
88
+ type : " POST" ,
89
+ dataType : " json" ,
90
+ contentType : " application/json" ,
91
91
data : JSON . stringify ( { searchTerm : searchTerm } ) ,
92
92
xhrFields : {
93
93
withCredentials : true ,
@@ -102,23 +102,23 @@ class QuestionView extends Component {
102
102
return ;
103
103
} ,
104
104
error : ( error ) => {
105
- alert ( ' Unable to load questions. Please try your request again' ) ;
105
+ alert ( " Unable to load questions. Please try your request again" ) ;
106
106
return ;
107
107
} ,
108
108
} ) ;
109
109
} ;
110
110
111
111
questionAction = ( id ) => ( action ) => {
112
- if ( action === ' DELETE' ) {
113
- if ( window . confirm ( ' are you sure you want to delete the question?' ) ) {
112
+ if ( action === " DELETE" ) {
113
+ if ( window . confirm ( " are you sure you want to delete the question?" ) ) {
114
114
$ . ajax ( {
115
115
url : `/questions/${ id } ` , //TODO: update request URL
116
- type : ' DELETE' ,
116
+ type : " DELETE" ,
117
117
success : ( result ) => {
118
118
this . getQuestions ( ) ;
119
119
} ,
120
120
error : ( error ) => {
121
- alert ( ' Unable to load questions. Please try your request again' ) ;
121
+ alert ( " Unable to load questions. Please try your request again" ) ;
122
122
return ;
123
123
} ,
124
124
} ) ;
@@ -128,8 +128,8 @@ class QuestionView extends Component {
128
128
129
129
render ( ) {
130
130
return (
131
- < div className = ' question-view' >
132
- < div className = ' categories-list' >
131
+ < div className = " question-view" >
132
+ < div className = " categories-list" >
133
133
< h2
134
134
onClick = { ( ) => {
135
135
this . getQuestions ( ) ;
@@ -147,7 +147,7 @@ class QuestionView extends Component {
147
147
>
148
148
{ this . state . categories [ id ] }
149
149
< img
150
- className = ' category'
150
+ className = " category"
151
151
alt = { `${ this . state . categories [ id ] . toLowerCase ( ) } ` }
152
152
src = { `${ this . state . categories [ id ] . toLowerCase ( ) } .svg` }
153
153
/>
@@ -156,7 +156,7 @@ class QuestionView extends Component {
156
156
</ ul >
157
157
< Search submitSearch = { this . submitSearch } />
158
158
</ div >
159
- < div className = ' questions-list' >
159
+ < div className = " questions-list" >
160
160
< h2 > Questions</ h2 >
161
161
{ this . state . questions . map ( ( q , ind ) => (
162
162
< Question
@@ -168,7 +168,7 @@ class QuestionView extends Component {
168
168
questionAction = { this . questionAction ( q . id ) }
169
169
/>
170
170
) ) }
171
- < div className = ' pagination-menu' > { this . createPagination ( ) } </ div >
171
+ < div className = " pagination-menu" > { this . createPagination ( ) } </ div >
172
172
</ div >
173
173
</ div >
174
174
) ;
0 commit comments