mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 18:48:37 -05:00
✨ Make file to library link idempotent.
And remove unused api calls.
This commit is contained in:
parent
b2957c5f35
commit
fca48e39ee
4 changed files with 16 additions and 47 deletions
|
@ -162,11 +162,14 @@
|
||||||
(files/check-edition-permissions! conn profile-id file-id)
|
(files/check-edition-permissions! conn profile-id file-id)
|
||||||
(link-file-to-library conn params)))
|
(link-file-to-library conn params)))
|
||||||
|
|
||||||
|
(def sql:link-file-to-library
|
||||||
|
"insert into file_library_rel (file_id, library_file_id)
|
||||||
|
values (?, ?)
|
||||||
|
on conflict do nothing;")
|
||||||
|
|
||||||
(defn- link-file-to-library
|
(defn- link-file-to-library
|
||||||
[conn {:keys [file-id library-id] :as params}]
|
[conn {:keys [file-id library-id] :as params}]
|
||||||
(db/insert! conn :file-library-rel
|
(db/exec-one! conn [sql:link-file-to-library file-id library-id]))
|
||||||
{:file-id file-id
|
|
||||||
:library-file-id library-id}))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Mutation: Unlink file from library
|
;; --- Mutation: Unlink file from library
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
(s/def ::team-id ::us/uuid)
|
(s/def ::team-id ::us/uuid)
|
||||||
(s/def ::url ::us/url)
|
(s/def ::url ::us/url)
|
||||||
|
|
||||||
|
|
||||||
;; --- Create Media object (Upload and create from url)
|
;; --- Create Media object (Upload and create from url)
|
||||||
|
|
||||||
(declare create-media-object)
|
(declare create-media-object)
|
||||||
|
|
|
@ -55,13 +55,3 @@
|
||||||
[conn {:keys [id] :as props}]
|
[conn {:keys [id] :as props}]
|
||||||
(let [sql "delete from media_object where id=? and deleted_at is not null"]
|
(let [sql "delete from media_object where id=? and deleted_at is not null"]
|
||||||
(db/exec-one! conn [sql id])))
|
(db/exec-one! conn [sql id])))
|
||||||
|
|
||||||
(defmethod handle-deletion :color
|
|
||||||
[conn {:keys [id] :as props}]
|
|
||||||
(let [sql "delete from color where id=? and deleted_at is not null"]
|
|
||||||
(db/exec-one! conn [sql id])))
|
|
||||||
|
|
||||||
(defmethod handle-deletion :page
|
|
||||||
[conn {:keys [id] :as props}]
|
|
||||||
(let [sql "delete from page where id=? and deleted_at is not null"]
|
|
||||||
(db/exec-one! conn [sql id])))
|
|
||||||
|
|
|
@ -287,51 +287,28 @@
|
||||||
|
|
||||||
;; --- Link and unlink Files
|
;; --- Link and unlink Files
|
||||||
|
|
||||||
(declare file-linked)
|
|
||||||
|
|
||||||
(defn link-file-to-library
|
(defn link-file-to-library
|
||||||
[file-id library-id]
|
[file-id library-id]
|
||||||
(ptk/reify ::link-file-to-library
|
(ptk/reify ::link-file-to-library
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [params {:file-id file-id
|
(let [fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1)
|
||||||
:library-id library-id}]
|
params {:file-id file-id
|
||||||
(->> (->> (rp/mutation :link-file-to-library params)
|
:library-id library-id}]
|
||||||
(rx/mapcat
|
(->> (rp/mutation :link-file-to-library params)
|
||||||
#(rx/zip (rp/query :file-library {:file-id library-id})
|
(rx/mapcat #(rp/query :file {:id library-id}))
|
||||||
(rp/query :media-objects {:file-id library-id
|
(rx/map #(partial fetched %)))))))
|
||||||
:is-local false}))))
|
|
||||||
(rx/map file-linked))))))
|
|
||||||
|
|
||||||
(defn file-linked
|
|
||||||
[[library media-objects colors]]
|
|
||||||
(ptk/reify ::file-linked
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(assoc-in state [:workspace-libraries (:id library)]
|
|
||||||
(assoc library
|
|
||||||
:media-objects media-objects
|
|
||||||
:colors colors)))))
|
|
||||||
|
|
||||||
(declare file-unlinked)
|
|
||||||
|
|
||||||
(defn unlink-file-from-library
|
(defn unlink-file-from-library
|
||||||
[file-id library-id]
|
[file-id library-id]
|
||||||
(ptk/reify ::unlink-file-from-library
|
(ptk/reify ::unlink-file-from-library
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [params {:file-id file-id
|
(let [unlinked #(d/dissoc-in % [:workspace-libraries library-id])
|
||||||
:library-id library-id}]
|
params {:file-id file-id
|
||||||
|
:library-id library-id}]
|
||||||
(->> (rp/mutation :unlink-file-from-library params)
|
(->> (rp/mutation :unlink-file-from-library params)
|
||||||
(rx/map #(file-unlinked file-id library-id)))))))
|
(rx/map (constantly unlinked)))))))
|
||||||
|
|
||||||
(defn file-unlinked
|
|
||||||
[file-id library-id]
|
|
||||||
(ptk/reify ::file-unlinked
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(d/dissoc-in state [:workspace-libraries library-id]))))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Fetch Pages
|
;; --- Fetch Pages
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue