Skip to content

Commit

Permalink
Fix #66: order entry in TL by date instead of time of creation
Browse files Browse the repository at this point in the history
  • Loading branch information
agateblue committed Oct 8, 2023
1 parent 6c2761c commit 7eab17b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/components/EntryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function getFormData (entry, formData) {
function toLocal(date) {
var local = new Date(date)
local.setMinutes(date.getMinutes() - date.getTimezoneOffset())
local.setMinutes(local.getMinutes() - local.getTimezoneOffset())
return local.toJSON().slice(0, 16)
}
Expand Down Expand Up @@ -258,15 +258,23 @@ export default {
if (!v) {
this.textDate = null
} else {
if (this.textDate && toLocal(this.textDate) === toLocal(v)) {
return
}
this.textDate = toLocal(v)
}
},
immediate: true,
},
textDate: {
handler (v) {
if (v && toLocal != toLocal(this.date)) {
this.date = new Date(v)
// if no seconds, we add them manually and random microseconds
if (v && v.length <=16) {
v = v.slice(0, 16)
v = `${v}:00`
}
if (v && toLocal(this.date) != toLocal(v)) {
this.date = new Date(toLocal(v))
}
},
immediate: true,
Expand Down
16 changes: 15 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,25 @@ export async function getEntries (store, sortDesc) {
console.time('getEntries')
let options = {
include_docs: true,
descending: sortDesc
}
let result = await store.state.db.allDocs(options)
let entries = result.rows.flatMap(r => r.doc.type === 'entry' ? [r.doc] : [])
entries.forEach(e => {
e.date = e.date || e._id
})
sortEntries(entries, sortDesc)
console.timeEnd('getEntries')

return entries
}

export function sortEntries (entries, sortDesc) {
entries.sort((a, b) => {
return new Date(a.date) - new Date(b.date)
})
if (sortDesc) {
entries.reverse()
}
return entries
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/Diary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default {
},
methods: {
async handleCreated (entry) {
this.entries.push(entry)
async handleCreated () {
await this.search()
trackEvent(this.$store, "entry.created")
},
async handleDelete (entry) {
Expand Down

0 comments on commit 7eab17b

Please sign in to comment.