Gallery view for query results

It would be nice to have a gallery view for queries that have images associated with them. For instance, books or films with cover/poster images, or contacts, etc.

Agreed, more views from queries would be incredibly useful.

Gallery, Kanban and calendar views.

I feel the queries in Logseq have not yet reached their full potential.

you can use custom view to render view as gallery. example:

:view (fn [result]
             (defn int-comma [n] (call-api "custom_num_with_comma" n))
             (when (seq result)
               [:div {:class "flex flex-row flex-wrap py-2"}
                (for [{:block/keys [uuid properties]} result]
                  [:span {:key uuid :class "flex flex-col items-center mr-2 mb-2 relative"}
                   [:span {:class "relative mb-1"} 
                    [:span {:class "absolute bottom-0 left-0 mb-1 ml-1"} [:a {:is "del-block" :data-uuid uuid}]] 
                    [:a {:on-click (fn [] (call-api "open_in_right_sidebar" (str uuid)))} [:img {:title (str (get properties :jak-title)) :style {:width "8rem" :height "8rem" :alt "NA"} :class (str (if (clojure.string/includes? (str (get properties :jak-avaliable)) "Stok tersedia") "" "opacity-50")) :src (str "https://" (get properties :jak-img))}]]
                    ]
                   [:span {:class (if (clojure.string/includes? (str (get properties :jak-avaliable)) "Stok tersedia") "" "text-red-600")} (str (get properties :jak-sku))]
                   [:span {:class (if (clojure.string/includes? (str (get properties :jak-avaliable)) "Stok tersedia") "" "text-red-600")} (str (int-comma (get properties :jak-price)) (if (> (get properties :jak-cart 0) 0) (str " (x" (get properties :jak-cart 0) ")") ""))]
                   ]
                  )]))

Thanks. Can you give more detailed instructions? I’m not sure how to use this…

complete query example. this query will get all block that contains image from current page. you can modify where clause to meet your requirement. if you click the image, the block that contains the image will open on sidebar

#+BEGIN_QUERY
{
 :query [:find (pull ?b [*])
         :in $ ?current
         :where
         [?p :block/name ?current]
         [?b :block/page ?p]
         [?b :block/content ?c]
         [(re-pattern "!\\[.*\\]\\(.*\\)") ?rx]
         [(re-find ?rx ?c)]
       ]
 :inputs [:current-page]
 :result-transform (fn [r] (map (fn [m] {:uuid (str (:block/uuid m)) :src (last (re-find (re-pattern "!\\[.*\\]\\(\\.\\.(.*)\\)") (:block/content m)))}) r))
 :view (fn [r] 
  (def graph-path (aget (call-api "get_current_graph") "path"))
  (log graph-path)
  [:div {:class "flex flex-row flex-wrap py-2"}
    (for [b r]
        [:span {:key (:uuid b) :class "flex flex-col items-center mr-2 mb-2 relative"}
          [:a {:on-click (fn [] (call-api "open_in_right_sidebar" (:uuid b)))} [:img {:style {:width "8rem" :height "8rem" :alt "NA"} :src (str "assets://" graph-path (:src b))}]]
        ]
    )
  ]
)
}
#+END_QUERY
4 Likes

Hello, this query works well for displaying all images in the current page. But I wonder whether it’s possible to query all images from other pages that are tagged with the current page. Like I keep a food photo log of 3 meals per day in my journal pages. I then want to visit my week page to see all of the meal photos taken this week. Example hierarchy is below:

[[2024/06/19 Wed]]
week:: [[Week 25]]

  • breakfast.jpg #food

[[2024/06/20 Thu]]
week:: [[Week 25]]

  • dinner.jpg #food

[[Week 25]]

  • Query all meal photos for this week?
  • For tagged pages, try replacing this:
    [?b :block/page ?p]
    
    with this:
    (or-join [?b ?p]
      [?b :block/page ?p]
      (and
        [?t :block/tags ?p]
        [?b :block/page ?t]
      )
    )
    
  • For property week:: , try this:
    [?p :block/original-name ?name]
    [?b :block/page ?t]
    [?t :block/properties ?props]
    [(get ?props :week) ?week]
    [(contains? ?week ?name)]
    

Thank you for your help, mentaloid. Unfortunately, query for image blocks that are tagged with current page (the or-join part) isn’t working as expected. I’lll add more pics for more details:

I misunderstood. For tagged images, replace [?b :block/page ?p] with [?b :block/refs ?p].

1 Like

Thank you. It works perfectly. Cheers! :bubble_tea: