Sort next tasks query in reverse order (upcoming -> future)

I have a default journal query that shows tasks on journal pages for the upcoming seven days. It currently sorts in descending order so the tasks upcoming in seven days (Dec 21, Dec 20, Dec 19, etc) sit above those due tomorrow.

I’d like to reverse the sort order (eg Dec 16, Dec 17, Dec 18, Dec 19, etc). I’ve tried a few different things using result-transform but never been able to figure it out.

Query and a screenshot of the current behavior below. Thanks for any assistance!

   {:title [:h3 "📅 Next"]
    :query [:find (pull ?block [*])
            :in $ ?start ?next
            :where
            [?block :block/marker ?marker]
            [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
            [?block :block/page ?p]
            [?p :block/journal? true]
            [?p :block/journal-day ?d]
            [(> ?d ?start)]
            [(< ?d ?next)]]
    :inputs [:today :7d-after]
    :breadcrumb-show? false
    :collapsed? true}

1 Like

I don’t know if you need the page blocks or not, but this result-transform will do the sorting you are looking for. Except that it will just be a list of tasks.
:result-transform (fn [result] (sort-by (fn [h] (get-in h [:block/page :block/journal-day])) result))
image

2 Likes