0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

Adapt frontend code to backend changes.

This commit is contained in:
Andrey Antukh 2020-08-19 13:06:03 +02:00
parent e3faddeb6b
commit 7ab7a87a88
4 changed files with 115 additions and 118 deletions

View file

@ -163,9 +163,9 @@
(ptk/reify ::fetch-projects
ptk/WatchEvent
(watch [_ state stream]
(->> (rp/query :projects-by-team {:team-id team-id})
(->> (rp/query :projects {:team-id team-id})
(rx/map projects-fetched)
(rx/catch (fn [error]
#_(rx/catch (fn [error]
(rx/of (rt/nav' :auth-login))))))))
(defn projects-fetched
@ -224,26 +224,16 @@
;; --- Fetch Shared Files
(declare shared-files-fetched)
(defn fetch-shared-files
[]
(ptk/reify ::fetch-shared-files
ptk/WatchEvent
(watch [_ state stream]
(let [params {}]
(->> (rp/query :shared-files params)
(rx/map shared-files-fetched))))))
(defn shared-files-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)))))
[team-id]
(letfn [(on-fetched [files state]
(let [files (d/index-by :id files)]
(assoc state :files files)))]
(ptk/reify ::fetch-shared-files
ptk/WatchEvent
(watch [_ state stream]
(->> (rp/query :shared-files {:team-id team-id})
(rx/map #(partial on-fetched %)))))))
;; --- Fetch recent files

View file

@ -266,13 +266,13 @@
(declare shared-files-fetched)
(defn fetch-shared-files
[]
[{:keys [team-id] :as params}]
(us/assert ::us/uuid team-id)
(ptk/reify ::fetch-shared-files
ptk/WatchEvent
(watch [_ state stream]
(let [params {}]
(->> (rp/query :shared-files params)
(rx/map shared-files-fetched))))))
(->> (rp/query :shared-files params)
(rx/map shared-files-fetched)))))
(defn shared-files-fetched
[files]

View file

@ -33,10 +33,10 @@
(defn- parse-params
[route profile]
(let [search-term (get-in route [:params :query :search-term])
route-name (get-in route [:data :name])
team-id (get-in route [:params :path :team-id])
project-id (get-in route [:params :path :project-id])]
(let [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])
project-id (get-in route [:params :path :project-id])]
(cond->
{:search-term search-term}
@ -46,6 +46,8 @@
(uuid-str? project-id)
(assoc :project-id (uuid project-id))
;; TODO: delete the usage of "drafts"
(= "drafts" project-id)
(assoc :project-id (:default-project-id profile)))))

View file

@ -10,7 +10,7 @@
[rumext.alpha :as mf]
[cuerdas.core :as str]
[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.main.store :as st]
[app.main.refs :as refs]
@ -20,90 +20,96 @@
(mf/defc libraries-tab
[{:keys [file libraries shared-files] :as props}]
(let [state (mf/use-state {:search-term ""})
(let [search-term (mf/use-state "")
sorted-libraries (->> (vals libraries)
(sort-by #(str/lower (:name %))))
filtered-files (->> shared-files
(filter #(not= (:id %) (:id file)))
(filter #(nil? (get libraries (:id %))))
(filter #(matches-search (:name %) (:search-term @state)))
(sort-by #(str/lower (:name %))))
filtered-files (->> shared-files
(filter #(not= (:id %) (:id file)))
(filter #(nil? (get libraries (:id %))))
(filter #(matches-search (:name %) @search-term))
(sort-by #(str/lower (:name %))))
on-search-term-change (fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value))]
(swap! state assoc :search-term value)))
on-search-term-change
(mf/use-callback
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value))]
(reset! search-term value))))
on-search-clear-click (fn [event]
(swap! state assoc :search-term ""))
on-search-clear
(mf/use-callback
(fn [event]
(reset! search-term "")))
link-library (fn [library-id]
(st/emit! (dw/link-file-to-library (:id file) library-id)))
link-library
(mf/use-callback (mf/deps file) #(st/emit! (dw/link-file-to-library (:id file) %)))
unlink-library (fn [library-id]
(st/emit! (dw/unlink-file-from-library (:id file) library-id)))
unlink-library
(mf/use-callback (mf/deps file) #(st/emit! (dw/unlink-file-from-library (:id file) %)))
contents-str (fn [library graphics-count colors-count]
(str
(str/join " · "
(cond-> []
(< 0 graphics-count)
(conj (tr "workspace.libraries.graphics" graphics-count))
contents-str
(fn [library graphics-count colors-count]
;; Include a &nbsp; so this block has always some content
(str
(str/join " · "
(cond-> []
(< 0 graphics-count)
(conj (tr "workspace.libraries.graphics" graphics-count))
(< 0 colors-count)
(conj (tr "workspace.libraries.colors" colors-count))))
"\u00A0"))] ;; Include a &nbsp; so this block has always some content
(< 0 colors-count)
(conj (tr "workspace.libraries.colors" colors-count))))
"\u00A0"))]
[:*
[:div.section
[:div.section-title (tr "workspace.libraries.in-this-file")]
[:div.section-list
[:div.section-list-item
[:div.item-name (tr "workspace.libraries.file-library")]
[:div.item-contents (contents-str file
(count (:media-objects file))
(count (:colors file)))]]
(for [library sorted-libraries]
[:div.section-list-item {:key (:id library)}
[:div.item-name (:name library)]
[:div.item-contents (contents-str library
(count (:media-objects library))
(count (:colors library)))]
[:input.item-button {:type "button"
:value (tr "workspace.libraries.remove")
:on-click #(unlink-library (:id library))}]])
]]
[:div.section
[:div.section-title (tr "workspace.libraries.shared-libraries")]
[:div.libraries-search
[:input.search-input
{:placeholder (tr "workspace.libraries.search-shared-libraries")
:type "text"
:value (:search-term @state)
:on-change on-search-term-change}]
(if (str/empty? (:search-term @state))
[:div.search-icon
i/search]
[:div.search-icon.search-close
{:on-click on-search-clear-click}
i/close])]
(if (> (count filtered-files) 0)
[:div.section-list
(for [file filtered-files]
[:div.section-list-item {:key (:id file)}
[:div.item-name (:name file)]
[:div.item-contents (contents-str file
(:graphics-count file)
(:colors-count file))]
[:input.item-button {:type "button"
:value (tr "workspace.libraries.add")
:on-click #(link-library (:id file))}]])]
[:div.section-list-empty
i/library
(if (str/empty? (:search-term @state))
(tr "workspace.libraries.no-shared-libraries-available")
(tr "workspace.libraries.no-matches-for" (:search-term @state)))])]]))
[:div.section
[:div.section-title (tr "workspace.libraries.in-this-file")]
[:div.section-list
[:div.section-list-item
[:div.item-name (tr "workspace.libraries.file-library")]
[:div.item-contents (contents-str file
(count (:media-objects file))
(count (:colors file)))]]
(for [library sorted-libraries]
[:div.section-list-item {:key (:id library)}
[:div.item-name (:name library)]
[:div.item-contents (contents-str library
(count (:media-objects library))
(count (:colors library)))]
[:input.item-button {:type "button"
:value (tr "workspace.libraries.remove")
:on-click #(unlink-library (:id library))}]])
]]
[:div.section
[:div.section-title (tr "workspace.libraries.shared-libraries")]
[:div.libraries-search
[:input.search-input
{:placeholder (tr "workspace.libraries.search-shared-libraries")
:type "text"
:value @search-term
:on-change on-search-term-change}]
(if (str/empty? @search-term)
[:div.search-icon
i/search]
[:div.search-icon.search-close
{:on-click on-search-clear}
i/close])]
(if (> (count filtered-files) 0)
[:div.section-list
(for [file filtered-files]
[:div.section-list-item {:key (:id file)}
[:div.item-name (:name file)]
[:div.item-contents (contents-str file
(:graphics-count file)
(:colors-count file))]
[:input.item-button {:type "button"
:value (tr "workspace.libraries.add")
:on-click #(link-library (:id file))}]])]
[:div.section-list-empty
i/library
(if (str/empty? @search-term)
(tr "workspace.libraries.no-shared-libraries-available")
(tr "workspace.libraries.no-matches-for" @search-term))])]]))
(mf/defc updates-tab
@ -113,23 +119,22 @@
(mf/defc libraries-dialog
[{:keys [] :as ctx}]
(let [state (mf/use-state {:current-tab :libraries})
current-tab (:current-tab @state)
(let [selected-tab (mf/use-state :libraries)
locale (mf/deref i18n/locale)
project (mf/deref refs/workspace-project)
file (mf/deref refs/workspace-file)
libraries (mf/deref refs/workspace-libraries)
shared-files (mf/deref refs/workspace-shared-files)
change-tab (fn [tab]
(swap! state assoc :current-tab tab))
close (fn [event]
(dom/prevent-default event)
(modal/hide!))]
change-tab #(reset! selected-tab %)
close #(modal/hide!)]
(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.libraries-dialog
@ -137,15 +142,15 @@
[:div.modal-content
[:div.libraries-header
[:div.header-item
{:class (classnames :active (= current-tab :libraries))
{:class (classnames :active (= @selected-tab :libraries))
:on-click #(change-tab :libraries)}
(tr "workspace.libraries.libraries")]
(t locale "workspace.libraries.libraries")]
[:div.header-item
{:class (classnames :active (= current-tab :updates))
{:class (classnames :active (= @selected-tab :updates))
:on-click #(change-tab :updates)}
(tr "workspace.libraries.updates")]]
(t locale "workspace.libraries.updates")]]
[:div.libraries-content
(case current-tab
(case @selected-tab
:libraries
[:& libraries-tab {:file file
:libraries libraries