Skip to content

Commit

Permalink
fix: daily log adapted to logseq 0.8.0 New data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed Aug 12, 2022
1 parent 315dfc8 commit 1d25bf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/util/baseInfo.ts
Expand Up @@ -107,6 +107,7 @@ export const getDefaultCalendarOptions = async () => {
export const genDailyLogCalendarOptions = (defaultOptions) => {
return {
...defaultOptions,
isReadOnly: true,
defaultView: 'week',
taskView: ['time'],
}
Expand Down
32 changes: 19 additions & 13 deletions src/util/schedule.ts
Expand Up @@ -69,19 +69,25 @@ export const getDailyLogSchedules = async () => {
const { logKey, defaultDuration } = getInitalSettings()
if (!logKey?.enabled) return []
const logs = await logseq.DB.q(`[[${logKey.id}]]`)
const _logs = logs
?.filter(block => {
if (block.headingLevel && block.format === 'markdown') {
block.content = block.content.replace(new RegExp(`^#{${block.headingLevel}} `), '')
}
return block.content?.trim() === `[[${logKey.id}]]`
})
?.map(block => Array.isArray(block.parent) ? block.parent : [])
?.flat()
?.filter(block => {
const _content = block.content?.trim()
return _content.length > 0 && block?.page?.journalDay && !block.marker && !block.scheduled && !block.deadline
}) || []
// logseq 0.8.0 modified the structure of the query return data
// const _logs = logs
// ?.filter(block => {
// if (block.headingLevel && block.format === 'markdown') {
// block.content = block.content.replace(new RegExp(`^#{${block.headingLevel}} `), '')
// }
// return block.content?.trim() === `[[${logKey.id}]]`
// })
// ?.map(block => Array.isArray(block.parent) ? block.parent : [])
// ?.flat()
// ?.filter(block => {
// const _content = block.content?.trim()
// return _content.length > 0 && block?.page?.journalDay && !block.marker && !block.scheduled && !block.deadline
// }) || []
const _logs = logs?.filter(block => {
// Interstitial Journal requries filter task
if (block?.marker || !block?.page?.journalDay) return false
return TIME_REG.test(block?.content)
}) || []
const _logSchedulePromises = _logs?.map(async block => {
const date = block?.page?.journalDay
const { start: _startTime, end: _endTime } = getTimeInfo(block?.content.replace(new RegExp(`^${block.marker} `), ''))
Expand Down

0 comments on commit 1d25bf9

Please sign in to comment.