💄 Add cosmetic changes (and comments) to toggle-file-thumbnail-selected function

This commit is contained in:
Andrey Antukh 2023-05-05 14:14:22 +02:00
parent 541a372f01
commit c2b6b40554

View file

@ -481,25 +481,33 @@
(let [selected (wsh/lookup-selected state)]
(rx/of (dch/update-shapes selected #(update % :blocked not)))))))
;; FIXME: this need to be refactored
(defn toggle-file-thumbnail-selected
[]
(ptk/reify ::toggle-file-thumbnail-selected
ptk/WatchEvent
(watch [_ state _]
(let [selected (wsh/lookup-selected state)
pages (-> state :workspace-data :pages-index vals)
get-frames (fn [{:keys [objects id] :as page}]
(->> (ctst/get-frames objects)
(sequence
(comp (filter :use-for-thumbnail?)
(map :id)
(remove selected)
(map (partial vector id))))))]
pages (-> state :workspace-data :pages-index vals)]
(rx/concat
;; First: clear the `:use-for-thumbnail?` flag from all not
;; selected frames.
(rx/from
(->> (mapcat get-frames pages)
(->> pages
(mapcat
(fn [{:keys [objects id] :as page}]
(->> (ctst/get-frames objects)
(sequence
(comp (filter :use-for-thumbnail?)
(map :id)
(remove selected)
(map (partial vector id)))))))
(d/group-by first second)
(map (fn [[page-id frame-ids]]
(dch/update-shapes frame-ids #(dissoc % :use-for-thumbnail?) {:page-id page-id})))))
;; And finally: toggle the flag value on all the selected shapes
(rx/of (dch/update-shapes selected #(update % :use-for-thumbnail? not))))))))