diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 8d85661df..c73c93ad2 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -194,7 +194,8 @@ (ptk/reify ::initialize-page ptk/WatchEvent (watch [_ state _] - (when-not (contains? (get-in state [:workspace-data :pages-index]) page-id) + (if (contains? (get-in state [:workspace-data :pages-index]) page-id) + (rx/of (dwp/preload-data-uris)) (let [default-page-id (get-in state [:workspace-data :pages 0])] (rx/of (go-to-page default-page-id))))) diff --git a/frontend/src/app/main/data/workspace/persistence.cljs b/frontend/src/app/main/data/workspace/persistence.cljs index 9a6793b86..1069d00a8 100644 --- a/frontend/src/app/main/data/workspace/persistence.cljs +++ b/frontend/src/app/main/data/workspace/persistence.cljs @@ -14,6 +14,7 @@ [app.common.spec.change :as spec.change] [app.common.spec.file :as spec.file] [app.common.uuid :as uuid] + [app.config :as cfg] [app.main.data.dashboard :as dd] [app.main.data.events :as ev] [app.main.data.fonts :as df] @@ -653,6 +654,9 @@ frame-changes (->> stream (rx/filter dch/commit-changes?) + + ;; Async so we wait for additional side-effects of commit-changes + (rx/observe-on :async) (rx/filter (comp not thumbnail-change?)) (rx/with-latest-from objects-stream) (rx/map extract-frame-changes) @@ -678,3 +682,26 @@ (rx/buffer-until (->> frame-changes (rx/debounce 1000))) (rx/flat-map #(reduce set/union %)) (rx/map #(update-frame-thumbnail %))))))))) + +(defn preload-data-uris + "Preloads the image data so it's ready when necesary" + [] + (ptk/reify ::preload-data-uris + ptk/WatchEvent + (watch [_ state _] + (let [extract-urls + (fn [{:keys [metadata fill-image]}] + (cond + (some? metadata) + [(cfg/resolve-file-media metadata)] + + (some? fill-image) + [(cfg/resolve-file-media fill-image)])) + + uris (into #{} + (comp (mapcat extract-urls) + (filter some?)) + (vals (wsh/lookup-page-objects state)))] + (->> (rx/from uris) + (rx/merge-map #(http/fetch-data-uri % false)) + (rx/ignore)))))) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index a48329c06..73fe95518 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -503,6 +503,7 @@ id-duplicated (when (= (count selected) 1) (first selected))] + ;; Warning: This order is important for the focus mode. (rx/of (dch/commit-changes changes) (select-shapes selected) (memorize-duplicated id-original id-duplicated))))))) diff --git a/frontend/src/app/main/ui/shapes/text/fontfaces.cljs b/frontend/src/app/main/ui/shapes/text/fontfaces.cljs index 5f2ae54fc..9e2730138 100644 --- a/frontend/src/app/main/ui/shapes/text/fontfaces.cljs +++ b/frontend/src/app/main/ui/shapes/text/fontfaces.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.shapes.text.fontfaces (:require [app.common.data :as d] + [app.common.pages.helpers :as cph] [app.main.fonts :as fonts] [app.main.ui.hooks :as hooks] [app.main.ui.shapes.embed :as embed] @@ -76,14 +77,10 @@ {::mf/wrap-props false ::mf/wrap [#(mf/memo' % (mf/check-props ["shapes"]))]} [props] - (let [shapes (->> (obj/get props "shapes") - (filterv #(= :text (:type %)))) - - content (->> shapes (mapv :content)) - - ;; Retrieve the fonts ids used by the text shapes - fonts (->> content - (mapv fonts/get-content-fonts) + (let [;; Retrieve the fonts ids used by the text shapes + fonts (->> (obj/get props "shapes") + (filterv cph/text-shape?) + (mapv (comp fonts/get-content-fonts :content)) (reduce set/union #{}) (hooks/use-equal-memo))]