Skip to content

Commit

Permalink
Merge pull request #5349 from penpot/palba-add-event-for-pdf
Browse files Browse the repository at this point in the history
✨ Add export format info to export-shapes event
  • Loading branch information
AzazelN28 authored Nov 26, 2024
2 parents 59e5656 + 53f5544 commit c607b61
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 46 deletions.
20 changes: 20 additions & 0 deletions frontend/src/app/main/data/exports/assets.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(ns app.main.data.exports.assets
(:require
[app.common.uuid :as uuid]
[app.main.data.events :as ev]
[app.main.data.modal :as modal]
[app.main.data.persistence :as dwp]
[app.main.data.workspace.state-helpers :as wsh]
Expand Down Expand Up @@ -247,6 +248,12 @@
(rx/map #(clear-export-state @resource-id))
(rx/take-until (rx/delay 6000 stopper))))))))

(defn request-export
[{:keys [exports] :as params}]
(if (= 1 (count exports))
(request-simple-export (assoc params :export (first exports)))
(request-multiple-export params)))

(defn retry-last-export
[]
(ptk/reify ::retry-last-export
Expand All @@ -256,3 +263,16 @@
(when (seq params)
(rx/of (request-multiple-export params)))))))

(defn export-shapes-event
[exports origin]
(let [types (reduce (fn [counts {:keys [type]}]
(if (#{:png :pdf :svg :jpeg} type)
(update counts type inc)
counts))
{:png 0, :pdf 0, :svg 0, :jpeg 0}
exports)]
(ptk/event
::ev/event (merge types
{::ev/name "export-shapes"
::ev/origin origin
:num-shapes (count exports)}))))
11 changes: 2 additions & 9 deletions frontend/src/app/main/ui/exports/assets.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[app.common.colors :as clr]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.main.data.events :as ev]
[app.main.data.exports.assets :as de]
[app.main.data.modal :as modal]
[app.main.refs :as refs]
Expand All @@ -23,7 +22,6 @@
[app.util.i18n :as i18n :refer [tr c]]
[app.util.strings :as ust]
[cuerdas.core :as str]
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))

(def ^:private neutral-icon
Expand Down Expand Up @@ -59,13 +57,8 @@
(fn [event]
(dom/prevent-default event)
(st/emit! (modal/hide)
(de/request-multiple-export
{:exports enabled-exports
:cmd cmd})
(ptk/event
::ev/event {::ev/name "export-shapes"
::ev/origin origin
:num-shapes (count enabled-exports)})))
(de/request-multiple-export {:exports enabled-exports :cmd cmd})
(de/export-shapes-event enabled-exports origin)))

on-toggle-enabled
(mf/use-fn
Expand Down
14 changes: 3 additions & 11 deletions frontend/src/app/main/ui/viewer/inspect/exports.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
(:require-macros [app.main.style :as stl])
(:require
[app.common.data :as d]
[app.main.data.events :as ev]
[app.main.data.exports.assets :as de]
[app.main.refs :as refs]
[app.main.store :as st]
Expand All @@ -18,7 +17,6 @@
[app.util.dom :as dom]
[app.util.i18n :refer [tr c]]
[app.util.keyboard :as kbd]
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))

(mf/defc exports
Expand Down Expand Up @@ -63,15 +61,9 @@
:object-id (-> shapes first :id)}
(cond-> share-id (assoc :share-id share-id)))
exports (mapv #(merge % defaults) @exports)]
(if (= 1 (count exports))
(st/emit!
(de/request-simple-export {:export (first exports)})
(ptk/event
::ev/event {::ev/name "export-shapes" ::ev/origin "viewer" :num-shapes 1}))
(st/emit!
(de/request-multiple-export {:exports exports})
(ptk/event
::ev/event {::ev/name "export-shapes" ::ev/origin "viewer" :num-shapes (count exports)}))))))
(st/emit!
(de/request-export {:exports exports})
(de/export-shapes-event exports "viewer")))))

add-export
(mf/use-callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
(:require-macros [app.main.style :as stl])
(:require
[app.common.data :as d]
[app.main.data.events :as ev]
[app.main.data.exports.assets :as de]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.state-helpers :as wsh]
Expand All @@ -21,7 +20,6 @@
[app.util.dom :as dom]
[app.util.i18n :refer [tr c]]
[app.util.keyboard :as kbd]
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))

(def exports-attrs
Expand Down Expand Up @@ -66,21 +64,20 @@
;; I can select multiple shapes all of them with no export settings and one of them with only one
;; In that situation we must export it directly
(if (and (= 1 (count shapes-with-exports)) (= 1 (-> shapes-with-exports first :exports count)))
(let [shape (-> shapes-with-exports first)
export (-> shape :exports first)
sname (:name shape)
suffix (:suffix export)
defaults {:page-id page-id
:file-id file-id
:name sname
:object-id (:id (first shapes-with-exports))}]
(cond-> sname
(some? suffix)
(str suffix))
(let [shape (-> shapes-with-exports first)
export (-> shape :exports first)
suffix (:suffix export)
sname (cond-> (:name shape)
(some? suffix)
(str suffix))
defaults {:page-id page-id
:file-id file-id
:name sname
:object-id (:id (first shapes-with-exports))}
full-export (merge export defaults)]
(st/emit!
(de/request-simple-export {:export (merge export defaults)})
(ptk/event
::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes 1})))
(de/request-simple-export {:export full-export})
(de/export-shapes-event [full-export] "workspace:sidebar")))
(st/emit!
(de/show-workspace-export-dialog {:selected (reverse ids) :origin "workspace:sidebar"})))

Expand All @@ -92,16 +89,11 @@
:name sname
:object-id (first ids)}
exports (mapv #(merge % defaults) exports)]
(if (= 1 (count exports))
(let [export (first exports)]
(st/emit!
(de/request-simple-export {:export export})
(ptk/event
::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes 1})))
(st/emit!
(de/request-multiple-export {:exports exports})
(ptk/event
::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes (count exports)})))))))

(st/emit!
(de/request-export {:exports exports})
(de/export-shapes-event exports "workspace:sidebar"))))))


;; TODO: maybe move to specific events for avoid to have this logic here?
add-export
Expand Down

0 comments on commit c607b61

Please sign in to comment.