Skip to content

Commit

Permalink
Default to the current day when on the journals (undefined pageEnti…
Browse files Browse the repository at this point in the history
…ty) or home (`null` pageEntity) page.

#3
  • Loading branch information
isosphere committed Jan 19, 2024
1 parent a7fb8c5 commit 8c2fc8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "logseq-journals-nextprev",
"description": "Provides buttons to jump to the next or previous journal entry",
"version": "1.0.4",
"version": "1.1.0",
"main": "dist/index.html",
"author": "Matthew Scheffel",
"scripts": {
Expand Down
25 changes: 15 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@
let pageEntity = await logseq.Editor.getCurrentPage()
let journalDay = pageEntity?.journalDay
if (!journalDay) {
console.error('Not a journal page')
return
}
if (journalDay === "undefined" || pageEntity === null) {
// Set currentJournalDate to the current date expressed as a "YYYYMMDD" string
let currentDate = new Date()
let year = currentDate.getFullYear()
let month = String(currentDate.getMonth() + 1).padStart(2, '0')
let day = String(currentDate.getDate()).padStart(2, '0')
journalDay = `${year}${month}${day}`
}
return journalDay;
},
Expand All @@ -75,33 +79,34 @@
let currentJournalDate = await this._getCurrentJournalDate()
if (typeof currentJournalDate === 'undefined') {
return
return;
}
let journals = await this._getOlderJournals(currentJournalDate)
let prev_day = Math.max(...Object.keys(journals).map(Number))
if (!journals[prev_day]) {
return
return;
}
return journals[prev_day]['name']
},
async _nextDay() {
let currentJournalDate = await this._getCurrentJournalDate()
if (typeof currentJournalDate === 'undefined') {
return
return;
}
let journals = await this._getNewerJournals(currentJournalDate)
let next_day = Math.min(...Object.keys(journals).map(Number))
if (!journals[next_day]) {
return
return;
}
return journals[next_day]['name']
return journals[next_day]['name'];
}
},
}
Expand Down

0 comments on commit 8c2fc8b

Please sign in to comment.