From 69b1dc7103c2ef425c9ee1c9e1741185bdec2ade Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Wed, 27 Oct 2021 17:16:03 +0200 Subject: [PATCH] feat!: use `ItemList` for the DiscussionListState sorting map --- js/src/forum/states/DiscussionListState.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/js/src/forum/states/DiscussionListState.ts b/js/src/forum/states/DiscussionListState.ts index 6f687c83a..ec408a533 100644 --- a/js/src/forum/states/DiscussionListState.ts +++ b/js/src/forum/states/DiscussionListState.ts @@ -1,6 +1,7 @@ import app from '../../forum/app'; import PaginatedListState, { Page } from '../../common/states/PaginatedListState'; import Discussion from '../../common/models/Discussion'; +import ItemList from '../../common/utils/ItemList'; export default class DiscussionListState extends PaginatedListState { protected extraDiscussions: Discussion[] = []; @@ -45,21 +46,22 @@ export default class DiscussionListState extends PaginatedListState } /** - * Get a map of sort keys (which appear in the URL, and are used for + * Get a list of sort keys (which appear in the URL, and are used for * translation) to the API sort value that they represent. */ - sortMap() { - const map: any = {}; + sortMap(): ItemList { + const sortItems = new ItemList(); if (this.params.q) { - map.relevance = ''; + sortItems.add('relevance', '', 100); } - map.latest = '-lastPostedAt'; - map.top = '-commentCount'; - map.newest = '-createdAt'; - map.oldest = 'createdAt'; - return map; + sortItems.add('latest', '-lastPostedAt', 80); + sortItems.add('top', '-commentCount', 60); + sortItems.add('newest', '-createdAt', 40); + sortItems.add('oldest', 'createdAt', 20); + + return sortItems; } /**