mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 09:08:31 -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)
|
||||
(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
|
||||
[conn {:keys [file-id library-id] :as params}]
|
||||
(db/insert! conn :file-library-rel
|
||||
{:file-id file-id
|
||||
:library-file-id library-id}))
|
||||
(db/exec-one! conn [sql:link-file-to-library file-id library-id]))
|
||||
|
||||
|
||||
;; --- Mutation: Unlink file from library
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
(s/def ::team-id ::us/uuid)
|
||||
(s/def ::url ::us/url)
|
||||
|
||||
|
||||
;; --- Create Media object (Upload and create from url)
|
||||
|
||||
(declare create-media-object)
|
||||
|
|
|
@ -55,13 +55,3 @@
|
|||
[conn {:keys [id] :as props}]
|
||||
(let [sql "delete from media_object where id=? and deleted_at is not null"]
|
||||
(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
|
||||
|
||||
(declare file-linked)
|
||||
|
||||
(defn link-file-to-library
|
||||
[file-id library-id]
|
||||
(ptk/reify ::link-file-to-library
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [params {:file-id file-id
|
||||
:library-id library-id}]
|
||||
(->> (->> (rp/mutation :link-file-to-library params)
|
||||
(rx/mapcat
|
||||
#(rx/zip (rp/query :file-library {:file-id library-id})
|
||||
(rp/query :media-objects {:file-id library-id
|
||||
: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)
|
||||
(let [fetched #(assoc-in %2 [:workspace-libraries (:id %1)] %1)
|
||||
params {:file-id file-id
|
||||
:library-id library-id}]
|
||||
(->> (rp/mutation :link-file-to-library params)
|
||||
(rx/mapcat #(rp/query :file {:id library-id}))
|
||||
(rx/map #(partial fetched %)))))))
|
||||
|
||||
(defn unlink-file-from-library
|
||||
[file-id library-id]
|
||||
(ptk/reify ::unlink-file-from-library
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [params {:file-id file-id
|
||||
:library-id library-id}]
|
||||
(let [unlinked #(d/dissoc-in % [:workspace-libraries library-id])
|
||||
params {:file-id file-id
|
||||
:library-id library-id}]
|
||||
(->> (rp/mutation :unlink-file-from-library params)
|
||||
(rx/map #(file-unlinked file-id library-id)))))))
|
||||
|
||||
(defn file-unlinked
|
||||
[file-id library-id]
|
||||
(ptk/reify ::file-unlinked
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(d/dissoc-in state [:workspace-libraries library-id]))))
|
||||
|
||||
(rx/map (constantly unlinked)))))))
|
||||
|
||||
;; --- Fetch Pages
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue