@@ -2,13 +2,16 @@ import Button from '@app/components/Common/Button';
2
2
import Header from '@app/components/Common/Header' ;
3
3
import LoadingSpinner from '@app/components/Common/LoadingSpinner' ;
4
4
import PageTitle from '@app/components/Common/PageTitle' ;
5
+ import Tooltip from '@app/components/Common/Tooltip' ;
5
6
import RequestItem from '@app/components/RequestList/RequestItem' ;
6
7
import { useUpdateQueryParams } from '@app/hooks/useUpdateQueryParams' ;
7
8
import { useUser } from '@app/hooks/useUser' ;
8
9
import globalMessages from '@app/i18n/globalMessages' ;
9
10
import defineMessages from '@app/utils/defineMessages' ;
10
11
import {
11
- BarsArrowDownIcon ,
12
+ ArrowDownIcon ,
13
+ ArrowUpIcon ,
14
+ Bars3BottomLeftIcon ,
12
15
ChevronLeftIcon ,
13
16
ChevronRightIcon ,
14
17
FunnelIcon ,
@@ -25,6 +28,7 @@ const messages = defineMessages('components.RequestList', {
25
28
showallrequests : 'Show All Requests' ,
26
29
sortAdded : 'Most Recent' ,
27
30
sortModified : 'Last Modified' ,
31
+ sortDirection : 'Toggle Sort Direction' ,
28
32
} ) ;
29
33
30
34
enum Filter {
@@ -39,6 +43,8 @@ enum Filter {
39
43
40
44
type Sort = 'added' | 'modified' ;
41
45
46
+ type SortDirection = 'asc' | 'desc' ;
47
+
42
48
const RequestList = ( ) => {
43
49
const router = useRouter ( ) ;
44
50
const intl = useIntl ( ) ;
@@ -48,6 +54,8 @@ const RequestList = () => {
48
54
const { user : currentUser } = useUser ( ) ;
49
55
const [ currentFilter , setCurrentFilter ] = useState < Filter > ( Filter . PENDING ) ;
50
56
const [ currentSort , setCurrentSort ] = useState < Sort > ( 'added' ) ;
57
+ const [ currentSortDirection , setCurrentSortDirection ] =
58
+ useState < SortDirection > ( 'desc' ) ;
51
59
const [ currentPageSize , setCurrentPageSize ] = useState < number > ( 10 ) ;
52
60
53
61
const page = router . query . page ? Number ( router . query . page ) : 1 ;
@@ -61,7 +69,7 @@ const RequestList = () => {
61
69
} = useSWR < RequestResultsResponse > (
62
70
`/api/v1/request?take=${ currentPageSize } &skip=${
63
71
pageIndex * currentPageSize
64
- } &filter=${ currentFilter } &sort=${ currentSort } ${
72
+ } &filter=${ currentFilter } &sort=${ currentSort } &sortDirection= ${ currentSortDirection } ${
65
73
router . pathname . startsWith ( '/profile' )
66
74
? `&requestedBy=${ currentUser ?. id } `
67
75
: router . query . userId
@@ -79,6 +87,7 @@ const RequestList = () => {
79
87
80
88
setCurrentFilter ( filterSettings . currentFilter ) ;
81
89
setCurrentSort ( filterSettings . currentSort ) ;
90
+ setCurrentSortDirection ( filterSettings . currentSortDirection ) ;
82
91
setCurrentPageSize ( filterSettings . currentPageSize ) ;
83
92
}
84
93
@@ -95,10 +104,11 @@ const RequestList = () => {
95
104
JSON . stringify ( {
96
105
currentFilter,
97
106
currentSort,
107
+ currentSortDirection,
98
108
currentPageSize,
99
109
} )
100
110
) ;
101
- } , [ currentFilter , currentSort , currentPageSize ] ) ;
111
+ } , [ currentFilter , currentSort , currentSortDirection , currentPageSize ] ) ;
102
112
103
113
if ( ! data && ! error ) {
104
114
return < LoadingSpinner /> ;
@@ -182,7 +192,7 @@ const RequestList = () => {
182
192
</ div >
183
193
< div className = "mb-2 flex flex-grow sm:mb-0 lg:flex-grow-0" >
184
194
< span className = "inline-flex cursor-default items-center rounded-l-md border border-r-0 border-gray-500 bg-gray-800 px-3 text-gray-100 sm:text-sm" >
185
- < BarsArrowDownIcon className = "h-6 w-6" />
195
+ < Bars3BottomLeftIcon className = "h-6 w-6" />
186
196
</ span >
187
197
< select
188
198
id = "sort"
@@ -197,7 +207,7 @@ const RequestList = () => {
197
207
} ) ;
198
208
} }
199
209
value = { currentSort }
200
- className = "rounded-r-only "
210
+ className = "rounded-none border-r-0 "
201
211
>
202
212
< option value = "added" >
203
213
{ intl . formatMessage ( messages . sortAdded ) }
@@ -206,6 +216,24 @@ const RequestList = () => {
206
216
{ intl . formatMessage ( messages . sortModified ) }
207
217
</ option >
208
218
</ select >
219
+ < Tooltip content = { intl . formatMessage ( messages . sortDirection ) } >
220
+ < Button
221
+ buttonType = "ghost"
222
+ className = "z-40 mr-2 rounded-l-none"
223
+ buttonSize = "md"
224
+ onClick = { ( ) =>
225
+ setCurrentSortDirection (
226
+ currentSortDirection === 'asc' ? 'desc' : 'asc'
227
+ )
228
+ }
229
+ >
230
+ { currentSortDirection === 'asc' ? (
231
+ < ArrowUpIcon className = "h-3" />
232
+ ) : (
233
+ < ArrowDownIcon className = "h-3" />
234
+ ) }
235
+ </ Button >
236
+ </ Tooltip >
209
237
</ div >
210
238
</ div >
211
239
</ div >
0 commit comments