diff --git a/frontend/src/app/main/data/dashboard.cljs b/frontend/src/app/main/data/dashboard.cljs index e51ed446c..93efdb0ba 100644 --- a/frontend/src/app/main/data/dashboard.cljs +++ b/frontend/src/app/main/data/dashboard.cljs @@ -713,18 +713,21 @@ [{:keys [project-id] :as params}] (us/assert ::us/uuid project-id) (ptk/reify ::create-file + + IDeref + (-deref [_] {:project-id project-id}) + ptk/WatchEvent - (watch [_ _ _] + (watch [it _ _] (let [{:keys [on-success on-error] :or {on-success identity on-error rx/throw}} (meta params) - name (name (gensym (str (tr "dashboard.new-file-prefix") " "))) params (assoc params :name name)] (->> (rp/mutation! :create-file params) (rx/tap on-success) - (rx/map file-created) + (rx/map #(with-meta (file-created %) (meta it))) (rx/catch on-error)))))) ;; --- EVENT: duplicate-file diff --git a/frontend/src/app/main/data/events.cljs b/frontend/src/app/main/data/events.cljs index 7adf4c86c..b457cd8bf 100644 --- a/frontend/src/app/main/data/events.cljs +++ b/frontend/src/app/main/data/events.cljs @@ -84,6 +84,7 @@ (derive :app.main.data.comments/update-comment-thread-status ::generic-action) (derive :app.main.data.dashboard/delete-team-member ::generic-action) (derive :app.main.data.dashboard/duplicate-project ::generic-action) +(derive :app.main.data.dashboard/create-file ::generic-action) (derive :app.main.data.dashboard/file-created ::generic-action) (derive :app.main.data.dashboard/invite-team-members ::generic-action) (derive :app.main.data.dashboard/leave-team ::generic-action) diff --git a/frontend/src/app/main/ui/dashboard/files.cljs b/frontend/src/app/main/ui/dashboard/files.cljs index 77e4f33f5..99678a6c3 100644 --- a/frontend/src/app/main/ui/dashboard/files.cljs +++ b/frontend/src/app/main/ui/dashboard/files.cljs @@ -75,7 +75,7 @@ :on-import on-import}] [:div.dashboard-header-actions - [:a.btn-secondary.btn-small {:on-click (partial on-create-clicked project) :data-test "new-file"} + [:a.btn-secondary.btn-small {:on-click (partial on-create-clicked project "dashboard:header") :data-test "new-file"} (tr "dashboard.new-file")] (when-not (:is-default project) @@ -97,12 +97,13 @@ (filter #(= (:id project) (:project-id %))) (sort-by :modified-at) (reverse)) - + on-create-clicked - (mf/use-callback - (fn [project event] + (mf/use-callback + (fn [project origin event] (dom/prevent-default event) - (st/emit! (dd/create-file {:project-id (:id project)}))))] + (st/emit! (with-meta (dd/create-file {:project-id (:id project)}) + {::ev/origin origin}))))] (mf/use-effect (mf/deps project) diff --git a/frontend/src/app/main/ui/dashboard/placeholder.cljs b/frontend/src/app/main/ui/dashboard/placeholder.cljs index 0f2d4472e..7b4f04ced 100644 --- a/frontend/src/app/main/ui/dashboard/placeholder.cljs +++ b/frontend/src/app/main/ui/dashboard/placeholder.cljs @@ -19,7 +19,7 @@ :else [:div.grid-empty-placeholder - [:button.create-new {:on-click (partial on-create-clicked project)} + [:button.create-new {:on-click (partial on-create-clicked project "dashboard:empty-folder-placeholder")} (tr "dashboard.new-file")]])) (mf/defc loading-placeholder diff --git a/frontend/src/app/main/ui/dashboard/projects.cljs b/frontend/src/app/main/ui/dashboard/projects.cljs index 98023ec41..d23ffc789 100644 --- a/frontend/src/app/main/ui/dashboard/projects.cljs +++ b/frontend/src/app/main/ui/dashboard/projects.cljs @@ -93,10 +93,11 @@ create-file (mf/use-callback (mf/deps project) - (fn [] + (fn [origin] (let [mdata {:on-success on-file-created} params {:project-id (:id project)}] - (st/emit! (dd/create-file (with-meta params mdata)))))) + (st/emit! (with-meta (dd/create-file (with-meta params mdata)) + {::ev/origin origin}))))) on-import (mf/use-callback @@ -140,7 +141,7 @@ i/pin)]) [:a.btn-secondary.btn-small.tooltip.tooltip-bottom - {:on-click create-file :alt (tr "dashboard.new-file") :data-test "project-new-file"} + {:on-click (partial create-file "dashboard:folder") :alt (tr "dashboard.new-file") :data-test "project-new-file"} i/close] [:a.btn-secondary.btn-small.tooltip.tooltip-bottom @@ -152,8 +153,7 @@ :team team :on-load-more on-nav :files files - :on-create-clicked create-file}]])) - + :on-create-clicked (partial create-file "dashboard:empty-folder-placeholder")}]])) (def recent-files-ref (l/derived :dashboard-recent-files st/state))