A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: fix sorting of newly created notes
Abdullah Atta72d5072cacaa
diff --git a/packages/core/src/database/sql-collection.ts b/packages/core/src/database/sql-collection.tsindex ec76b9b09..83cf0c2e9 100644--- a/packages/core/src/database/sql-collection.ts+++ b/packages/core/src/database/sql-collection.ts@@ -51,7 +51,7 @@ const formats = {year: "%Y",week: "%Y-%W",abc: null,- default: null,+ default: "%Y-%W",none: null} satisfies Record<GroupOptions["groupBy"], string | null>;@@ -505,9 +505,10 @@ export class FilteredSelector<T extends Item> {return <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")- qb = qb.orderBy("pinned desc");+ qb = qb.orderBy(sql`IFNULL(pinned, 0) desc`);for (const item of sortBy) {if (item === "title") {@@ -521,7 +522,7 @@ export class FilteredSelector<T extends Item> {const timeFormat = isGroupOptions(options)? formats[options.groupBy]: null;- if (!timeFormat) {+ if (!timeFormat || isSortByDate(options)) {qb = qb.orderBy(item, options.sortDirection);continue;}@@ -559,3 +560,13 @@ function isGroupOptions(): options is GroupOptions {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"+ );+}