From 4d2866c035a67d0ff2d36d63c187eafe1d2f6e33 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Sat, 2 Dec 2023 15:17:54 -0600 Subject: [PATCH] sort: need better defaulting since we switched from override --- ui/src/logic/channel.ts | 8 ++++++-- ui/src/logic/useMessageSort.ts | 6 +++++- ui/src/logic/useSidebarSort.ts | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ui/src/logic/channel.ts b/ui/src/logic/channel.ts index 53789d90e4..bcbf460d50 100644 --- a/ui/src/logic/channel.ts +++ b/ui/src/logic/channel.ts @@ -189,9 +189,13 @@ export function useChannelSort(defaultSort: SortMode = DEFAULT_SORT) { [RECENT_SORT]: (flag: string, _channel: GroupChannel) => flag, }; - return sortRecordsBy(channels, accessors[sortFn], sortFn === RECENT_SORT); + return sortRecordsBy( + channels, + accessors[sortFn] || accessors[defaultSort], + sortFn === RECENT_SORT + ); }, - [sortFn, sortRecordsBy] + [sortFn, defaultSort, sortRecordsBy] ); return { diff --git a/ui/src/logic/useMessageSort.ts b/ui/src/logic/useMessageSort.ts index decb1e91bd..95c7431e63 100644 --- a/ui/src/logic/useMessageSort.ts +++ b/ui/src/logic/useMessageSort.ts @@ -21,7 +21,11 @@ export default function useMessageSort() { [RECENT_SORT]: (flag: string, _unread: Unread | DMUnread) => flag, }; - return sortRecordsBy(unreads, accessors[sortFn], true); + return sortRecordsBy( + unreads, + accessors[sortFn] || accessors[RECENT_SORT], + true + ); } return { diff --git a/ui/src/logic/useSidebarSort.ts b/ui/src/logic/useSidebarSort.ts index 97cc114494..a9050ea0e0 100644 --- a/ui/src/logic/useSidebarSort.ts +++ b/ui/src/logic/useSidebarSort.ts @@ -6,7 +6,7 @@ import { } from '@/state/settings'; import { useUnreads } from '@/state/channel/channel'; import { useDmUnreads } from '@/state/chat'; -import { ALPHABETICAL_SORT, DEFAULT_SORT, SortMode } from '@/constants'; +import { DEFAULT_SORT, RECENT_SORT, SortMode } from '@/constants'; import { whomIsDm, whomIsMultiDm } from './utils'; export interface Sorter { @@ -110,7 +110,7 @@ export default function useSidebarSort({ const aVal = accessor(aKey, aObj); const bVal = accessor(bKey, bObj); - const sorter = sortOptions[sortFn] ?? sortOptions[ALPHABETICAL_SORT]; + const sorter = sortOptions[sortFn] ?? sortOptions[RECENT_SORT]; return sorter(aVal, bVal); });