 
 (defn reddit-get-username [token callback]
   ;; request username
-  (js/console.log "in get-username")
+  (console-log "in get-username")
   (go (let [response (<! (http/get "https://oauth.reddit.com/api/v1/me"
                                    {:with-credentials? false
                                     :oauth-token token}))
             body  (:body response)
             error (:error body)]
-        (println body)
+        (console-log body)
         (if (or (nil? error) (clojure.string/blank? error))
           (let [username (:name body)]
             (set-app-state-field :username username))

(def saved-posts (r/atom {}))
(def subreddits (r/atom {}))
(def get-posts? (r/atom true))

(defn clear-and-refresh-app []
  (alandipert.storage-atom/remove-local-storage! :saved-for-reddit-app-state)

          ;; redirect to reddit for requesting authorization
          (let [gen-state (clojure.string/replace (str (rand 50)) "." "")]
            (set-app-state-field :state gen-state)
            (console-log @app-state)
            (set! (.-location js/window) (reddit-auth-url client-id redirect-uri gen-state)))
          ;; code query param is not nil or token is populated in app state
          (do
            (console-log @app-state)
            (if (clojure.string/blank? (:token @app-state))
              ;; app-state does not contain auth-token
              ;; retreive auth-token from reddit api
              (let [auth-token-callback-chan (chan)
                    username-callback-chan (chan)]
                (console-log "acquiring auth token")
                (reddit-request-auth-token client-id redirect-uri code state auth-token-callback-chan)
                ;; start process that waits for auth-token; before obtaining username
                (go (let [token (<! auth-token-callback-chan)]
                      (console-log "received callback from request-auth-token")
                      (console-log (str "reeceived token " token))
                      (reddit-get-username token username-callback-chan)))
                ;; starts process that waits for username; before retreiving all posts
                (go (let [username (<! username-callback-chan)]
                      (console-log "received callback from get-username")
                      (get-all-saved-posts (:token @app-state) username saved-posts))))
              ;; all reddit auth and setup is already in app-state
              ;;  retreive all saved posts
              (get-all-saved-posts (:token @app-state) (:username @app-state) saved-posts))))
        ;; render html doms
        (console-log subreddits)
        (r/render-component [loggedin-html (:username @app-state)] (dommy/sel1 :#loggedin))
        (r/render-component [search-bar-html] (dommy/sel1 :#search-form))
        (r/render-component [main-html app-state saved-posts subreddits] (dommy/sel1 :#app)))
