mirror of
https://github.com/penpot/penpot.git
synced 2025-07-08 19:27:18 +02:00
✨ Add some minor performance improvements to dashboard components
This commit is contained in:
parent
35969e9f26
commit
bf3888585a
4 changed files with 32 additions and 27 deletions
|
@ -893,8 +893,8 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [origin-project (get-in state [:dashboard-files (first ids) :project-id])]
|
(let [origin-project (get-in state [:dashboard-files (first ids) :project-id])]
|
||||||
(-> state
|
(-> state
|
||||||
(d/update-in-when [:dashboard-projects origin-project :count] #(- % (count ids)))
|
(d/update-in-when [:dashboard-projects origin-project] update :count #(- % (count ids)))
|
||||||
(d/update-in-when [:dashboard-projects project-id :count] #(+ % (count ids))))))
|
(d/update-in-when [:dashboard-projects project-id] update :count #(+ % (count ids))))))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
|
|
|
@ -159,8 +159,8 @@
|
||||||
[:span (tr "dashboard.libraries-and-templates")]
|
[:span (tr "dashboard.libraries-and-templates")]
|
||||||
[:span.icon (if collapsed i/arrow-up i/arrow-down)]]]
|
[:span.icon (if collapsed i/arrow-up i/arrow-down)]]]
|
||||||
[:div.content {:ref content-ref
|
[:div.content {:ref content-ref
|
||||||
:style {:left @card-offset :width (str container-size "px")}}
|
:style {:left @card-offset :width (str container-size "px")}}
|
||||||
|
|
||||||
(for [num-item (range (count templates)) :let [item (nth templates num-item)]]
|
(for [num-item (range (count templates)) :let [item (nth templates num-item)]]
|
||||||
(let [is-visible? (and (>= num-item first-visible-card) (<= num-item last-visible-card))]
|
(let [is-visible? (and (>= num-item first-visible-card) (<= num-item last-visible-card))]
|
||||||
[:a.card-container {:tab-index (if (or (not is-visible?) collapsed)
|
[:a.card-container {:tab-index (if (or (not is-visible?) collapsed)
|
||||||
|
@ -227,25 +227,31 @@
|
||||||
[{:keys [team projects project section search-term profile] :as props}]
|
[{:keys [team projects project section search-term profile] :as props}]
|
||||||
(let [container (mf/use-ref)
|
(let [container (mf/use-ref)
|
||||||
content-width (mf/use-state 0)
|
content-width (mf/use-state 0)
|
||||||
default-project-id
|
|
||||||
(->> (vals projects)
|
|
||||||
(d/seek :is-default)
|
|
||||||
(:id))
|
|
||||||
on-resize
|
|
||||||
(fn [_]
|
|
||||||
(let [dom (mf/ref-val container)
|
|
||||||
width (obj/get dom "clientWidth")]
|
|
||||||
(reset! content-width width)))]
|
|
||||||
|
|
||||||
(mf/use-effect
|
default-project-id
|
||||||
#(let [key1 (events/listen js/window "resize" on-resize)]
|
(mf/with-memo [projects]
|
||||||
(fn []
|
(->> (vals projects)
|
||||||
(events/unlistenByKey key1))))
|
(d/seek :is-default)
|
||||||
|
(:id)))
|
||||||
|
|
||||||
|
on-resize
|
||||||
|
(mf/use-fn
|
||||||
|
(fn [_]
|
||||||
|
(let [dom (mf/ref-val container)
|
||||||
|
width (obj/get dom "clientWidth")]
|
||||||
|
(reset! content-width width))))
|
||||||
|
|
||||||
|
clear-selected-fn
|
||||||
|
(mf/use-fn
|
||||||
|
#(st/emit! (dd/clear-selected-files)))]
|
||||||
|
|
||||||
|
(mf/with-effect []
|
||||||
|
(let [key1 (events/listen js/window "resize" on-resize)]
|
||||||
|
#(events/unlistenByKey key1)))
|
||||||
|
|
||||||
(mf/use-effect on-resize)
|
(mf/use-effect on-resize)
|
||||||
|
|
||||||
[:div.dashboard-content {:on-click #(st/emit! (dd/clear-selected-files))
|
[:div.dashboard-content {:on-click clear-selected-fn :ref container}
|
||||||
:ref container}
|
|
||||||
(case section
|
(case section
|
||||||
:dashboard-projects
|
:dashboard-projects
|
||||||
[:*
|
[:*
|
||||||
|
@ -280,8 +286,7 @@
|
||||||
:search-term search-term}]
|
:search-term search-term}]
|
||||||
|
|
||||||
:dashboard-libraries
|
:dashboard-libraries
|
||||||
[*
|
[:& libraries-page {:team team}]
|
||||||
[:& libraries-page {:team team}]]
|
|
||||||
|
|
||||||
:dashboard-team-members
|
:dashboard-team-members
|
||||||
[:& team-members-page {:team team :profile profile}]
|
[:& team-members-page {:team team :profile profile}]
|
||||||
|
|
|
@ -131,7 +131,7 @@
|
||||||
|
|
||||||
on-move
|
on-move
|
||||||
(fn [team-id project-id]
|
(fn [team-id project-id]
|
||||||
(let [params {:ids (set (map :id files))
|
(let [params {:ids (into #{} (map :id) files)
|
||||||
:project-id project-id}]
|
:project-id project-id}]
|
||||||
(fn []
|
(fn []
|
||||||
(st/emit! (dd/move-files
|
(st/emit! (dd/move-files
|
||||||
|
@ -213,7 +213,7 @@
|
||||||
(rx/map group-by-team)
|
(rx/map group-by-team)
|
||||||
(rx/subs #(when (mf/ref-val mounted-ref)
|
(rx/subs #(when (mf/ref-val mounted-ref)
|
||||||
(reset! teams %)))))))
|
(reset! teams %)))))))
|
||||||
|
|
||||||
(when current-team
|
(when current-team
|
||||||
(let [sub-options (concat (vec (for [project current-projects]
|
(let [sub-options (concat (vec (for [project current-projects]
|
||||||
{:option-name (get-project-name project)
|
{:option-name (get-project-name project)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
on-menu-click
|
on-menu-click
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [position (dom/get-client-position event)]
|
(let [position (dom/get-client-position event)]
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(swap! local assoc :menu-open true :menu-pos position))))
|
(swap! local assoc :menu-open true :menu-pos position))))
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
|
|
||||||
[:header.dashboard-header
|
[:header.dashboard-header
|
||||||
(if (:is-default project)
|
(if (:is-default project)
|
||||||
[:div.dashboard-title#dashboard-drafts-title
|
[:div.dashboard-title#dashboard-drafts-title
|
||||||
[:h1 (tr "labels.drafts")]]
|
[:h1 (tr "labels.drafts")]]
|
||||||
|
|
||||||
(if (:edition @local)
|
(if (:edition @local)
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
:on-import on-import}]
|
:on-import on-import}]
|
||||||
|
|
||||||
[:div.dashboard-header-actions
|
[:div.dashboard-header-actions
|
||||||
[:a.btn-secondary.btn-small
|
[:a.btn-secondary.btn-small
|
||||||
{:tab-index "0"
|
{:tab-index "0"
|
||||||
:on-click on-create-click
|
:on-click on-create-click
|
||||||
:data-test "new-file"
|
:data-test "new-file"
|
||||||
|
@ -114,7 +114,7 @@
|
||||||
|
|
||||||
[:div.icon.tooltip.tooltip-bottom-left
|
[:div.icon.tooltip.tooltip-bottom-left
|
||||||
{:tab-index "0"
|
{:tab-index "0"
|
||||||
:on-click on-menu-click
|
:on-click on-menu-click
|
||||||
:alt (tr "dashboard.options")
|
:alt (tr "dashboard.options")
|
||||||
:on-key-down (fn [event]
|
:on-key-down (fn [event]
|
||||||
(when (kbd/enter? event)
|
(when (kbd/enter? event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue