mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 14:39:34 +01:00
core: fix sorting of newly created notes
This commit is contained in:
@@ -51,7 +51,7 @@ const formats = {
|
|||||||
year: "%Y",
|
year: "%Y",
|
||||||
week: "%Y-%W",
|
week: "%Y-%W",
|
||||||
abc: null,
|
abc: null,
|
||||||
default: null,
|
default: "%Y-%W",
|
||||||
none: null
|
none: null
|
||||||
} satisfies Record<GroupOptions["groupBy"], string | null>;
|
} satisfies Record<GroupOptions["groupBy"], string | null>;
|
||||||
|
|
||||||
@@ -505,9 +505,10 @@ export class FilteredSelector<T extends Item> {
|
|||||||
return <T>(
|
return <T>(
|
||||||
qb: SelectQueryBuilder<DatabaseSchema, keyof DatabaseSchema, T>
|
qb: SelectQueryBuilder<DatabaseSchema, keyof DatabaseSchema, T>
|
||||||
) => {
|
) => {
|
||||||
if (this.type === "notes") qb = qb.orderBy("conflicted desc");
|
if (this.type === "notes")
|
||||||
|
qb = qb.orderBy(sql`IFNULL(conflicted, 0) desc`);
|
||||||
if (this.type === "notes" || this.type === "notebooks")
|
if (this.type === "notes" || this.type === "notebooks")
|
||||||
qb = qb.orderBy("pinned desc");
|
qb = qb.orderBy(sql`IFNULL(pinned, 0) desc`);
|
||||||
|
|
||||||
for (const item of sortBy) {
|
for (const item of sortBy) {
|
||||||
if (item === "title") {
|
if (item === "title") {
|
||||||
@@ -521,7 +522,7 @@ export class FilteredSelector<T extends Item> {
|
|||||||
const timeFormat = isGroupOptions(options)
|
const timeFormat = isGroupOptions(options)
|
||||||
? formats[options.groupBy]
|
? formats[options.groupBy]
|
||||||
: null;
|
: null;
|
||||||
if (!timeFormat) {
|
if (!timeFormat || isSortByDate(options)) {
|
||||||
qb = qb.orderBy(item, options.sortDirection);
|
qb = qb.orderBy(item, options.sortDirection);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -559,3 +560,13 @@ function isGroupOptions(
|
|||||||
): options is GroupOptions {
|
): options is GroupOptions {
|
||||||
return "groupBy" in options;
|
return "groupBy" in options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSortByDate(options: SortOptions | GroupOptions) {
|
||||||
|
return (
|
||||||
|
options.sortBy === "dateCreated" ||
|
||||||
|
options.sortBy === "dateEdited" ||
|
||||||
|
options.sortBy === "dateDeleted" ||
|
||||||
|
options.sortBy === "dateModified" ||
|
||||||
|
options.sortBy === "dateUploaded"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user