This commit is contained in:
Julian Freeman
2026-04-16 14:13:06 -04:00
parent 53287eabff
commit 0b46db0b43

View File

@@ -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) { export function compareProfileId(left: string, right: string) {
const leftKey = profileSortKeyValue(left); const leftKey = profileSortKeyValue(left);
const rightKey = profileSortKeyValue(right); const rightKey = profileSortKeyValue(right);
@@ -27,7 +41,7 @@ export function sortProfiles(items: ProfileSummary[], sortKey: ProfileSortKey) {
return profiles.sort((left, right) => { return profiles.sort((left, right) => {
if (sortKey === "email") { if (sortKey === "email") {
return ( return (
compareText(left.email ?? "", right.email ?? "") || compareOptionalText(left.email, right.email) ||
compareText(left.name, right.name) || compareText(left.name, right.name) ||
compareProfileId(left.id, right.id) compareProfileId(left.id, right.id)
); );
@@ -53,9 +67,9 @@ export function sortBookmarks(items: BookmarkSummary[], sortKey: BookmarkSortKey
const bookmarks = [...items]; const bookmarks = [...items];
return bookmarks.sort((left, right) => { return bookmarks.sort((left, right) => {
if (sortKey === "url") { 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);
}); });
} }