File tree Expand file tree Collapse file tree 3 files changed +24
-17
lines changed
apps/question-service/src/app Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -72,21 +72,22 @@ export default function Home() {
72
72
73
73
// Include States for Create/Edit Modal (TODO: Sean)
74
74
75
- // When the page is initialised, fetch all the questions ONCE and display in table
75
+ // When the page is initialised, fetch all the questions and display in table
76
+ // When the dependencies/states change, the useEffect hook will trigger to re-fetch the questions
76
77
useEffect ( ( ) => {
77
78
if ( ! isLoading ) {
78
79
setIsLoading ( true ) ;
79
80
}
80
81
81
- GetQuestions ( currentPage , limit ) . then ( ( data ) => {
82
+ GetQuestions ( currentPage , limit , sortBy ) . then ( ( data ) => {
82
83
setQuestions ( data . questions ) ;
83
84
setTotalCount ( data . totalCount ) ;
84
85
setTotalPages ( data . totalPages ) ;
85
86
setCurrentPage ( data . currentPage ) ;
86
87
setLimit ( data . limit ) ;
87
88
setIsLoading ( false ) ;
88
89
} ) ;
89
- } , [ limit , currentPage ] ) ;
90
+ } , [ limit , currentPage , sortBy ] ) ;
90
91
91
92
// Table column specification
92
93
const columns : TableProps < Question > [ "columns" ] = [
@@ -167,8 +168,6 @@ export default function Home() {
167
168
current ,
168
169
pageSize
169
170
) => {
170
- console . log ( current ) ;
171
- console . log ( pageSize ) ;
172
171
setCurrentPage ( current ) ;
173
172
setLimit ( pageSize ) ;
174
173
} ;
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ export interface QuestionListResponse {
24
24
// GET request to fetch all the questions (TODO: Ben --> Fetch with filtering/sorting etc)
25
25
export const GetQuestions = async (
26
26
currentPage ?: number ,
27
- limit ?: number
27
+ limit ?: number ,
28
+ sortBy ?: string
28
29
) : Promise < QuestionListResponse > => {
29
30
let query_url = `${ process . env . NEXT_PUBLIC_API_URL } questions` ;
30
31
let query_params = "" ;
@@ -37,6 +38,13 @@ export const GetQuestions = async (
37
38
query_params += `${ query_params . length > 0 ? "&" : "?" } limit=${ limit } ` ;
38
39
}
39
40
41
+ if ( sortBy ) {
42
+ const [ field , order ] = sortBy . split ( " " ) ;
43
+ query_params += `${
44
+ query_params . length > 0 ? "&" : "?"
45
+ } sortField=${ field } &sortValue=${ order } `;
46
+ }
47
+
40
48
query_url += query_params ;
41
49
const response = await fetch ( query_url ) ;
42
50
const data = await response . json ( ) ;
Original file line number Diff line number Diff line change @@ -78,49 +78,49 @@ export const CategoriesOption = [
78
78
export const DifficultyOption = [
79
79
{
80
80
label : "Easy" ,
81
- value : "Easy " ,
81
+ value : "easy " ,
82
82
} ,
83
83
{
84
84
label : "Medium" ,
85
- value : "Medium " ,
85
+ value : "medium " ,
86
86
} ,
87
87
{
88
88
label : "Hard" ,
89
- value : "Hard " ,
89
+ value : "hard " ,
90
90
} ,
91
91
] ;
92
92
93
93
export const OrderOption = [
94
94
{
95
95
label : "Id (ASC)" ,
96
- value : "Id (ASC) " ,
96
+ value : "id asc " ,
97
97
} ,
98
98
{
99
99
label : "Id (DESC)" ,
100
- value : "Id (DESC) " ,
100
+ value : "id desc " ,
101
101
} ,
102
102
{
103
103
label : "Most Recent" ,
104
- value : "Most Recent " ,
104
+ value : "createdAt desc " ,
105
105
} ,
106
106
{
107
107
label : "Oldest" ,
108
- value : "Oldest " ,
108
+ value : "createdAt asc " ,
109
109
} ,
110
110
{
111
111
label : "Alphabetical (A-Z)" ,
112
- value : "Alphabetical (A-Z)" , // TODO: Edit the values based on backend in the future
112
+ value : "title asc" ,
113
113
} ,
114
114
{
115
115
label : "Alphabetical (Z-A)" ,
116
- value : "Alphabetical (Z-A)" , // TODO: Edit the values based on backend in the future
116
+ value : "title desc" ,
117
117
} ,
118
118
{
119
119
label : "Difficulty (ASC)" ,
120
- value : "Difficulty (ASC) " ,
120
+ value : "complexity asc " ,
121
121
} ,
122
122
{
123
123
label : "Difficulty (DESC)" ,
124
- value : "Difficulty (DESC) " ,
124
+ value : "complexity desc " ,
125
125
} ,
126
126
] ;
You can’t perform that action at this time.
0 commit comments