From dee4ad8794f3f146eab49d94606d46025ee8989c Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 2 Aug 2024 20:57:55 +0200 Subject: [PATCH] Make 'sortWorldInfoEntries' custom sortable --- public/scripts/world-info.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 6c9bd5304..7a227e8ba 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1642,13 +1642,15 @@ function getWIElement(name) { * Sorts the given data based on the selected sort option * * @param {any[]} data WI entries + * @param {object} [options={}] - Optional arguments + * @param {{sortField?: string, sortOrder?: string, sortRule?: string}} [options.customSort={}] - Custom sort options, instead of the chosen UI sort * @returns {any[]} Sorted data */ -export function sortWorldInfoEntries(data) { +export function sortWorldInfoEntries(data, { customSort = null } = {}) { const option = $('#world_info_sort_order').find(':selected'); - const sortField = option.data('field'); - const sortOrder = option.data('order'); - const sortRule = option.data('rule'); + const sortField = customSort.sortField ?? option.data('field'); + const sortOrder = customSort.sortOrder ?? option.data('order'); + const sortRule = customSort.sortRule ?? option.data('rule'); const orderSign = sortOrder === 'asc' ? 1 : -1; if (!data.length) return data;