 ;; -------------------------
 ;; Upload
 
-(defn track-upload [upload-state]
-  (let [{loaded      :loaded
-         total       :total
-         status      :status
-         status-body :body} @upload-state
-
-        {error-msg  :msg
+(defn track-upload [{loaded      :loaded
+                     total       :total
+                     status      :status
+                     status-body :body}]
+
+  (let [{error-msg :msg
          track     :track} status-body
 
         percentage (-> loaded
                        (/ total) (* 100))]
+
     (if (< 0 percentage 100)
       [:progress.pure-input-1 {:max 100 :value percentage}]
 


(defn upload-section []
  (let [form-ref       (r/atom nil)
        file-input-ref (r/atom nil)
        upload-state   (r/atom {})]
    ; TODO:
    ; - make state a list of chans, and append to it the retured one
    ; - loop over that list to diplay statuses
    (fn []
      [:section#upload
       [:h2 "Upload"]

          {:title "Upload"
           :on-click #(when @file-input-ref
                        (when-let [form @form-ref]
                          (let [up-chan      (req/upload! form)
                                upload-state (r/cursor app-state [:uploads])]
                            (go-loop []
                                     (when-let [delta (<! up-chan)]
                                       (swap! upload-state merge
                                              {(hash up-chan) delta})
                                       (recur))))))}
          [:i.fa.fa-upload]]]

