Skip to content

Commit

Permalink
sort: need better defaulting since we switched from override
Browse files Browse the repository at this point in the history
  • Loading branch information
arthyn committed Dec 2, 2023
1 parent a22793e commit 4d2866c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ui/src/logic/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion ui/src/logic/useMessageSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/logic/useSidebarSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit 4d2866c

Please sign in to comment.