op sort
This commit is contained in:
@@ -14,6 +14,20 @@ export function compareText(left: string, right: string) {
|
||||
});
|
||||
}
|
||||
|
||||
function compareOptionalText(left: string | null | undefined, right: string | null | undefined) {
|
||||
const leftValue = left?.trim() ?? "";
|
||||
const rightValue = right?.trim() ?? "";
|
||||
|
||||
const leftEmpty = leftValue.length === 0;
|
||||
const rightEmpty = rightValue.length === 0;
|
||||
|
||||
if (leftEmpty && rightEmpty) return 0;
|
||||
if (leftEmpty) return 1;
|
||||
if (rightEmpty) return -1;
|
||||
|
||||
return compareText(leftValue, rightValue);
|
||||
}
|
||||
|
||||
export function compareProfileId(left: string, right: string) {
|
||||
const leftKey = profileSortKeyValue(left);
|
||||
const rightKey = profileSortKeyValue(right);
|
||||
@@ -27,7 +41,7 @@ export function sortProfiles(items: ProfileSummary[], sortKey: ProfileSortKey) {
|
||||
return profiles.sort((left, right) => {
|
||||
if (sortKey === "email") {
|
||||
return (
|
||||
compareText(left.email ?? "", right.email ?? "") ||
|
||||
compareOptionalText(left.email, right.email) ||
|
||||
compareText(left.name, right.name) ||
|
||||
compareProfileId(left.id, right.id)
|
||||
);
|
||||
@@ -53,9 +67,9 @@ export function sortBookmarks(items: BookmarkSummary[], sortKey: BookmarkSortKey
|
||||
const bookmarks = [...items];
|
||||
return bookmarks.sort((left, right) => {
|
||||
if (sortKey === "url") {
|
||||
return compareText(left.url, right.url);
|
||||
return compareOptionalText(left.url, right.url) || compareText(left.title, right.title);
|
||||
}
|
||||
return compareText(left.title, right.title) || compareText(left.url, right.url);
|
||||
return compareOptionalText(left.title, right.title) || compareText(left.url, right.url);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user