Merge pull request #3193 from penpot/niwinz-thumbnails-1

🎉 Allow submit thumbnails using multipart
This commit is contained in:
Alejandro 2023-05-08 16:11:11 +02:00 committed by GitHub
commit 2ce676885f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 866 additions and 305 deletions

View file

@ -449,10 +449,12 @@
page (get-in state [:workspace-data :pages-index page-id])
name (cp/generate-unique-name unames (:name page))
no_thumbnails_objects (->> (:objects page)
(d/mapm (fn [_ val] (dissoc val :use-for-thumbnail?))))
page (-> page (assoc :name name :id id :objects no_thumbnails_objects))
page (-> page
(assoc :name name)
(assoc :id id)
(assoc :objects
(->> (:objects page)
(d/mapm (fn [_ val] (dissoc val :use-for-thumbnail?))))))
changes (-> (pcb/empty-changes it)
(pcb/add-page id page))]
@ -1265,7 +1267,7 @@
not-group-like? (and (= (count selected) 1)
(not (contains? #{:group :bool} (:type head))))
no-bool-shapes? (->> all-selected (some (comp #{:frame :text} :type)))]
(rx/concat

View file

@ -96,7 +96,7 @@
(pcb/change-parent (:parent-id attrs) [shape]))
(cond-> (ctl/grid-layout? objects (:parent-id shape))
(pcb/update-shapes [(:parent-id shape)] ctl/assign-cells)))]
[shape changes]))
(defn add-shape
@ -400,7 +400,7 @@
changes
(prepare-move-shapes-into-frame changes (:id shape) selected objects)]
[shape changes]))))
(defn create-artboard-from-selection
@ -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))))))))

View file

@ -150,6 +150,10 @@
[id params]
(send-command! id params {:forward-query-params [:file-id :object-id]}))
(defmethod command :get-file-object-thumbnails
[id params]
(send-command! id params {:forward-query-params [:file-id]}))
(defmethod command :export-binfile
[id params]
(send-command! id params {:response-type :blob}))