 (defn ^:private mark-page-selected
   "Assocs {:selected? true} to `page' if `selected-pages'
   contains (:id page). Used in `index-column'."
-  [selected-pages page]
+  [page selected-pages]
   (assoc page :selected? (contains? (set selected-pages) (:id page))))
 
 (ui/defcomponent inbox-column [[state column] owner opts]

                            ;; Delegate to `inbox'
                            (handle-drop! (:id column)
                                          source-column
                                          page-ids)))}
     [:header (column-title column state)]
     [:ul.pages
      (om/build-all inbox-column-page (column-pages column state)
                    {:opts {:page-click! (fn [click] 
                                           (om/update-state! owner :selection
                                                             #(selection/click % click)))}
                     :fn (partial mark-page-selected (:selected selection))})]]))

(defn ^:private inbox-handle-drop! [state owner page-cache target source page-ids]
  (let [columns (om/get-state owner :columns)
        target (get columns target)
        source (get columns source)
        ;; Remove page-ids already in `target'
        target-pages (mapv :id (column-pages target state))
        pages (into []
                    (comp (remove (set target-pages))
                          (map page-cache)
                          (map om/value))
                    page-ids)]
    (if-not (seq pages)
      ;; TODO: Should we do that in the columns itself?
      (js/console.warn "Ignoring drop consisting only of duplicate pages:"
                       (pr-str page-ids))
      (go
        (if (<! (accept-drop! target state pages))
          (do
            (println "Target saved. Removing from source...")
            (<! (remove-pages! source state page-ids))

        (js/console.error (str "[DocumentColumnSource] Failed to get document " document-id)
                          {:document-id document-id}))))
  ColumnDropTarget
  (accept-drop! [_ state new-pages target-idx]
    (go
      (println "dropping" (pr-str (map :id new-pages)) "on document" document-id
               (str "(at index " target-idx ")"))
      (let [document (om/value (get-in state [:documents document-id]))]
        (<! (api/update-document! (update document :pages
                                          #(into % new-pages))))
