mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 07:16:07 -05:00
✨ Improve loading state on dashboard.
This commit is contained in:
parent
b2bd4bd694
commit
404fae9c7c
5 changed files with 51 additions and 38 deletions
|
@ -351,6 +351,13 @@
|
||||||
"es" : "Todavía no hay ningún archivo aquí"
|
"es" : "Todavía no hay ningún archivo aquí"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dashboard.loading-files" : {
|
||||||
|
"used-in" : [ "src/app/main/ui/dashboard/grid.cljs:189" ],
|
||||||
|
"translations" : {
|
||||||
|
"en" : "loading your files ...",
|
||||||
|
"es" : "cargando tus ficheros ..."
|
||||||
|
}
|
||||||
|
},
|
||||||
"dashboard.invite-profile" : {
|
"dashboard.invite-profile" : {
|
||||||
"used-in" : [ "src/app/main/ui/dashboard/team.cljs:72" ],
|
"used-in" : [ "src/app/main/ui/dashboard/team.cljs:72" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
|
|
|
@ -117,25 +117,9 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [profile (:profile state)]
|
(let [profile (:profile state)]
|
||||||
(->> (rx/merge (ptk/watch (fetch-team params) state stream)
|
(rx/merge (ptk/watch (fetch-team params) state stream)
|
||||||
(ptk/watch (fetch-projects {:team-id id}) state stream)
|
(ptk/watch (fetch-projects {:team-id id}) state stream)
|
||||||
(ptk/watch (du/fetch-users {:team-id id}) state stream))
|
(ptk/watch (du/fetch-users {:team-id id}) state stream))))))
|
||||||
(rx/catch (fn [{:keys [type code] :as error}]
|
|
||||||
(cond
|
|
||||||
(and (= :not-found type)
|
|
||||||
(not= id (:default-team-id profile)))
|
|
||||||
(rx/of (rt/nav :dashboard-projects {:team-id (:default-team-id profile)})
|
|
||||||
(dm/error "Team does not found"))
|
|
||||||
|
|
||||||
(and (= :validation type)
|
|
||||||
(= :not-authorized code)
|
|
||||||
(not= id (:default-team-id profile)))
|
|
||||||
(rx/of (rt/nav :dashboard-projects {:team-id (:default-team-id profile)})
|
|
||||||
(dm/error "Team does not found"))
|
|
||||||
|
|
||||||
:else
|
|
||||||
(rx/throw error)))))))))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Search Files
|
;; --- Search Files
|
||||||
|
|
||||||
|
@ -197,23 +181,29 @@
|
||||||
[{:keys [team-id] :as params}]
|
[{:keys [team-id] :as params}]
|
||||||
(us/assert ::us/uuid team-id)
|
(us/assert ::us/uuid team-id)
|
||||||
(ptk/reify ::fetch-recent-files
|
(ptk/reify ::fetch-recent-files
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(dissoc state :files :recent-files))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [params {:team-id team-id}]
|
(let [params {:team-id team-id}]
|
||||||
(->> (rp/query :recent-files params)
|
(->> (rp/query :recent-files params)
|
||||||
(rx/map recent-files-fetched))))))
|
(rx/map #(recent-files-fetched team-id %)))))))
|
||||||
|
|
||||||
(defn recent-files-fetched
|
(defn recent-files-fetched
|
||||||
[files]
|
[team-id files]
|
||||||
(ptk/reify ::recent-files-fetched
|
(ptk/reify ::recent-files-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(reduce-kv (fn [state project-id files]
|
(let [projects (keys (get-in state [:projects team-id]))]
|
||||||
|
(reduce (fn [state project-id]
|
||||||
|
(let [files (filter #(= project-id (:project-id %)) files)]
|
||||||
(-> state
|
(-> state
|
||||||
(update-in [:files project-id] merge (d/index-by :id files))
|
(update-in [:files project-id] merge (d/index-by :id files))
|
||||||
(assoc-in [:recent-files project-id] (into #{} (map :id) files))))
|
(assoc-in [:recent-files project-id] (into #{} (map :id) files)))))
|
||||||
state
|
state
|
||||||
(group-by :project-id files)))))
|
projects)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Data Modification
|
;; Data Modification
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
:profile profile
|
:profile profile
|
||||||
:section section
|
:section section
|
||||||
:search-term search-term}]
|
:search-term search-term}]
|
||||||
(when team
|
(when (and team (seq projects))
|
||||||
[:& dashboard-content {:projects projects
|
[:& dashboard-content {:projects projects
|
||||||
:profile profile
|
:profile profile
|
||||||
:project project
|
:project project
|
||||||
|
|
|
@ -183,16 +183,25 @@
|
||||||
|
|
||||||
(mf/defc empty-placeholder
|
(mf/defc empty-placeholder
|
||||||
[]
|
[]
|
||||||
(let [locale (mf/deref i18n/locale)]
|
|
||||||
[:div.grid-empty-placeholder
|
[:div.grid-empty-placeholder
|
||||||
[:div.icon i/file-html]
|
[:div.icon i/file-html]
|
||||||
[:div.text (t locale "dashboard.empty-files")]]))
|
[:div.text (tr "dashboard.empty-files")]])
|
||||||
|
|
||||||
|
(mf/defc loading-placeholder
|
||||||
|
[]
|
||||||
|
[:div.grid-empty-placeholder
|
||||||
|
[:div.icon i/loader]
|
||||||
|
[:div.text (tr "dashboard.loading-files")]])
|
||||||
|
|
||||||
(mf/defc grid
|
(mf/defc grid
|
||||||
[{:keys [id opts files] :as props}]
|
[{:keys [id opts files] :as props}]
|
||||||
(let [locale (mf/deref i18n/locale)]
|
(let [locale (mf/deref i18n/locale)]
|
||||||
[:section.dashboard-grid
|
[:section.dashboard-grid
|
||||||
(if (pos? (count files))
|
(cond
|
||||||
|
(nil? files)
|
||||||
|
[:& loading-placeholder]
|
||||||
|
|
||||||
|
(seq files)
|
||||||
[:div.grid-row
|
[:div.grid-row
|
||||||
(for [item files]
|
(for [item files]
|
||||||
[:& grid-item
|
[:& grid-item
|
||||||
|
@ -200,6 +209,7 @@
|
||||||
:file item
|
:file item
|
||||||
:key (:id item)}])]
|
:key (:id item)}])]
|
||||||
|
|
||||||
|
:else
|
||||||
[:& empty-placeholder])]))
|
[:& empty-placeholder])]))
|
||||||
|
|
||||||
(mf/defc line-grid-row
|
(mf/defc line-grid-row
|
||||||
|
@ -255,9 +265,15 @@
|
||||||
[{:keys [project-id opts files on-load-more] :as props}]
|
[{:keys [project-id opts files on-load-more] :as props}]
|
||||||
(let [locale (mf/deref i18n/locale)]
|
(let [locale (mf/deref i18n/locale)]
|
||||||
[:section.dashboard-grid
|
[:section.dashboard-grid
|
||||||
(if (pos? (count files))
|
(cond
|
||||||
|
(nil? files)
|
||||||
|
[:& loading-placeholder]
|
||||||
|
|
||||||
|
(seq files)
|
||||||
[:& line-grid-row {:files files
|
[:& line-grid-row {:files files
|
||||||
:on-load-more on-load-more
|
:on-load-more on-load-more
|
||||||
:locale locale}]
|
:locale locale}]
|
||||||
|
|
||||||
|
:else
|
||||||
[:& empty-placeholder])]))
|
[:& empty-placeholder])]))
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
files-map (mf/deref files-ref)
|
files-map (mf/deref files-ref)
|
||||||
recent-ids (mf/deref recent-ref)
|
recent-ids (mf/deref recent-ref)
|
||||||
|
|
||||||
files (->> recent-ids
|
files (some->> recent-ids
|
||||||
(map #(get files-map %))
|
(map #(get files-map %))
|
||||||
(sort-by :modified-at)
|
(sort-by :modified-at)
|
||||||
(reverse))
|
(reverse))
|
||||||
|
|
Loading…
Add table
Reference in a new issue