        (assoc :loading-remotely? false)
        (assoc :remote-error error))))
 
-(reg-event-db
+(reg-event-fx
  :fetch-entries
- (fn [db _]
-   (let [url (str (:server db) "/elfeed/search?q=" "@15-days-old %2bunread")]
-     (POST
-         url
-         {:handler (fn [data]
-                     (dispatch [:process-remote-entries data]))
-          :error-handler (fn [error]
-                           (dispatch [:process-remote-entries-error error]))
-          :response-format :json
-          :keywords? true}))
-   (-> db
-       (assoc :error-entries false)
-       (assoc :fetching-entries? true))))
+ (fn [{db :db} _]
+   {:http-xhrio {:method :post
+                 :uri (str (:server db) "/elfeed/search?q=" "@15-days-old %2bunread")
+                 :format :text
+                 :response-format (ajax/json-response-format {:keywords? true})
+                 :keywords? true
+                 :on-success [:process-remote-entries]
+                 :on-failure [:process-remote-entries-error]}
+    :db (assoc db
+               :error-entries false
+               :fetching-entries? true)}))
 
 (reg-event-db
  :process-remote-entries

       (assoc :fetching-entries? false)
       (assoc :error-entries error))))

(reg-event-db
 :mark-entry-as-read
 (fn [db [_ entry]]
   (let [url (str (:server db) "/elfeed/mark-read" "?webid=" (js/encodeURIComponent (:webid entry)))]
     (POST
         url
         {:handler (fn [data]
                     )
          :format :json
          :error-handler (fn [error]
                           
                           )}))
   (-> db
       (update :recent-reads (fn [coll]
                               (if coll
                                 (conj coll (:webid entry))
                                 #{(:webid entry)}))))))

(reg-event-db
 :fetch-entry-content
 (fn [db [_ entry]]
   (let [url (str (:server db) "/elfeed/content/" (:content entry))]
     (POST url
         {:handler (fn [data]
                     (dispatch [:process-remote-entry entry data])
                     (dispatch [:mark-entry-as-read entry]))
          :error-handler (fn [error]
                           (dispatch [:process-remote-entry-error error]))}))
   (-> db
       (assoc :error-entry false)
       (assoc :current-entry (:webid entry))
       (assoc-in [:entries-m (:webid entry)] entry)
       (assoc :fetching-entry? true))))

(reg-event-db
 :process-remote-entry
 ->ls
 (fn [db [_ entry response]]
   (-> db
       (assoc :fetching-entry? false)
       (assoc-in [:entries-m (:webid entry) :content-body] response))))

(ns elfeed-cljsrn.events
  (:require [ajax.core :as ajax]
            [cljs.reader :as reader]
            [day8.re-frame.http-fx]
            [re-frame.core :refer [reg-event-db after dispatch reg-event-fx]]
            [cljs.spec :as s]
            [elfeed-cljsrn.local-storage :as ls]
            [elfeed-cljsrn.rn :as rn]
            [elfeed-cljsrn.db :as db :refer [app-db db->ls! ls-db-key]]))
