Skip to content

Commit 66a5ab4

Browse files
authored
feat(requestlist): sort direction (fallenbagel#1147)
* feat(requestlist): sort direction * style: quoted attributes * style: quoted attributes
1 parent 7c734bc commit 66a5ab4

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

overseerr-api.yml

+6
Original file line numberDiff line numberDiff line change
@@ -5438,6 +5438,12 @@ paths:
54385438
type: string
54395439
enum: [added, modified]
54405440
default: added
5441+
- in: query
5442+
name: sortDirection
5443+
schema:
5444+
type: string
5445+
enum: [asc, desc]
5446+
default: desc
54415447
- in: query
54425448
name: requestedBy
54435449
schema:

server/routes/request.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ requestRoutes.get<Record<string, unknown>, RequestResultsResponse>(
9494
}
9595

9696
let sortFilter: string;
97+
let sortDirection: 'ASC' | 'DESC';
9798

9899
switch (req.query.sort) {
99100
case 'modified':
@@ -103,6 +104,14 @@ requestRoutes.get<Record<string, unknown>, RequestResultsResponse>(
103104
sortFilter = 'request.id';
104105
}
105106

107+
switch (req.query.sortDirection) {
108+
case 'asc':
109+
sortDirection = 'ASC';
110+
break;
111+
default:
112+
sortDirection = 'DESC';
113+
}
114+
106115
let query = getRepository(MediaRequest)
107116
.createQueryBuilder('request')
108117
.leftJoinAndSelect('request.media', 'media')
@@ -142,7 +151,7 @@ requestRoutes.get<Record<string, unknown>, RequestResultsResponse>(
142151
}
143152

144153
const [requests, requestCount] = await query
145-
.orderBy(sortFilter, 'DESC')
154+
.orderBy(sortFilter, sortDirection)
146155
.take(pageSize)
147156
.skip(skip)
148157
.getManyAndCount();

src/components/RequestList/index.tsx

+33-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import Button from '@app/components/Common/Button';
22
import Header from '@app/components/Common/Header';
33
import LoadingSpinner from '@app/components/Common/LoadingSpinner';
44
import PageTitle from '@app/components/Common/PageTitle';
5+
import Tooltip from '@app/components/Common/Tooltip';
56
import RequestItem from '@app/components/RequestList/RequestItem';
67
import { useUpdateQueryParams } from '@app/hooks/useUpdateQueryParams';
78
import { useUser } from '@app/hooks/useUser';
89
import globalMessages from '@app/i18n/globalMessages';
910
import defineMessages from '@app/utils/defineMessages';
1011
import {
11-
BarsArrowDownIcon,
12+
ArrowDownIcon,
13+
ArrowUpIcon,
14+
Bars3BottomLeftIcon,
1215
ChevronLeftIcon,
1316
ChevronRightIcon,
1417
FunnelIcon,
@@ -25,6 +28,7 @@ const messages = defineMessages('components.RequestList', {
2528
showallrequests: 'Show All Requests',
2629
sortAdded: 'Most Recent',
2730
sortModified: 'Last Modified',
31+
sortDirection: 'Toggle Sort Direction',
2832
});
2933

3034
enum Filter {
@@ -39,6 +43,8 @@ enum Filter {
3943

4044
type Sort = 'added' | 'modified';
4145

46+
type SortDirection = 'asc' | 'desc';
47+
4248
const RequestList = () => {
4349
const router = useRouter();
4450
const intl = useIntl();
@@ -48,6 +54,8 @@ const RequestList = () => {
4854
const { user: currentUser } = useUser();
4955
const [currentFilter, setCurrentFilter] = useState<Filter>(Filter.PENDING);
5056
const [currentSort, setCurrentSort] = useState<Sort>('added');
57+
const [currentSortDirection, setCurrentSortDirection] =
58+
useState<SortDirection>('desc');
5159
const [currentPageSize, setCurrentPageSize] = useState<number>(10);
5260

5361
const page = router.query.page ? Number(router.query.page) : 1;
@@ -61,7 +69,7 @@ const RequestList = () => {
6169
} = useSWR<RequestResultsResponse>(
6270
`/api/v1/request?take=${currentPageSize}&skip=${
6371
pageIndex * currentPageSize
64-
}&filter=${currentFilter}&sort=${currentSort}${
72+
}&filter=${currentFilter}&sort=${currentSort}&sortDirection=${currentSortDirection}${
6573
router.pathname.startsWith('/profile')
6674
? `&requestedBy=${currentUser?.id}`
6775
: router.query.userId
@@ -79,6 +87,7 @@ const RequestList = () => {
7987

8088
setCurrentFilter(filterSettings.currentFilter);
8189
setCurrentSort(filterSettings.currentSort);
90+
setCurrentSortDirection(filterSettings.currentSortDirection);
8291
setCurrentPageSize(filterSettings.currentPageSize);
8392
}
8493

@@ -95,10 +104,11 @@ const RequestList = () => {
95104
JSON.stringify({
96105
currentFilter,
97106
currentSort,
107+
currentSortDirection,
98108
currentPageSize,
99109
})
100110
);
101-
}, [currentFilter, currentSort, currentPageSize]);
111+
}, [currentFilter, currentSort, currentSortDirection, currentPageSize]);
102112

103113
if (!data && !error) {
104114
return <LoadingSpinner />;
@@ -182,7 +192,7 @@ const RequestList = () => {
182192
</div>
183193
<div className="mb-2 flex flex-grow sm:mb-0 lg:flex-grow-0">
184194
<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" />
186196
</span>
187197
<select
188198
id="sort"
@@ -197,7 +207,7 @@ const RequestList = () => {
197207
});
198208
}}
199209
value={currentSort}
200-
className="rounded-r-only"
210+
className="rounded-none border-r-0"
201211
>
202212
<option value="added">
203213
{intl.formatMessage(messages.sortAdded)}
@@ -206,6 +216,24 @@ const RequestList = () => {
206216
{intl.formatMessage(messages.sortModified)}
207217
</option>
208218
</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>
209237
</div>
210238
</div>
211239
</div>

src/i18n/locale/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@
503503
"components.RequestList.requests": "Requests",
504504
"components.RequestList.showallrequests": "Show All Requests",
505505
"components.RequestList.sortAdded": "Most Recent",
506+
"components.RequestList.sortDirection": "Toggle Sort Direction",
506507
"components.RequestList.sortModified": "Last Modified",
507508
"components.RequestModal.AdvancedRequester.advancedoptions": "Advanced",
508509
"components.RequestModal.AdvancedRequester.animenote": "* This series is an anime.",
@@ -1099,7 +1100,7 @@
10991100
"components.Setup.finishing": "Finishing…",
11001101
"components.Setup.servertype": "Choose Server Type",
11011102
"components.Setup.setup": "Setup",
1102-
"components.Setup.signin": "Sign in to your account",
1103+
"components.Setup.signin": "Sign In",
11031104
"components.Setup.signinMessage": "Get started by signing in",
11041105
"components.Setup.signinWithEmby": "Enter your Emby details",
11051106
"components.Setup.signinWithJellyfin": "Enter your Jellyfin details",

0 commit comments

Comments
 (0)