mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 09:21:40 +02:00
♻️ Refactor dashboard state management.
Mainly for performance, also affects backend endpoints.
This commit is contained in:
parent
e7b3f12b71
commit
c70bc5baff
23 changed files with 1110 additions and 1007 deletions
|
@ -11,8 +11,8 @@
|
|||
[app.main.data.modal :as modal]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.context :as ctx]
|
||||
[app.main.ui.components.context-menu :refer [context-menu]]
|
||||
[app.main.ui.context :as ctx]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[app.util.router :as rt]
|
||||
[beicon.core :as rx]
|
||||
|
@ -30,64 +30,53 @@
|
|||
current-team-id (mf/use-ctx ctx/current-team-id)
|
||||
teams (mf/use-state nil)
|
||||
|
||||
on-duplicate-success
|
||||
(fn [new-project]
|
||||
(st/emit! (dm/success (tr "dashboard.success-duplicate-project"))
|
||||
(rt/nav :dashboard-files
|
||||
{:team-id (:team-id new-project)
|
||||
:project-id (:id new-project)})))
|
||||
|
||||
on-duplicate
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
#(let [on-success
|
||||
(fn [new-project]
|
||||
(st/emit! (dm/success (tr "dashboard.success-duplicate-project"))
|
||||
(rt/nav :dashboard-files
|
||||
{:team-id (:team-id new-project)
|
||||
:project-id (:id new-project)})))]
|
||||
(st/emit! (dd/duplicate-project
|
||||
(with-meta project {:on-success on-success})))))
|
||||
(fn []
|
||||
(st/emit! (dd/duplicate-project
|
||||
(with-meta project {:on-success on-duplicate-success}))))
|
||||
|
||||
toggle-pin
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
(st/emitf (dd/toggle-project-pin project)))
|
||||
(st/emitf (dd/toggle-project-pin project))
|
||||
|
||||
on-move-success
|
||||
(fn [team-id]
|
||||
(st/emit! (dd/go-to-projects team-id)))
|
||||
|
||||
on-move
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
(fn [team-id]
|
||||
(let [data {:id (:id project)
|
||||
:team-id team-id}
|
||||
|
||||
mdata {:on-success
|
||||
(st/emitf (rt/nav :dashboard-projects
|
||||
{:team-id team-id}))}]
|
||||
|
||||
(fn [team-id]
|
||||
(let [data {:id (:id project) :team-id team-id}
|
||||
mdata {:on-success #(on-move-success team-id)}]
|
||||
(st/emitf (dm/success (tr "dashboard.success-move-project"))
|
||||
(dd/move-project (with-meta data mdata))))))
|
||||
(dd/move-project (with-meta data mdata)))))
|
||||
|
||||
delete-fn
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
(fn [event]
|
||||
(st/emit! (dm/success (tr "dashboard.success-delete-project"))
|
||||
(dd/delete-project project)
|
||||
(rt/nav :dashboard-projects {:team-id (:team-id project)}))))
|
||||
(fn [event]
|
||||
(st/emit! (dm/success (tr "dashboard.success-delete-project"))
|
||||
(dd/delete-project project)
|
||||
(dd/go-to-projects (:team-id project))))
|
||||
|
||||
on-delete
|
||||
(mf/use-callback
|
||||
(mf/deps project)
|
||||
(st/emitf (modal/show
|
||||
{:type :confirm
|
||||
:title (tr "modals.delete-project-confirm.title")
|
||||
:message (tr "modals.delete-project-confirm.message")
|
||||
:accept-label (tr "modals.delete-project-confirm.accept")
|
||||
:on-accept delete-fn})))]
|
||||
(st/emitf
|
||||
(modal/show
|
||||
{:type :confirm
|
||||
:title (tr "modals.delete-project-confirm.title")
|
||||
:message (tr "modals.delete-project-confirm.message")
|
||||
:accept-label (tr "modals.delete-project-confirm.accept")
|
||||
:on-accept delete-fn}))]
|
||||
|
||||
(mf/use-layout-effect
|
||||
(mf/deps show?)
|
||||
(fn []
|
||||
(if show?
|
||||
(->> (rp/query! :teams)
|
||||
(rx/map (fn [teams]
|
||||
(remove #(= (:id %) current-team-id) teams)))
|
||||
(rx/subs #(reset! teams %)))
|
||||
(reset! teams []))))
|
||||
(mf/use-effect
|
||||
(fn []
|
||||
(->> (rp/query! :teams)
|
||||
(rx/map (fn [teams]
|
||||
(into [] (remove #(= (:id %) current-team-id)) teams)))
|
||||
(rx/subs #(reset! teams %)))))
|
||||
|
||||
(when @teams
|
||||
[:& context-menu {:on-close on-menu-close
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue