 (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)
            (println @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
            (println @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)]
                (js/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)]
                      (js/console.log "received callback from request-auth-token")
                      (js/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)]
                      (js/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
        (println 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)))


(enable-console-print!)

;; helper function to print to js/console
(defn console-log [msg & more-msgs]
  (.log js/console (str msg more-msgs)))

;; setting reddit-api properties for dev or prod
(if (= "pvik.github.io" (get (clojure.string/split (str (.-location js/window)) #"/") 2))
  (do
