feat: Show drafts in sidebar when viewing (#2820)

This commit is contained in:
Tom Moor
2021-12-11 09:34:36 -08:00
committed by GitHub
parent e5b4186faa
commit 7aa4709e69
39 changed files with 445 additions and 246 deletions

View File

@@ -6,6 +6,7 @@ type NaturalSortOptions = {
caseSensitive?: boolean;
direction?: "asc" | "desc";
};
const sorter = naturalSort();
const regex = emojiRegex();
@@ -13,15 +14,14 @@ const stripEmojis = (value: string) => value.replace(regex, "");
const cleanValue = (value: string) => stripEmojis(deburr(value));
function getSortByField<T extends Record<string, any>>(
function getSortByField<T>(
item: T,
keyOrCallback: string | (() => string)
keyOrCallback: string | ((item: T) => string)
) {
const field =
typeof keyOrCallback === "string"
? item[keyOrCallback]
: // @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
keyOrCallback(item);
: keyOrCallback(item);
return cleanValue(field);
}
@@ -31,10 +31,14 @@ function naturalSortBy<T>(
sortOptions?: NaturalSortOptions
): T[] {
if (!items) return [];
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'NaturalSortOptions' is not assig... Remove this comment to see the full error message
const sort = sortOptions ? naturalSort(sortOptions) : sorter;
return items.sort((a: any, b: any): -1 | 0 | 1 =>
// @ts-expect-error ts-migrate(2322) FIXME: Type 'number' is not assignable to type '0 | 1 | -... Remove this comment to see the full error message
const sort = sortOptions
? naturalSort({
caseSensitive: sortOptions.caseSensitive,
direction: sortOptions.direction === "desc" ? "desc" : undefined,
})
: sorter;
return items.sort((a: T, b: T) =>
sort(getSortByField(a, key), getSortByField(b, key))
);
}