Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ const { remote } = require('electron')
const { dialog } = remote
const WP_POST_PATH = '/wp/v2/posts'

const regexMatchStartingTitleNumber = new RegExp('^([0-9]*\.?[0-9]+).*$')

function sortByCreatedAt (a, b) {
return new Date(b.createdAt) - new Date(a.createdAt)
}

function sortByAlphabetical (a, b) {
const matchA = regexMatchStartingTitleNumber.exec(a.title)
const matchB = regexMatchStartingTitleNumber.exec(b.title)

if (matchA && matchA.length === 2 && matchB && matchB.length === 2) {
// Both note titles are starting with a float. We will compare it now.
const floatA = parseFloat(matchA[1])
const floatB = parseFloat(matchB[1])

const diff = floatA - floatB
if (diff !== 0) {
return diff
}

// The float values are equal. We will compare the full title.
}

return a.title.localeCompare(b.title)
}

Expand Down