From 2ce766c49ea20d6d43d80ea3c23c75f2854ed3bb Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 26 May 2022 17:55:19 +0200 Subject: [PATCH] :bug: Fix performance issue with focus mode --- frontend/src/app/main/ui/workspace/shapes/frame.cljs | 5 ++++- .../ui/workspace/shapes/frame/thumbnail_render.cljs | 11 +++++++++-- frontend/src/app/main/ui/workspace/viewport.cljs | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/frame.cljs b/frontend/src/app/main/ui/workspace/shapes/frame.cljs index dcfc8b3e5..9d420f3fb 100644 --- a/frontend/src/app/main/ui/workspace/shapes/frame.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/frame.cljs @@ -126,5 +126,8 @@ :ref on-frame-load :opacity (when (:hidden shape) 0)} [:& ff/fontfaces-style {:fonts fonts}] - [:g.frame-thumbnail-wrapper {:id (dm/str "thumbnail-container-" (:id shape))} + [:g.frame-thumbnail-wrapper + {:id (dm/str "thumbnail-container-" (:id shape)) + ;; Hide the thumbnail when not displaying + :opacity (when (and @rendered? (not thumbnail?)) 0)} thumbnail-renderer]]])))) diff --git a/frontend/src/app/main/ui/workspace/shapes/frame/thumbnail_render.cljs b/frontend/src/app/main/ui/workspace/shapes/frame/thumbnail_render.cljs index 87100daa3..35bd2d49c 100644 --- a/frontend/src/app/main/ui/workspace/shapes/frame/thumbnail_render.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/frame/thumbnail_render.cljs @@ -9,7 +9,9 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.common.math :as mth] + [app.main.data.workspace.thumbnails :as dwt] [app.main.refs :as refs] + [app.main.store :as st] [app.main.ui.hooks :as hooks] [app.main.ui.shapes.frame :as frame] [app.util.dom :as dom] @@ -83,7 +85,12 @@ img-node (mf/ref-val frame-image-ref)] (when (draw-thumbnail-canvas! canvas-node img-node) (reset! image-url nil) - (reset! render-frame? false)))))) + (reset! render-frame? false)) + + ;; If we don't have the thumbnail data saved (normaly the first load) we update the data + ;; when available + (when (not @thumbnail-data-ref) + (st/emit! (dwt/update-thumbnail page-id id) )))))) generate-thumbnail (mf/use-callback @@ -183,7 +190,7 @@ :width fixed-width :height fixed-height ;; DEBUG - :style {:filter (when (debug? :thumbnails) "sepia(1)")}}]] + :style {:filter (when (debug? :thumbnails) "invert(1)")}}]] (when (some? @image-url) [:image {:ref frame-image-ref diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 33419511a..bcd31fa34 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -71,8 +71,8 @@ focus (mf/deref refs/workspace-focus-selected) objects-ref (mf/use-memo #(refs/workspace-page-objects-by-id page-id)) - base-objects (-> (mf/deref objects-ref) - (ui-hooks/with-focus-objects focus)) + objects (mf/deref objects-ref) + base-objects (-> objects (ui-hooks/with-focus-objects focus)) modifiers (mf/deref refs/workspace-modifiers) @@ -245,7 +245,7 @@ [:g {:pointer-events "none" :opacity 0} [:& stv/viewport-texts {:key (dm/str "texts-" page-id) :page-id page-id - :objects base-objects + :objects objects :modifiers modifiers :edition edition}]]]