 (defn search-submitted
   "Send XHR searching for materials."
   [db [scratch-entid]]
-  (let [search-string (get-in (d/pull db [:scratch/val] scratch-entid)
-                              [:scratch/val "searchInput"])
+  (let [search-string (pull-single db :searchInput scratch-entid)
         url (str "/gq/" (th-utils/url-encode search-string))]
     (when search-string
       (ajax/GET url

  "Install scratch area with SCRATCH-KEY as its :scratch/key attribute's value."
  [_ [scratch-key]]
  [{:db/id -1
    :scratch/key scratch-key
    :scratch/val {}}])
(th-utils/register-handler* new-scratch)

(defn set-scratch-val
  "Set V as the value of key K in the scratch area indentified by
  SCRATCH-ENTID."
  [db [scratch-entid k v]]
  {:pre [scratch-entid k v]}
  (let [{m :scratch-val}
        (d/pull db [:scratch/val] scratch-entid)]
    [{:db/id scratch-entid
      :scratch/val (assoc (or m {}) k v)}]))
(th-utils/register-handler* set-scratch-val)




(defn get-scratch-entid
  "Entity ID of the scratch area with SCRATCH-KEY as the value of its
  :scratch/key attribute. Assumes that this scratch area already exists."
  [conn [_ scratch-key]]
  (let [r (tsky/bind '[:find ?e .
                       :in $ ?key
                       :where [?e :scratch/key ?key]]
                     conn scratch-key)]
    (assert @r)
    r))
(th-utils/register-sub* get-scratch-entid)

(defn get-scratch-contents
  "Contents of scratch area with entity ID SCRATCH-ENTID."
  [conn [_ scratch-entid]]
  (reaction (d/pull @conn '[*] scratch-entid)))
(th-utils/register-sub* get-scratch-contents)

(defn search-result
  "Result of the material search."
