From 1864896b705aa7c315ff072c03bf771e1dc122e8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 15 Nov 2023 17:20:17 +0100 Subject: [PATCH] :bug: Fix pointer loading issue on link-file-to-library action --- frontend/src/app/main/data/workspace.cljs | 25 ++--------- .../src/app/main/data/workspace/common.cljs | 45 ++++++++++++++++--- .../app/main/data/workspace/libraries.cljs | 4 ++ 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 47d5dc259..9255f9bd7 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -36,6 +36,7 @@ [app.main.data.workspace.bool :as dwb] [app.main.data.workspace.changes :as dch] [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.common :as dwdc] [app.main.data.workspace.edition :as dwe] @@ -128,26 +129,6 @@ (let [data (d/removem (comp t/pointer? val) 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 [{:keys [features file thumbnails project team team-users comments-users]}] (ptk/reify ::bundle-fetched @@ -185,7 +166,7 @@ ;; FIXME: move to bundle fetch stages ;; 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/from (seq pages-index)) (rx/mapcat @@ -207,7 +188,7 @@ (rx/map #(assoc % :synced-at synced-at))))) (rx/merge-map (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/merge-map (fn [{:keys [id] :as file}] diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 78109f41f..9d8221640 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -8,10 +8,12 @@ (:require [app.common.data.macros :as dm] [app.common.logging :as log] + [app.common.transit :as t] [app.common.types.shape.layout :as ctl] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.undo :as dwu] + [app.main.repo :as rp] [app.util.router :as rt] [beicon.core :as rx] [potok.core :as ptk])) @@ -19,6 +21,30 @@ ;; Change this to :info :debug or :trace to debug this module (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? "Check if the state is properly initialized in a workspace. This means it has the `:current-page-id` and `:current-file-id` properly set." @@ -26,11 +52,9 @@ (and (uuid? (:current-file-id state)) (uuid? (:current-page-id state)))) -;; --- Helpers - -(defn interrupt? [e] (= e :interrupt)) - -(declare undo-to-index) +(defn interrupt? + [e] + (= e :interrupt)) (defn- assure-valid-current-page [] @@ -49,9 +73,16 @@ (rx/empty) (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 (ptk/reify ::undo ptk/WatchEvent diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 276f19900..ac2237b93 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -27,6 +27,7 @@ [app.main.data.modal :as modal] [app.main.data.workspace :as-alias dw] [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.libraries-helpers :as dwlh] [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}) (rx/ignore)) (->> (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] (fn [state] (assoc-in state [:workspace-libraries library-id] file)))))