Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function App() {
{settings.showNextNDaysTask && (
<TaskSection
title={`Next ${settings.numberOfNextNDays} Days`}
query={getNextNDaysTaskQuery(settings.numberOfNextNDays)}
query={getNextNDaysTaskQuery(settings.numberOfNextNDays, customMarkers, treatJournalEntriesAsScheduled)}
/>
)}
<TaskSection
Expand All @@ -120,8 +120,9 @@ function App() {
? getScheduledTaskQuery(
treatJournalEntriesAsScheduled,
dayjs().add(settings.numberOfNextNDays, 'd'),
customMarkers,
)
: getScheduledTaskQuery(treatJournalEntriesAsScheduled)
: getScheduledTaskQuery(treatJournalEntriesAsScheduled, undefined, customMarkers)
}
/>
<TaskSection
Expand Down
48 changes: 42 additions & 6 deletions src/querys/next-n-days.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
import dayjs from 'dayjs';

export default function getNextNDaysTaskQuery(days: number) {
export default function getNextNDaysTaskQuery(
days: number,
customMarkers: string[] = [],
treatJournalEntriesAsScheduled = true,
) {
const start = dayjs().format('YYYYMMDD');
const next = dayjs().add(days, 'd').format('YYYYMMDD');
const markers = customMarkers.map((m) => '"' + m + '"').join(' ');

const journalMarkerFilter = customMarkers.length > 0
? `(or
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
[(contains? #{${markers}} ?marker)])`
: `[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]`;

const journalEntryCond = treatJournalEntriesAsScheduled ? `
(and
${journalMarkerFilter}
[?p :block/journal? true]
[?p :block/journal-day ?d]
(not [?b :block/scheduled])
(not [?b :block/deadline])
[(> ?d ${start})]
[(<= ?d ${next})])
` : '';

const customMarkerScheduledCond = customMarkers.length > 0 ? `
(and
[(contains? #{${markers}} ?marker)]
(or
[?b :block/scheduled ?d]
[?b :block/deadline ?d])
[(> ?d ${start})]
[(<= ?d ${next})])
` : '';

const query = `
[:find (pull ?b [*])
:where
[?b :block/marker ?marker]
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
[?b :block/page ?p]
(or
[?b :block/scheduled ?d]
[?b :block/deadline ?d])
[(> ?d ${start})]]
[(> ?d ${next})]]
(and
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
(or
[?b :block/scheduled ?d]
[?b :block/deadline ?d])
[(> ?d ${start})]
[(<= ?d ${next})])
${journalEntryCond}
${customMarkerScheduledCond})]
`;
return query;
}
10 changes: 9 additions & 1 deletion src/querys/scheduled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@ import dayjs, { Dayjs } from 'dayjs';
export default function getScheduledTaskQuery(
treatJournalEntriesAsScheduled = true,
startDate: Dayjs | Date = new Date(),
customMarkers: string[] = [],
) {
const start = dayjs(startDate).format('YYYYMMDD');
const markers = customMarkers.map((m) => '"' + m + '"').join(' ');

const journalEntryCond = treatJournalEntriesAsScheduled ? `
(and
[?p :block/journal? true]
[?p :block/journal-day ?d])` : '';

const markerFilter = customMarkers.length > 0
? `(or
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
[(contains? #{${markers}} ?marker)])`
: `[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]`;

const query = `
[:find (pull ?b [*])
:where
[?b :block/marker ?marker]
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
${markerFilter}
[?b :block/page ?p]
(or
(or
Expand Down
13 changes: 12 additions & 1 deletion src/querys/today.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export default function getTodayTaskQuery(
[(<= ?d ${today})])
` : '';

const customMarkerJournalCond = customMarkers.length > 0 && treatJournalEntriesAsScheduled ? `
(and
[(contains? #{${markers}} ?marker)]
[?p :block/journal? true]
[?p :block/journal-day ?d]
(not [?b :block/scheduled])
(not [?b :block/deadline])
[(<= ?d ${today})])
` : '';

const query = `
[:find (pull ?b [*])
:where
Expand All @@ -39,7 +49,8 @@ export default function getTodayTaskQuery(
[?b :block/deadline ?d])
[(<= ?d ${today})])
${journalEntryCond}
${customMarkerCond})]
${customMarkerCond}
${customMarkerJournalCond})]
`;

return query;
Expand Down