Backend for sorting by create date field

This commit is contained in:
Cohee 2023-08-31 19:30:56 +03:00
parent c19eb3146f
commit 4f1130260c
1 changed files with 6 additions and 1 deletions

View File

@ -30,7 +30,7 @@ import {
import { registerSlashCommand } from "./slash-commands.js"; import { registerSlashCommand } from "./slash-commands.js";
import { tokenizers } from "./tokenizers.js"; import { tokenizers } from "./tokenizers.js";
import { countOccurrences, delay, isOdd, resetScrollHeight } from "./utils.js"; import { countOccurrences, delay, isOdd, resetScrollHeight, sortMoments, timestampToMoment } from "./utils.js";
export { export {
loadPowerUserSettings, loadPowerUserSettings,
@ -1165,6 +1165,11 @@ const compareFunc = (first, second) => {
case 'boolean': case 'boolean':
const a = first[power_user.sort_field]; const a = first[power_user.sort_field];
const b = second[power_user.sort_field]; const b = second[power_user.sort_field];
if (power_user.sort_field === 'create_date') {
return sortMoments(timestampToMoment(a), timestampToMoment(b));
}
if (a === true || a === 'true') return 1; // Prioritize 'true' or true if (a === true || a === 'true') return 1; // Prioritize 'true' or true
if (b === true || b === 'true') return -1; // Prioritize 'true' or true if (b === true || b === 'true') return -1; // Prioritize 'true' or true
if (a && !b) return -1; // Move truthy values to the end if (a && !b) return -1; // Move truthy values to the end