Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add export format info to export-shapes event #5349

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
✨ Add export format info to export-shapes event
  • Loading branch information
pabloalba committed Nov 21, 2024
commit 53f55444cda5725b92638319327b17a03e57af63
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