mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 14:56:43 +02:00
🎉 Duplicate projects and files
This commit is contained in:
parent
9945243a23
commit
044f1f63c0
6 changed files with 107 additions and 16 deletions
|
@ -12,6 +12,7 @@
|
|||
[app.common.uuid :as uuid]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.data.users :as du]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[app.util.router :as rt]
|
||||
[app.util.time :as dt]
|
||||
[app.util.timers :as ts]
|
||||
|
@ -347,6 +348,28 @@
|
|||
(rx/map #(partial created %))
|
||||
(rx/catch on-error)))))))
|
||||
|
||||
(defn duplicate-project
|
||||
[{:keys [id name] :as params}]
|
||||
(us/assert ::us/uuid id)
|
||||
(letfn [(duplicated [project state]
|
||||
(-> state
|
||||
(assoc-in [:projects (:team-id project) (:id project)] project)
|
||||
(assoc-in [:dashboard-local :project-for-edit] (:id project))))]
|
||||
(ptk/reify ::duplicate-project
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [{:keys [on-success on-error]
|
||||
:or {on-success identity
|
||||
on-error identity}} (meta params)
|
||||
|
||||
new-name (str name " " (tr "dashboard.copy-suffix"))]
|
||||
|
||||
(->> (rp/mutation! :duplicate-project {:project-id id
|
||||
:new-name new-name})
|
||||
(rx/tap on-success)
|
||||
(rx/map #(partial duplicated %))
|
||||
(rx/catch on-error)))))))
|
||||
|
||||
(def clear-project-for-edit
|
||||
(ptk/reify ::clear-project-for-edit
|
||||
ptk/UpdateEvent
|
||||
|
@ -494,3 +517,24 @@
|
|||
(-> state
|
||||
(assoc-in [:files project-id id] file)
|
||||
(update-in [:recent-files project-id] (fnil conj #{}) id)))))
|
||||
|
||||
;; --- Duplicate File
|
||||
|
||||
(defn duplicate-file
|
||||
[{:keys [id name] :as params}]
|
||||
(us/assert ::us/uuid id)
|
||||
(ptk/reify ::duplicate-file
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [{:keys [on-success on-error]
|
||||
:or {on-success identity
|
||||
on-error identity}} (meta params)
|
||||
|
||||
new-name (str name " " (tr "dashboard.copy-suffix"))]
|
||||
|
||||
(->> (rp/mutation! :duplicate-file {:file-id id
|
||||
:new-name new-name})
|
||||
(rx/tap on-success)
|
||||
(rx/map file-created)
|
||||
(rx/catch on-error))))))
|
||||
|
||||
|
|
|
@ -36,6 +36,11 @@
|
|||
qparams {:page-id (first (get-in file [:data :pages]))}]
|
||||
(st/emit! (rt/nav-new-window :workspace pparams qparams)))))
|
||||
|
||||
on-duplicate
|
||||
(mf/use-callback
|
||||
(mf/deps file)
|
||||
(st/emitf (dd/duplicate-file file)))
|
||||
|
||||
delete-fn
|
||||
(mf/use-callback
|
||||
(mf/deps file)
|
||||
|
@ -100,6 +105,7 @@
|
|||
:left left
|
||||
:options [[(tr "dashboard.open-in-new-tab") on-new-tab]
|
||||
[(tr "labels.rename") on-edit]
|
||||
[(tr "dashboard.duplicate") on-duplicate]
|
||||
[(tr "labels.delete") on-delete]
|
||||
(if (:is-shared file)
|
||||
[(tr "dashboard.remove-shared") on-del-shared]
|
||||
|
|
|
@ -26,6 +26,17 @@
|
|||
(let [top (or top 0)
|
||||
left (or left 0)
|
||||
|
||||
on-duplicate
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
#(let [on-success
|
||||
(fn [new-project]
|
||||
(st/emit! (rt/nav :dashboard-files
|
||||
{:team-id (:team-id new-project)
|
||||
:project-id (:id new-project)})))]
|
||||
(st/emit! (dd/duplicate-project
|
||||
(with-meta project {:on-success on-success})))))
|
||||
|
||||
delete-fn
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
|
@ -49,5 +60,6 @@
|
|||
:top top
|
||||
:left left
|
||||
:options [[(tr "labels.rename") on-edit]
|
||||
[(tr "dashboard.duplicate") on-duplicate]
|
||||
[(tr "labels.delete") on-delete]]}]))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue