0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

Improve builtin template fetching management

This commit is contained in:
Andrey Antukh 2023-07-10 11:42:32 +02:00
parent a665339c98
commit 02b41abaf8
3 changed files with 16 additions and 6 deletions

View file

@ -233,7 +233,7 @@
(let [project (-> (db/get-by-id conn :project project-id)
(assoc :is-pinned false))
files (db/query conn :file
{:project-id (:id project)
:deleted-at nil}
@ -412,10 +412,17 @@
(binfile/import!))))
;; --- COMMAND: Retrieve list of builtin templates
;; --- COMMAND: Get list of builtin templates
(s/def ::retrieve-list-of-builtin-templates any?)
(sv/defmethod ::retrieve-list-of-builtin-templates
{::doc/added "1.10"
::doc/deprecated "1.19"}
[cfg _params]
(mapv #(select-keys % [:id :name :thumbnail-uri]) (:templates cfg)))
(sv/defmethod ::get-builtin-templates
{::doc/added "1.19"}
[cfg _params]
(mapv #(select-keys % [:id :name :thumbnail-uri]) (:templates cfg)))

View file

@ -34,7 +34,6 @@
(declare fetch-projects)
(declare fetch-team-members)
(declare fetch-builtin-templates)
(defn initialize
[{:keys [id] :as params}]
@ -62,8 +61,7 @@
(ptk/watch (fetch-projects) state stream)
(ptk/watch (fetch-team-members) state stream)
(ptk/watch (du/fetch-teams) state stream)
(ptk/watch (du/fetch-users {:team-id id}) state stream)
(ptk/watch (fetch-builtin-templates) state stream)))))
(ptk/watch (du/fetch-users {:team-id id}) state stream)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Fetching (context aware: current team)
@ -275,7 +273,7 @@
(ptk/reify ::fetch-builtin-templates
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :retrieve-list-of-builtin-templates)
(->> (rp/cmd! :get-builtin-templates)
(rx/map builtin-templates-fetched)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -8,6 +8,7 @@
(:require
[app.common.data.macros :as dm]
[app.common.math :as mth]
[app.main.data.dashboard :as dd]
[app.main.data.events :as ev]
[app.main.data.modal :as modal]
[app.main.data.users :as du]
@ -226,6 +227,10 @@
]
(mf/with-effect [collapsed]
(when-not collapsed
(st/emit! (dd/fetch-builtin-templates))))
[:div.dashboard-templates-section
{:class (when ^boolean collapsed "collapsed")}
[:& title {:collapsed collapsed}]