             [discuss.sidebar :as sidebar]
             [discuss.utils.common :as lib]))
 
+(defn- get-reference-usages-from-app-state
+  "Return list of reference usages, which were previously stored in the app-state.
+   TODO: optimize"
+  []
+  (get-in @lib/app-state [:common :reference-usages]))
+
 (defn reference-usage-handler
-  "Handler to process information about the reference."
+  "Handler to process information about the reference. Store results and change view."
   [response]
   (let [res (com/success-handler response)]
-    (println res)))
+    (lib/update-state-item! :common :reference-usages (fn [_] res))
+    (lib/change-view! :reference-usages)))
 
 (defn query-reference-details
   "Show usages of the provided reference."
   [reference-id]
   (let [url (str (:base config/api) (get-in config/api [:get :reference-usages]) "/" reference-id)]
-    (println "OMG I am here!")
     (com/ajax-get url {} reference-usage-handler)))
 
 

               (dom/button #js {:className "btn btn-primary"}
                           "Create new Statement with this reference")))))

(defn usages-view
  "List with details showing the usages of the given reference."
  []
  (reify om/IRender
    (render [_]
      (dom/h4 nil "foo"))))
  "When clicking on a reference directly in the text, interact with the user to give her the choice of what
   her next steps might be."
  [reference]
  (lib/change-view! :reference-dialog)
  (lib/save-selected-reference! reference)
  (sidebar/show)
