fix(cmdk): missing current-page search impl

Close #10658
pull/10668/head
Andelf 2023-12-08 16:22:41 +08:00 committed by Tienson Qin
parent 099cad5b64
commit 2547eb3653
1 changed files with 77 additions and 55 deletions

View File

@ -1,6 +1,5 @@
(ns frontend.components.cmdk
(:require
[clojure.string :as string]
(:require [clojure.string :as string]
[frontend.components.block :as block]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
@ -341,6 +340,29 @@
(search/fuzzy-search filters q {:extract-fn :text}))]
(swap! !results update group merge {:status :success :items matched-items})))
(defmethod load-results :current-page [group state]
(if-let [current-page (page-util/get-current-page-id)]
(let [!results (::results state)
!input (::input state)
repo (state/get-current-repo)
opts {:limit 100 :page current-page}]
(swap! !results assoc-in [group :status] :loading)
(swap! !results assoc-in [:current-page :status] :loading)
(p/let [blocks (search/block-search repo @!input opts)
blocks (remove nil? blocks)
items (map (fn [block]
(let [id (if (uuid? (:block/uuid block))
(:block/uuid block)
(uuid (:block/uuid block)))]
{:icon "block"
:icon-theme :gray
:text (:block/content block)
:header (block/breadcrumb {:search? true} repo id {})
:current-page? true
:source-block block})) blocks)]
(swap! !results update :current-page merge {:status :success :items items})))
(reset! (::filter state) nil)))
;; The default load-results function triggers all the other load-results function
(defmethod load-results :default [_ state]
(if-not (some-> state ::input deref seq)
@ -725,7 +747,7 @@
[:div "to filter search results"]]
[:div.flex.flex-row.gap-1.items-center.opacity-50.hover:opacity-100
(shui/shortcut ["mod" "enter"] context)
[:div "to open search in the sidebar"]]]) )
[:div "to open search in the sidebar"]]]))
(rum/defcs tip <
{:init (fn [state]