mirror of
https://github.com/penpot/penpot.git
synced 2025-03-14 16:51:18 -05:00
✨ Adapt frontend code to backend changes.
This commit is contained in:
parent
e3faddeb6b
commit
7ab7a87a88
4 changed files with 115 additions and 118 deletions
|
@ -163,9 +163,9 @@
|
||||||
(ptk/reify ::fetch-projects
|
(ptk/reify ::fetch-projects
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(->> (rp/query :projects-by-team {:team-id team-id})
|
(->> (rp/query :projects {:team-id team-id})
|
||||||
(rx/map projects-fetched)
|
(rx/map projects-fetched)
|
||||||
(rx/catch (fn [error]
|
#_(rx/catch (fn [error]
|
||||||
(rx/of (rt/nav' :auth-login))))))))
|
(rx/of (rt/nav' :auth-login))))))))
|
||||||
|
|
||||||
(defn projects-fetched
|
(defn projects-fetched
|
||||||
|
@ -224,26 +224,16 @@
|
||||||
|
|
||||||
;; --- Fetch Shared Files
|
;; --- Fetch Shared Files
|
||||||
|
|
||||||
(declare shared-files-fetched)
|
|
||||||
|
|
||||||
(defn fetch-shared-files
|
(defn fetch-shared-files
|
||||||
[]
|
[team-id]
|
||||||
(ptk/reify ::fetch-shared-files
|
(letfn [(on-fetched [files state]
|
||||||
ptk/WatchEvent
|
(let [files (d/index-by :id files)]
|
||||||
(watch [_ state stream]
|
(assoc state :files files)))]
|
||||||
(let [params {}]
|
(ptk/reify ::fetch-shared-files
|
||||||
(->> (rp/query :shared-files params)
|
ptk/WatchEvent
|
||||||
(rx/map shared-files-fetched))))))
|
(watch [_ state stream]
|
||||||
|
(->> (rp/query :shared-files {:team-id team-id})
|
||||||
(defn shared-files-fetched
|
(rx/map #(partial on-fetched %)))))))
|
||||||
[files]
|
|
||||||
(us/verify (s/every ::file) files)
|
|
||||||
(ptk/reify ::shared-files-fetched
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(let [state (dissoc state :files)
|
|
||||||
files (d/index-by :id files)]
|
|
||||||
(assoc state :files files)))))
|
|
||||||
|
|
||||||
;; --- Fetch recent files
|
;; --- Fetch recent files
|
||||||
|
|
||||||
|
|
|
@ -266,13 +266,13 @@
|
||||||
(declare shared-files-fetched)
|
(declare shared-files-fetched)
|
||||||
|
|
||||||
(defn fetch-shared-files
|
(defn fetch-shared-files
|
||||||
[]
|
[{:keys [team-id] :as params}]
|
||||||
|
(us/assert ::us/uuid team-id)
|
||||||
(ptk/reify ::fetch-shared-files
|
(ptk/reify ::fetch-shared-files
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [params {}]
|
(->> (rp/query :shared-files params)
|
||||||
(->> (rp/query :shared-files params)
|
(rx/map shared-files-fetched)))))
|
||||||
(rx/map shared-files-fetched))))))
|
|
||||||
|
|
||||||
(defn shared-files-fetched
|
(defn shared-files-fetched
|
||||||
[files]
|
[files]
|
||||||
|
|
|
@ -33,10 +33,10 @@
|
||||||
|
|
||||||
(defn- parse-params
|
(defn- parse-params
|
||||||
[route profile]
|
[route profile]
|
||||||
(let [search-term (get-in route [:params :query :search-term])
|
(let [route-name (get-in route [:data :name])
|
||||||
route-name (get-in route [:data :name])
|
search-term (get-in route [:params :query :search-term])
|
||||||
team-id (get-in route [:params :path :team-id])
|
team-id (get-in route [:params :path :team-id])
|
||||||
project-id (get-in route [:params :path :project-id])]
|
project-id (get-in route [:params :path :project-id])]
|
||||||
(cond->
|
(cond->
|
||||||
{:search-term search-term}
|
{:search-term search-term}
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@
|
||||||
(uuid-str? project-id)
|
(uuid-str? project-id)
|
||||||
(assoc :project-id (uuid project-id))
|
(assoc :project-id (uuid project-id))
|
||||||
|
|
||||||
|
;; TODO: delete the usage of "drafts"
|
||||||
|
|
||||||
(= "drafts" project-id)
|
(= "drafts" project-id)
|
||||||
(assoc :project-id (:default-project-id profile)))))
|
(assoc :project-id (:default-project-id profile)))))
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.i18n :refer (tr)]
|
[app.util.i18n :as i18n :refer [t tr]]
|
||||||
[app.util.data :refer [classnames matches-search]]
|
[app.util.data :refer [classnames matches-search]]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
|
@ -20,90 +20,96 @@
|
||||||
|
|
||||||
(mf/defc libraries-tab
|
(mf/defc libraries-tab
|
||||||
[{:keys [file libraries shared-files] :as props}]
|
[{:keys [file libraries shared-files] :as props}]
|
||||||
(let [state (mf/use-state {:search-term ""})
|
(let [search-term (mf/use-state "")
|
||||||
|
|
||||||
sorted-libraries (->> (vals libraries)
|
sorted-libraries (->> (vals libraries)
|
||||||
(sort-by #(str/lower (:name %))))
|
(sort-by #(str/lower (:name %))))
|
||||||
|
|
||||||
filtered-files (->> shared-files
|
filtered-files (->> shared-files
|
||||||
(filter #(not= (:id %) (:id file)))
|
(filter #(not= (:id %) (:id file)))
|
||||||
(filter #(nil? (get libraries (:id %))))
|
(filter #(nil? (get libraries (:id %))))
|
||||||
(filter #(matches-search (:name %) (:search-term @state)))
|
(filter #(matches-search (:name %) @search-term))
|
||||||
(sort-by #(str/lower (:name %))))
|
(sort-by #(str/lower (:name %))))
|
||||||
|
|
||||||
on-search-term-change (fn [event]
|
on-search-term-change
|
||||||
(let [value (-> (dom/get-target event)
|
(mf/use-callback
|
||||||
(dom/get-value))]
|
(fn [event]
|
||||||
(swap! state assoc :search-term value)))
|
(let [value (-> (dom/get-target event)
|
||||||
|
(dom/get-value))]
|
||||||
|
(reset! search-term value))))
|
||||||
|
|
||||||
on-search-clear-click (fn [event]
|
on-search-clear
|
||||||
(swap! state assoc :search-term ""))
|
(mf/use-callback
|
||||||
|
(fn [event]
|
||||||
|
(reset! search-term "")))
|
||||||
|
|
||||||
link-library (fn [library-id]
|
link-library
|
||||||
(st/emit! (dw/link-file-to-library (:id file) library-id)))
|
(mf/use-callback (mf/deps file) #(st/emit! (dw/link-file-to-library (:id file) %)))
|
||||||
|
|
||||||
unlink-library (fn [library-id]
|
unlink-library
|
||||||
(st/emit! (dw/unlink-file-from-library (:id file) library-id)))
|
(mf/use-callback (mf/deps file) #(st/emit! (dw/unlink-file-from-library (:id file) %)))
|
||||||
|
|
||||||
contents-str (fn [library graphics-count colors-count]
|
contents-str
|
||||||
(str
|
(fn [library graphics-count colors-count]
|
||||||
(str/join " · "
|
;; Include a so this block has always some content
|
||||||
(cond-> []
|
(str
|
||||||
(< 0 graphics-count)
|
(str/join " · "
|
||||||
(conj (tr "workspace.libraries.graphics" graphics-count))
|
(cond-> []
|
||||||
|
(< 0 graphics-count)
|
||||||
|
(conj (tr "workspace.libraries.graphics" graphics-count))
|
||||||
|
|
||||||
(< 0 colors-count)
|
(< 0 colors-count)
|
||||||
(conj (tr "workspace.libraries.colors" colors-count))))
|
(conj (tr "workspace.libraries.colors" colors-count))))
|
||||||
"\u00A0"))] ;; Include a so this block has always some content
|
"\u00A0"))]
|
||||||
[:*
|
[:*
|
||||||
[:div.section
|
[:div.section
|
||||||
[:div.section-title (tr "workspace.libraries.in-this-file")]
|
[:div.section-title (tr "workspace.libraries.in-this-file")]
|
||||||
[:div.section-list
|
[:div.section-list
|
||||||
[:div.section-list-item
|
[:div.section-list-item
|
||||||
[:div.item-name (tr "workspace.libraries.file-library")]
|
[:div.item-name (tr "workspace.libraries.file-library")]
|
||||||
[:div.item-contents (contents-str file
|
[:div.item-contents (contents-str file
|
||||||
(count (:media-objects file))
|
(count (:media-objects file))
|
||||||
(count (:colors file)))]]
|
(count (:colors file)))]]
|
||||||
(for [library sorted-libraries]
|
(for [library sorted-libraries]
|
||||||
[:div.section-list-item {:key (:id library)}
|
[:div.section-list-item {:key (:id library)}
|
||||||
[:div.item-name (:name library)]
|
[:div.item-name (:name library)]
|
||||||
[:div.item-contents (contents-str library
|
[:div.item-contents (contents-str library
|
||||||
(count (:media-objects library))
|
(count (:media-objects library))
|
||||||
(count (:colors library)))]
|
(count (:colors library)))]
|
||||||
[:input.item-button {:type "button"
|
[:input.item-button {:type "button"
|
||||||
:value (tr "workspace.libraries.remove")
|
:value (tr "workspace.libraries.remove")
|
||||||
:on-click #(unlink-library (:id library))}]])
|
:on-click #(unlink-library (:id library))}]])
|
||||||
]]
|
]]
|
||||||
[:div.section
|
[:div.section
|
||||||
[:div.section-title (tr "workspace.libraries.shared-libraries")]
|
[:div.section-title (tr "workspace.libraries.shared-libraries")]
|
||||||
[:div.libraries-search
|
[:div.libraries-search
|
||||||
[:input.search-input
|
[:input.search-input
|
||||||
{:placeholder (tr "workspace.libraries.search-shared-libraries")
|
{:placeholder (tr "workspace.libraries.search-shared-libraries")
|
||||||
:type "text"
|
:type "text"
|
||||||
:value (:search-term @state)
|
:value @search-term
|
||||||
:on-change on-search-term-change}]
|
:on-change on-search-term-change}]
|
||||||
(if (str/empty? (:search-term @state))
|
(if (str/empty? @search-term)
|
||||||
[:div.search-icon
|
[:div.search-icon
|
||||||
i/search]
|
i/search]
|
||||||
[:div.search-icon.search-close
|
[:div.search-icon.search-close
|
||||||
{:on-click on-search-clear-click}
|
{:on-click on-search-clear}
|
||||||
i/close])]
|
i/close])]
|
||||||
(if (> (count filtered-files) 0)
|
(if (> (count filtered-files) 0)
|
||||||
[:div.section-list
|
[:div.section-list
|
||||||
(for [file filtered-files]
|
(for [file filtered-files]
|
||||||
[:div.section-list-item {:key (:id file)}
|
[:div.section-list-item {:key (:id file)}
|
||||||
[:div.item-name (:name file)]
|
[:div.item-name (:name file)]
|
||||||
[:div.item-contents (contents-str file
|
[:div.item-contents (contents-str file
|
||||||
(:graphics-count file)
|
(:graphics-count file)
|
||||||
(:colors-count file))]
|
(:colors-count file))]
|
||||||
[:input.item-button {:type "button"
|
[:input.item-button {:type "button"
|
||||||
:value (tr "workspace.libraries.add")
|
:value (tr "workspace.libraries.add")
|
||||||
:on-click #(link-library (:id file))}]])]
|
:on-click #(link-library (:id file))}]])]
|
||||||
[:div.section-list-empty
|
[:div.section-list-empty
|
||||||
i/library
|
i/library
|
||||||
(if (str/empty? (:search-term @state))
|
(if (str/empty? @search-term)
|
||||||
(tr "workspace.libraries.no-shared-libraries-available")
|
(tr "workspace.libraries.no-shared-libraries-available")
|
||||||
(tr "workspace.libraries.no-matches-for" (:search-term @state)))])]]))
|
(tr "workspace.libraries.no-matches-for" @search-term))])]]))
|
||||||
|
|
||||||
|
|
||||||
(mf/defc updates-tab
|
(mf/defc updates-tab
|
||||||
|
@ -113,23 +119,22 @@
|
||||||
|
|
||||||
(mf/defc libraries-dialog
|
(mf/defc libraries-dialog
|
||||||
[{:keys [] :as ctx}]
|
[{:keys [] :as ctx}]
|
||||||
(let [state (mf/use-state {:current-tab :libraries})
|
(let [selected-tab (mf/use-state :libraries)
|
||||||
|
|
||||||
current-tab (:current-tab @state)
|
|
||||||
|
|
||||||
|
locale (mf/deref i18n/locale)
|
||||||
|
project (mf/deref refs/workspace-project)
|
||||||
file (mf/deref refs/workspace-file)
|
file (mf/deref refs/workspace-file)
|
||||||
libraries (mf/deref refs/workspace-libraries)
|
libraries (mf/deref refs/workspace-libraries)
|
||||||
shared-files (mf/deref refs/workspace-shared-files)
|
shared-files (mf/deref refs/workspace-shared-files)
|
||||||
|
|
||||||
change-tab (fn [tab]
|
change-tab #(reset! selected-tab %)
|
||||||
(swap! state assoc :current-tab tab))
|
close #(modal/hide!)]
|
||||||
|
|
||||||
close (fn [event]
|
|
||||||
(dom/prevent-default event)
|
|
||||||
(modal/hide!))]
|
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
#(st/emit! (dw/fetch-shared-files)))
|
(mf/deps project)
|
||||||
|
(fn []
|
||||||
|
(when (:team-id project)
|
||||||
|
(st/emit! (dw/fetch-shared-files {:team-id (:team-id project)})))))
|
||||||
|
|
||||||
[:div.modal-overlay
|
[:div.modal-overlay
|
||||||
[:div.modal.libraries-dialog
|
[:div.modal.libraries-dialog
|
||||||
|
@ -137,15 +142,15 @@
|
||||||
[:div.modal-content
|
[:div.modal-content
|
||||||
[:div.libraries-header
|
[:div.libraries-header
|
||||||
[:div.header-item
|
[:div.header-item
|
||||||
{:class (classnames :active (= current-tab :libraries))
|
{:class (classnames :active (= @selected-tab :libraries))
|
||||||
:on-click #(change-tab :libraries)}
|
:on-click #(change-tab :libraries)}
|
||||||
(tr "workspace.libraries.libraries")]
|
(t locale "workspace.libraries.libraries")]
|
||||||
[:div.header-item
|
[:div.header-item
|
||||||
{:class (classnames :active (= current-tab :updates))
|
{:class (classnames :active (= @selected-tab :updates))
|
||||||
:on-click #(change-tab :updates)}
|
:on-click #(change-tab :updates)}
|
||||||
(tr "workspace.libraries.updates")]]
|
(t locale "workspace.libraries.updates")]]
|
||||||
[:div.libraries-content
|
[:div.libraries-content
|
||||||
(case current-tab
|
(case @selected-tab
|
||||||
:libraries
|
:libraries
|
||||||
[:& libraries-tab {:file file
|
[:& libraries-tab {:file file
|
||||||
:libraries libraries
|
:libraries libraries
|
||||||
|
|
Loading…
Add table
Reference in a new issue