             :on-click (fn [] (alandipert.storage-atom/remove-local-storage! :saved-for-reddit-app-state)
                         (set! (.-location js/window) "/"))}]])
 
+(defn handle-error [error]
+  (swap! error-msg #(str error))
+  (r/render-component [error-html] (dommy/sel1 :#error)))
+
+
+(defn get-saved-posts [& after]
+  (let [saved-post-get-chan (if (nil? after)
+                              (http/get (str "https://oauth.reddit.com/user/" (:username @app-state) "/saved")
+                                        {:with-credentials? false
+                                         :oauth-token (:token @app-state)})
+                              (http/get (str "https://oauth.reddit.com/user/" (:username @app-state) "/saved")
+                                        {:with-credentials? false
+                                         :oauth-token (:token @app-state)
+                                         :query-params {"after" (first after)}}))]
+    (js/console.log "Retreiving saved posts..." after)
+    (go (let [response (<! saved-post-get-chan )
+              posts (-> response :body :data :children)
+              error (-> response :body :error)
+              after (-> response :body :data :after) ]
+          (println "received response")
+          #_(println response)
+          (if (clojure.string/blank? error)
+            (do
+              (set-app-state-field :after after)
+              (if (clojure.string/blank? after)
+                (set! (.-disabled (dommy/sel1 :#btn-get-posts)) true))
+              (doseq [p posts]
+                #_(println (process-json-post p))
+                (swap! saved-posts #(conj % %2) (assoc (:data p) :key (str (-> p :data :name) (-> p :data :subreddit_id) (-> p :data :link_id))))))
+            (handle-error (str error " " (:error-text response) "\nYour API token might've expired")))))))
+
+(defn loggedin-html []
+  [:p {:class "navbar-text navbar-right"} "Logged in as " (:username @app-state)])
+
 (defn post-html [p]
   (let [link? (nil? (:title p))
+        key (:key p)
         title (unescapeEntities (if link? (:link_title p) (:title p)))
-        url (if link? (str (:link_url p) (:key p)) (:url p))
+        url (if link? (str (:link_url p) key) (:url p))
         body (if (not (nil? (:body_html p))) (unescapeEntities (:body_html p)))
         subreddit (:subreddit p)
         author (:author p)


;; define your app data so that it doesn't get over-written on reload
(def app-state (local-storage (r/atom {:username ""
                                       :token ""})
                              :saved-for-reddit-app-state))

(def saved-posts (r/atom []))

   [:div {:class "row"}
    [:div {:class "col-md-12"}
     [:input {:type "button" :value "moar!"
              :id "btn-get-posts" :name "btn-get-posts"
              :on-click (fn [] (println "get more posts") (get-saved-posts (:after @app-state)) )}]]]
   [:p "Reddit API Token: "
    [:input {:type "text" :id "token" :name "token"
             :value (:token @app-state) :readOnly "true"}]]])

(defn process-json-post [post]
  (let [p (:data post)
