Query for simple weekly tasks view, like org-agenda

Hi all,

I’ve been wrestling with this one for a few days… Basically I want to create a query I can put in an “Agenda” page, that displays all my weekly tasks sorted by day of the week. Just like in org-agenda, but I’d be excited to switch to Logseq from Emacs!

Here’s what I have so far. I was planning to put headings “Monday”, “Tuesday”, etc. and put this query in each. Really hacky, but not sure how else to do it…?

I’ve gotten it to the point where it isn’t throwing errors anymore, but now it returns no results! Does anyone have an idea where I’ve gone wrong?

#+BEGIN_QUERY
{
:title "Sunday in next 7 days"
:query
[:find (pull ?block [*])
 :in $ ?start ?end ?today
 :where
 [?block :block/marker "TODO"]
 [?block :block/content ?content]
 [(clojure.string/includes? ?content "Sun")]
 [?block :block/scheduled ?scheduled]
 [(>= ?scheduled ?today)]
 [(<= ?scheduled ?end)
 ]]

:inputs [:today :7d-after ["Sun"]]
:result-transform (fn [result]
                   (sort-by (fn [d]
                              (get-in d [:block/scheduled :time]))
                           result))
:collapsed? false
:table-view? false
:group-by-page? false
:breadcrumb-show? false
}
#+END_QUERY

Bonus points if it can display tasks in order of time scheduled!

I’m aware of the agenda plugin, but am looking for a more distraction-free simple list of tasks. And I love the way queries’ output is directly editable.

Looks like others were looking for something similar in this forum, so hopefully we could be nearly there :slight_smile:

Not sure what exactly input and output is, but the error in your query is here:
[(>= ?scheduled ?today)]

You have: :inputs [:today :7d-after ["Sun"]]
Which map to: :in $ ?start ?end ?today

Therefore ?today is filled with ["Sun"].
Which will never evaluate to true against a date in format YYYYMMDD.

The line should be: [(>= ?scheduled ?start)]

Hope that helps!

1 Like

It works! You are amazing, thanks so much!

I was just Frankensteining bits of code together, but your explanation helps me understand it :slight_smile:

1 Like

Can you please put the final query here?

1 Like

Sure, it isn’t perfect because depending on what day of the week it is today, it won’t display chronologically. But at the moment I’m just repeating this query for each day of the week:

## Monday
- #+BEGIN_QUERY 
  {
  :query
  [:find (pull ?block [*])
  :in $ ?start ?end ?dayOfWeek
  :where
  [?block :block/marker "TODO"]
  [?block :block/content ?content]
  [(clojure.string/includes? ?content "Mon")]
  [?block :block/scheduled ?scheduled]
  [(>= ?scheduled ?start)]
  [(<= ?scheduled ?end)
  ]]
  :inputs [:today :6d-after ["Mon"]]
  :result-transform (fn [result]
                 (sort-by (fn [d]
                            (get-in d [:block/scheduled :time]))
                         result))
  :collapsed? false
  :table-view? false
  :group-by-page? false
  :breadcrumb-show? false
  }
  #+END_QUERY