0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-24 15:56:11 -05:00

🐛 Fix pointer loading issue on link-file-to-library action

This commit is contained in:
Andrey Antukh 2023-11-15 17:20:17 +01:00
parent c79e148497
commit 1864896b70
3 changed files with 45 additions and 29 deletions

View file

@ -36,6 +36,7 @@
[app.main.data.workspace.bool :as dwb] [app.main.data.workspace.bool :as dwb]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.collapse :as dwco] [app.main.data.workspace.collapse :as dwco]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.drawing :as dwd] [app.main.data.workspace.drawing :as dwd]
[app.main.data.workspace.drawing.common :as dwdc] [app.main.data.workspace.drawing.common :as dwdc]
[app.main.data.workspace.edition :as dwe] [app.main.data.workspace.edition :as dwe]
@ -128,26 +129,6 @@
(let [data (d/removem (comp t/pointer? val) data)] (let [data (d/removem (comp t/pointer? val) data)]
(assoc state :workspace-data data))))) (assoc state :workspace-data data)))))
(defn- resolve-file-data
[file-id {:keys [pages-index] :as data}]
(letfn [(resolve-pointer [[key val :as kv]]
(if (t/pointer? val)
(->> (rp/cmd! :get-file-fragment {:file-id file-id :fragment-id @val})
(rx/map #(get % :content))
(rx/map #(vector key %)))
(rx/of kv)))
(resolve-pointers [coll]
(->> (rx/from (seq coll))
(rx/merge-map resolve-pointer)
(rx/reduce conj {})))]
(->> (rx/zip (resolve-pointers data)
(resolve-pointers pages-index))
(rx/take 1)
(rx/map (fn [[data pages-index]]
(assoc data :pages-index pages-index))))))
(defn- bundle-fetched (defn- bundle-fetched
[{:keys [features file thumbnails project team team-users comments-users]}] [{:keys [features file thumbnails project team team-users comments-users]}]
(ptk/reify ::bundle-fetched (ptk/reify ::bundle-fetched
@ -185,7 +166,7 @@
;; FIXME: move to bundle fetch stages ;; FIXME: move to bundle fetch stages
;; Load main file ;; Load main file
(->> (resolve-file-data file-id file-data) (->> (dwc/resolve-file-data file-id file-data)
(rx/mapcat (fn [{:keys [pages-index] :as data}] (rx/mapcat (fn [{:keys [pages-index] :as data}]
(->> (rx/from (seq pages-index)) (->> (rx/from (seq pages-index))
(rx/mapcat (rx/mapcat
@ -207,7 +188,7 @@
(rx/map #(assoc % :synced-at synced-at))))) (rx/map #(assoc % :synced-at synced-at)))))
(rx/merge-map (rx/merge-map
(fn [{:keys [id data] :as file}] (fn [{:keys [id data] :as file}]
(->> (resolve-file-data id data) (->> (dwc/resolve-file-data id data)
(rx/map (fn [data] (assoc file :data data)))))) (rx/map (fn [data] (assoc file :data data))))))
(rx/merge-map (rx/merge-map
(fn [{:keys [id] :as file}] (fn [{:keys [id] :as file}]

View file

@ -8,10 +8,12 @@
(:require (:require
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.transit :as t]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu] [app.main.data.workspace.undo :as dwu]
[app.main.repo :as rp]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -19,6 +21,30 @@
;; Change this to :info :debug or :trace to debug this module ;; Change this to :info :debug or :trace to debug this module
(log/set-level! :warn) (log/set-level! :warn)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HELPERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn resolve-file-data
[file-id {:keys [pages-index] :as data}]
(letfn [(resolve-pointer [[key val :as kv]]
(if (t/pointer? val)
(->> (rp/cmd! :get-file-fragment {:file-id file-id :fragment-id @val})
(rx/map #(get % :content))
(rx/map #(vector key %)))
(rx/of kv)))
(resolve-pointers [coll]
(->> (rx/from (seq coll))
(rx/merge-map resolve-pointer)
(rx/reduce conj {})))]
(->> (rx/zip (resolve-pointers data)
(resolve-pointers pages-index))
(rx/take 1)
(rx/map (fn [[data pages-index]]
(assoc data :pages-index pages-index))))))
(defn initialized? (defn initialized?
"Check if the state is properly initialized in a workspace. This means "Check if the state is properly initialized in a workspace. This means
it has the `:current-page-id` and `:current-file-id` properly set." it has the `:current-page-id` and `:current-file-id` properly set."
@ -26,11 +52,9 @@
(and (uuid? (:current-file-id state)) (and (uuid? (:current-file-id state))
(uuid? (:current-page-id state)))) (uuid? (:current-page-id state))))
;; --- Helpers (defn interrupt?
[e]
(defn interrupt? [e] (= e :interrupt)) (= e :interrupt))
(declare undo-to-index)
(defn- assure-valid-current-page (defn- assure-valid-current-page
[] []
@ -49,9 +73,16 @@
(rx/empty) (rx/empty)
(rx/of (rt/nav :workspace pparams qparams))))))) (rx/of (rt/nav :workspace pparams qparams)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; UNDO
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare undo-to-index)
;; These functions should've been in
;; `src/app/main/data/workspace/undo.cljs` but doing that causes a
;; circular dependency with `src/app/main/data/workspace/changes.cljs`
;; These functions should've been in `src/app/main/data/workspace/undo.cljs` but doing that causes
;; a circular dependency with `src/app/main/data/workspace/changes.cljs`
(def undo (def undo
(ptk/reify ::undo (ptk/reify ::undo
ptk/WatchEvent ptk/WatchEvent

View file

@ -27,6 +27,7 @@
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.workspace :as-alias dw] [app.main.data.workspace :as-alias dw]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.groups :as dwg] [app.main.data.workspace.groups :as dwg]
[app.main.data.workspace.libraries-helpers :as dwlh] [app.main.data.workspace.libraries-helpers :as dwlh]
[app.main.data.workspace.notifications :as-alias dwn] [app.main.data.workspace.notifications :as-alias dwn]
@ -1143,6 +1144,9 @@
(->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id}) (->> (rp/cmd! :link-file-to-library {:file-id file-id :library-id library-id})
(rx/ignore)) (rx/ignore))
(->> (rp/cmd! :get-file {:id library-id :features features}) (->> (rp/cmd! :get-file {:id library-id :features features})
(rx/merge-map (fn [{:keys [id data] :as file}]
(->> (dwc/resolve-file-data id data)
(rx/map (fn [data] (assoc file :data data))))))
(rx/map (fn [file] (rx/map (fn [file]
(fn [state] (fn [state]
(assoc-in state [:workspace-libraries library-id] file))))) (assoc-in state [:workspace-libraries library-id] file)))))