Sort journals by date (oldest first) but view with group-by-page?

I managed to sort journals by date in the reverse order, but this could not work with the pretty :group-by-page? true option. Is it possible sort journals by date (oldest first) but still view the results grouped by page?

 {:title "Reverse sort"
  :query [:find (pull ?b [*])
          :in $ ?start ?today
          :where
          (between ?b ?start ?today)]
  :inputs [:-7d :today]
  :result-transform (fn [result] (reverse (sort-by (fn [h] (get h :block/journal-day)) result)))
  :collapsed? false
  :group-by-page? false
  :table-view? false
  :breadcrumb-show? true
}

Another attempt that can list the links to the pages but does not show page contents

#+BEGIN_QUERY
 {:title "Q"
  :query [:find ?name
       :in $ ?start ?today
       :where
       [?p :block/journal-day ?d]
       [(>= ?d ?start)]
       [(<= ?d ?today)]
       [?p :block/name ?name]]
  :inputs [:-7d :today]
  :view (fn [result]
        [:div.flex.flex-col
         (for [page result]
           [:a {:href (str "#/page/" page)} (clojure.string/capitalize page)])])}
}
#+END_QUERY

No, this is unfortunately not possible.
Also small correction for your result-transform:
:result-transform (fn [result] (reverse (sort-by (fn [h] (get-in h [:block/page :block/journal-day])) result)))

I don’t know exactly what you wish to achieve. Maybe there’s a different way to get what you wish?

1 Like

Thanks for pointing it out!
I was trying to review my week in chronological order. Maybe if my blocks are better organised I would not need the group-by-page view anymore.
I ended up including a recent journals query in my Contents page and clicking through them to review the week:

#+BEGIN_QUERY
 {:title "Last week's journals"
  :query [:find (pull ?p [:block/name :block/journal-day])
       :in $ ?start ?today
       :where
       [?p :block/journal-day ?day]
       [(> ?day ?start)]
       [(<= ?day ?today)]
       [?p :block/name ?name]]
  :inputs [:-7d :today]
  :result-transform (fn [result] (reverse (sort-by (fn [h] (get h :block/journal-day)) result)))
  :view (fn [result]
        [:div.flex.flex-col
         (for [page (map :block/name result)]
           [:a {:href (str "#/page/" page)} (clojure.string/capitalize page)])])}
}
#+END_QUERY
1 Like