mirror of
https://github.com/penpot/penpot.git
synced 2025-03-16 01:31:22 -05:00
💄 Add cosmetic improvements to dashboard import modal code
This commit is contained in:
parent
d2059475f0
commit
cac785f3e1
1 changed files with 45 additions and 36 deletions
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
(defn use-import-file
|
(defn use-import-file
|
||||||
[project-id on-finish-import]
|
[project-id on-finish-import]
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(mf/deps project-id on-finish-import)
|
(mf/deps project-id on-finish-import)
|
||||||
(fn [files]
|
(fn [files]
|
||||||
(when files
|
(when files
|
||||||
|
@ -52,7 +52,9 @@
|
||||||
:on-finish-import on-finish-import})))))))
|
:on-finish-import on-finish-import})))))))
|
||||||
|
|
||||||
(mf/defc import-form
|
(mf/defc import-form
|
||||||
{::mf/forward-ref true}
|
{::mf/forward-ref true
|
||||||
|
::mf/props :obj}
|
||||||
|
|
||||||
[{:keys [project-id on-finish-import]} external-ref]
|
[{:keys [project-id on-finish-import]} external-ref]
|
||||||
|
|
||||||
(let [on-file-selected (use-import-file project-id on-finish-import)]
|
(let [on-file-selected (use-import-file project-id on-finish-import)]
|
||||||
|
@ -62,23 +64,25 @@
|
||||||
:ref external-ref
|
:ref external-ref
|
||||||
:on-selected on-file-selected}]]))
|
:on-selected on-file-selected}]]))
|
||||||
|
|
||||||
(defn update-file [files file-id new-name]
|
(defn update-file
|
||||||
(->> files
|
[files file-id new-name]
|
||||||
(mapv
|
(mapv
|
||||||
(fn [file]
|
(fn [file]
|
||||||
(let [new-name (str/trim new-name)]
|
(let [new-name (str/trim new-name)]
|
||||||
(cond-> file
|
(cond-> file
|
||||||
(and (= (:file-id file) file-id)
|
(and (= (:file-id file) file-id)
|
||||||
(not= "" new-name))
|
(not= "" new-name))
|
||||||
(assoc :name new-name)))))))
|
(assoc :name new-name))))
|
||||||
|
files))
|
||||||
|
|
||||||
(defn remove-file [files file-id]
|
(defn remove-file
|
||||||
(->> files
|
[files file-id]
|
||||||
(mapv
|
(mapv
|
||||||
(fn [file]
|
(fn [file]
|
||||||
(cond-> file
|
(cond-> file
|
||||||
(= (:file-id file) file-id)
|
(= (:file-id file) file-id)
|
||||||
(assoc :deleted? true))))))
|
(assoc :deleted? true)))
|
||||||
|
files))
|
||||||
|
|
||||||
(defn set-analyze-error
|
(defn set-analyze-error
|
||||||
[files uri error]
|
[files uri error]
|
||||||
|
@ -89,7 +93,8 @@
|
||||||
(-> (assoc :status :analyze-error)
|
(-> (assoc :status :analyze-error)
|
||||||
(assoc :error error)))))))
|
(assoc :error error)))))))
|
||||||
|
|
||||||
(defn set-analyze-result [files uri type data]
|
(defn set-analyze-result
|
||||||
|
[files uri type data]
|
||||||
(let [existing-files? (into #{} (->> files (map :file-id) (filter some?)))
|
(let [existing-files? (into #{} (->> files (map :file-id) (filter some?)))
|
||||||
replace-file
|
replace-file
|
||||||
(fn [file]
|
(fn [file]
|
||||||
|
@ -106,12 +111,14 @@
|
||||||
[file]))]
|
[file]))]
|
||||||
(into [] (mapcat replace-file) files)))
|
(into [] (mapcat replace-file) files)))
|
||||||
|
|
||||||
(defn mark-files-importing [files]
|
(defn mark-files-importing
|
||||||
|
[files]
|
||||||
(->> files
|
(->> files
|
||||||
(filter #(= :ready (:status %)))
|
(filter #(= :ready (:status %)))
|
||||||
(mapv #(assoc % :status :importing))))
|
(mapv #(assoc % :status :importing))))
|
||||||
|
|
||||||
(defn update-status [files file-id status progress errors]
|
(defn update-status
|
||||||
|
[files file-id status progress errors]
|
||||||
(->> files
|
(->> files
|
||||||
(mapv (fn [file]
|
(mapv (fn [file]
|
||||||
(cond-> file
|
(cond-> file
|
||||||
|
@ -124,7 +131,7 @@
|
||||||
(= file-id (:file-id file))
|
(= file-id (:file-id file))
|
||||||
(assoc :errors errors))))))
|
(assoc :errors errors))))))
|
||||||
|
|
||||||
(defn parse-progress-message
|
(defn- parse-progress-message
|
||||||
[message]
|
[message]
|
||||||
(case (:type message)
|
(case (:type message)
|
||||||
:upload-data
|
:upload-data
|
||||||
|
@ -151,7 +158,8 @@
|
||||||
(str message)))
|
(str message)))
|
||||||
|
|
||||||
(mf/defc import-entry
|
(mf/defc import-entry
|
||||||
[{:keys [state file editing? can-be-deleted?]}]
|
{::mf/props :obj}
|
||||||
|
[{:keys [state file editing? can-be-deleted]}]
|
||||||
(let [loading? (or (= :analyzing (:status file))
|
(let [loading? (or (= :analyzing (:status file))
|
||||||
(= :importing (:status file)))
|
(= :importing (:status file)))
|
||||||
analyze-error? (= :analyze-error (:status file))
|
analyze-error? (= :analyze-error (:status file))
|
||||||
|
@ -163,7 +171,7 @@
|
||||||
progress (:progress file)
|
progress (:progress file)
|
||||||
|
|
||||||
handle-edit-key-press
|
handle-edit-key-press
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(when (or (kbd/enter? e) (kbd/esc? e))
|
(when (or (kbd/enter? e) (kbd/esc? e))
|
||||||
(dom/prevent-default e)
|
(dom/prevent-default e)
|
||||||
|
@ -171,7 +179,7 @@
|
||||||
(dom/blur! (dom/get-target e)))))
|
(dom/blur! (dom/get-target e)))))
|
||||||
|
|
||||||
handle-edit-blur
|
handle-edit-blur
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(mf/deps file)
|
(mf/deps file)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(let [value (dom/get-target-val e)]
|
(let [value (dom/get-target-val e)]
|
||||||
|
@ -179,13 +187,13 @@
|
||||||
(update :files update-file (:file-id file) value))))))
|
(update :files update-file (:file-id file) value))))))
|
||||||
|
|
||||||
handle-edit-entry
|
handle-edit-entry
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(mf/deps file)
|
(mf/deps file)
|
||||||
(fn []
|
(fn []
|
||||||
(swap! state assoc :editing (:file-id file))))
|
(swap! state assoc :editing (:file-id file))))
|
||||||
|
|
||||||
handle-remove-entry
|
handle-remove-entry
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(mf/deps file)
|
(mf/deps file)
|
||||||
(fn []
|
(fn []
|
||||||
(swap! state update :files remove-file (:file-id file))))]
|
(swap! state update :files remove-file (:file-id file))))]
|
||||||
|
@ -224,7 +232,7 @@
|
||||||
[:div {:class (stl/css :edit-entry-buttons)}
|
[:div {:class (stl/css :edit-entry-buttons)}
|
||||||
(when (= "application/zip" (:type file))
|
(when (= "application/zip" (:type file))
|
||||||
[:button {:on-click handle-edit-entry} i/curve-refactor])
|
[:button {:on-click handle-edit-entry} i/curve-refactor])
|
||||||
(when can-be-deleted?
|
(when can-be-deleted
|
||||||
[:button {:on-click handle-remove-entry} i/delete-refactor])]]
|
[:button {:on-click handle-remove-entry} i/delete-refactor])]]
|
||||||
(cond
|
(cond
|
||||||
analyze-error?
|
analyze-error?
|
||||||
|
@ -252,7 +260,8 @@
|
||||||
|
|
||||||
(mf/defc import-dialog
|
(mf/defc import-dialog
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :import}
|
::mf/register-as :import
|
||||||
|
::mf/props :obj}
|
||||||
[{:keys [project-id files template on-finish-import]}]
|
[{:keys [project-id files template on-finish-import]}]
|
||||||
(let [state (mf/use-state
|
(let [state (mf/use-state
|
||||||
{:status :analyzing
|
{:status :analyzing
|
||||||
|
@ -262,7 +271,7 @@
|
||||||
(mapv #(assoc % :status :analyzing)))})
|
(mapv #(assoc % :status :analyzing)))})
|
||||||
|
|
||||||
analyze-import
|
analyze-import
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(fn [files]
|
(fn [files]
|
||||||
(->> (uw/ask-many!
|
(->> (uw/ask-many!
|
||||||
{:cmd :analyze-import
|
{:cmd :analyze-import
|
||||||
|
@ -277,7 +286,7 @@
|
||||||
(swap! state update :files set-analyze-result uri type data)))))))
|
(swap! state update :files set-analyze-result uri type data)))))))
|
||||||
|
|
||||||
import-files
|
import-files
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(fn [project-id files]
|
(fn [project-id files]
|
||||||
(st/emit! (ptk/event ::ev/event {::ev/name "import-files"
|
(st/emit! (ptk/event ::ev/event {::ev/name "import-files"
|
||||||
:num-files (count files)}))
|
:num-files (count files)}))
|
||||||
|
@ -291,7 +300,7 @@
|
||||||
(swap! state update :files update-status file-id status message errors))))))
|
(swap! state update :files update-status file-id status message errors))))))
|
||||||
|
|
||||||
handle-cancel
|
handle-cancel
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(mf/deps (:editing @state))
|
(mf/deps (:editing @state))
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(when (nil? (:editing @state))
|
(when (nil? (:editing @state))
|
||||||
|
@ -334,7 +343,7 @@
|
||||||
|
|
||||||
|
|
||||||
handle-continue
|
handle-continue
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(mf/deps project-id (:files @state))
|
(mf/deps project-id (:files @state))
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
|
@ -343,7 +352,7 @@
|
||||||
(continue-files))))
|
(continue-files))))
|
||||||
|
|
||||||
handle-accept
|
handle-accept
|
||||||
(mf/use-callback
|
(mf/use-fn
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(st/emit! (modal/hide))
|
(st/emit! (modal/hide))
|
||||||
|
@ -400,13 +409,13 @@
|
||||||
:key (dm/str (:uri file))
|
:key (dm/str (:uri file))
|
||||||
:file file
|
:file file
|
||||||
:editing? editing?
|
:editing? editing?
|
||||||
:can-be-deleted? (> (count files) 1)}]))
|
:can-be-deleted (> (count files) 1)}]))
|
||||||
|
|
||||||
(when (some? template)
|
(when (some? template)
|
||||||
[:& import-entry {:state state
|
[:& import-entry {:state state
|
||||||
:file (assoc template :status (if (= 1 (:importing-templates @state)) :importing :ready))
|
:file (assoc template :status (if (= 1 (:importing-templates @state)) :importing :ready))
|
||||||
:editing? false
|
:editing? false
|
||||||
:can-be-deleted? false}])]
|
:can-be-deleted false}])]
|
||||||
|
|
||||||
[:div {:class (stl/css :modal-footer)}
|
[:div {:class (stl/css :modal-footer)}
|
||||||
[:div {:class (stl/css :action-buttons)}
|
[:div {:class (stl/css :action-buttons)}
|
||||||
|
|
Loading…
Add table
Reference in a new issue