From dc06e2da99b21872a2c7fb423ea38fe0b1340db4 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Tue, 23 Mar 2021 13:52:32 +0800 Subject: [PATCH] getSearchQueryString: add "sort_by" options --- flow-typed/search.js | 3 +++ ui/constants/search.js | 3 +++ ui/util/query-params.js | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/flow-typed/search.js b/flow-typed/search.js index d762fd9e5..e1fa45f27 100644 --- a/flow-typed/search.js +++ b/flow-typed/search.js @@ -14,6 +14,9 @@ declare type SearchOptions = { MEDIA_TEXT: string, MEDIA_IMAGE: string, MEDIA_APPLICATION: string, + SORT: string, + SORT_ACCENDING: string, + SORT_DESCENDING: string, }; declare type SearchState = { diff --git a/ui/constants/search.js b/ui/constants/search.js index c6dcfa628..b0d28faee 100644 --- a/ui/constants/search.js +++ b/ui/constants/search.js @@ -21,4 +21,7 @@ export const SEARCH_OPTIONS = { MEDIA_TEXT: 'text', MEDIA_IMAGE: 'image', MEDIA_APPLICATION: 'application', + SORT: 'sort_by', + SORT_ACCENDING: '^release_time', + SORT_DESCENDING: 'release_time', }; diff --git a/ui/util/query-params.js b/ui/util/query-params.js index 1c54dd602..371370c70 100644 --- a/ui/util/query-params.js +++ b/ui/util/query-params.js @@ -65,11 +65,17 @@ export const getSearchQueryString = (query: string, options: any = {}) => { ); } } + + const sortBy = options[SEARCH_OPTIONS.SORT]; + if (sortBy) { + queryParams.push(`${SEARCH_OPTIONS.SORT}=${sortBy}`); + } } const additionalOptions = {}; const { related_to } = options; const { nsfw } = options; + if (related_to) additionalOptions['related_to'] = related_to; if (nsfw === false) additionalOptions['nsfw'] = false;