瀏覽代碼

feat(rtc): add password input ui when create-db-graph

rcmerci 1 月之前
父節點
當前提交
7d11cbbed9
共有 2 個文件被更改,包括 69 次插入43 次删除
  1. 68 42
      src/main/frontend/components/repo.cljs
  2. 1 1
      src/main/frontend/handler/repo.cljs

+ 68 - 42
src/main/frontend/components/repo.cljs

@@ -36,11 +36,11 @@
                db-based?)
          (let [local-dir (config/get-local-dir url)
                graph-name (text-util/get-graph-name-from-path url)]
-           [:a.flex.items-center {:title    local-dir
+           [:a.flex.items-center {:title local-dir
                                   :on-click #(on-click graph)}
             [:span graph-name (when (and GraphName (not db-based?)) [:strong.pl-1 "(" GraphName ")"])]
             (when remote? [:strong.px-1.flex.items-center (ui/icon "cloud")])])
-         [:a.flex.items-center {:title    GraphUUID
+         [:a.flex.items-center {:title GraphUUID
                                 :on-click #(on-click graph)}
           (db/get-repo-path (or url GraphName))
           (when remote? [:strong.pl-1.flex.items-center (ui/icon "cloud")])])])))
@@ -266,32 +266,32 @@
                                               GraphName)
                             downloading? (and downloading-graph-id (= GraphUUID downloading-graph-id))]
                         (when short-repo-name
-                          {:title        [:span.flex.items-center.title-wrap short-repo-name
-                                          (when remote? [:span.pl-1.flex.items-center
-                                                         {:title (str "<" GraphName "> #" GraphUUID)}
-                                                         (ui/icon "cloud" {:size 18})
-                                                         (when downloading?
-                                                           [:span.opacity.text-sm.pl-1 "downloading"])])]
+                          {:title [:span.flex.items-center.title-wrap short-repo-name
+                                   (when remote? [:span.pl-1.flex.items-center
+                                                  {:title (str "<" GraphName "> #" GraphUUID)}
+                                                  (ui/icon "cloud" {:size 18})
+                                                  (when downloading?
+                                                    [:span.opacity.text-sm.pl-1 "downloading"])])]
                            :hover-detail repo-url ;; show full path on hover
-                           :options      {:on-click
-                                          (fn [e]
-                                            (when-not downloading?
-                                              (when-let [on-click (:on-click opts)]
-                                                (on-click e))
-                                              (if (and (gobj/get e "shiftKey")
-                                                       (not (and rtc-graph? remote?)))
-                                                (state/pub-event! [:graph/open-new-window url])
-                                                (cond
+                           :options {:on-click
+                                     (fn [e]
+                                       (when-not downloading?
+                                         (when-let [on-click (:on-click opts)]
+                                           (on-click e))
+                                         (if (and (gobj/get e "shiftKey")
+                                                  (not (and rtc-graph? remote?)))
+                                           (state/pub-event! [:graph/open-new-window url])
+                                           (cond
                                                   ;; exists locally?
-                                                  (or (:root graph) (not rtc-graph?))
-                                                  (state/pub-event! [:graph/switch url])
+                                             (or (:root graph) (not rtc-graph?))
+                                             (state/pub-event! [:graph/switch url])
 
-                                                  (and rtc-graph? remote?)
-                                                  (state/pub-event!
-                                                   [:rtc/download-remote-graph GraphName GraphUUID GraphSchemaVersion])
+                                             (and rtc-graph? remote?)
+                                             (state/pub-event!
+                                              [:rtc/download-remote-graph GraphName GraphUUID GraphSchemaVersion])
 
-                                                  :else
-                                                  (state/pub-event! [:graph/pull-down-remote-graph graph])))))}})))
+                                             :else
+                                             (state/pub-event! [:graph/pull-down-remote-graph graph])))))}})))
                     switch-repos)]
     (->> repo-links (remove nil?))))
 
@@ -358,7 +358,7 @@
                (if (and (or (seq remotes) (seq rtc-graphs)) login?)
                  (repo-handler/combine-local-&-remote-graphs repos (concat remotes rtc-graphs)) repos))
         items-fn #(repos-dropdown-links repos current-repo downloading-graph-id opts)
-        header-fn #(when (> (count repos) 1)                ; show switch to if there are multiple repos
+        header-fn #(when (> (count repos) 1) ; show switch to if there are multiple repos
                      [:div.font-medium.md:text-sm.md:opacity-50.px-1.py-1.flex.flex-row.justify-between.items-center
                       [:h4.pb-1 (t :left-side-bar/switch)]
 
@@ -458,6 +458,8 @@
   (rum/local "" ::graph-name)
   (rum/local false ::cloud?)
   (rum/local false ::creating-db?)
+  (rum/local "" ::password)
+  (rum/local "" ::password-confirm)
   (rum/local (rum/create-ref) ::input-ref)
   {:did-mount (fn [s]
                 (when-let [^js input (some-> @(::input-ref s)
@@ -468,28 +470,33 @@
   (let [*creating-db? (::creating-db? state)
         *graph-name (::graph-name state)
         *cloud? (::cloud? state)
+        *password (::password state)
+        *password-confirm (::password-confirm state)
         input-ref @(::input-ref state)
         new-db-f (fn []
                    (when-not (or (string/blank? @*graph-name)
                                  @*creating-db?)
                      (if (invalid-graph-name? @*graph-name)
                        (invalid-graph-name-warning)
-                       (do
-                         (reset! *creating-db? true)
-                         (p/let [repo (repo-handler/new-db! @*graph-name)]
-                           (when @*cloud?
-                             (->
-                              (p/do
-                                (state/set-state! :rtc/uploading? true)
-                                (rtc-handler/<rtc-create-graph! repo)
-                                (rtc-flows/trigger-rtc-start repo)
-                                (rtc-handler/<get-remote-graphs))
-                              (p/catch (fn [error]
-                                         (log/error :create-db-failed error)))
-                              (p/finally (fn []
-                                           (state/set-state! :rtc/uploading? false)
-                                           (reset! *creating-db? false)))))
-                           (shui/dialog-close!))))))
+                       (if (and (not (string/blank? @*password))
+                                (not= @*password @*password-confirm))
+                         (notification/show! [:p "Password and password confirmation do not match!"] :warning false)
+                         (do
+                           (reset! *creating-db? true)
+                           (p/let [repo (repo-handler/new-db! @*graph-name {:password @*password})]
+                             (when @*cloud?
+                               (->
+                                (p/do
+                                  (state/set-state! :rtc/uploading? true)
+                                  (rtc-handler/<rtc-create-graph! repo)
+                                  (rtc-flows/trigger-rtc-start repo)
+                                  (rtc-handler/<get-remote-graphs))
+                                (p/catch (fn [error]
+                                           (log/error :create-db-failed error)))
+                                (p/finally (fn []
+                                             (state/set-state! :rtc/uploading? false)
+                                             (reset! *creating-db? false)))))
+                             (shui/dialog-close!)))))))
         submit! (fn [^js e click?]
                   (when-let [value (and (or click? (= (gobj/get e "key") "Enter"))
                                         (util/trim-safe (.-value (rum/deref input-ref))))]
@@ -501,7 +508,26 @@
        :disabled @*creating-db?
        :ref input-ref
        :placeholder "your graph name"
-       :on-key-down submit!})
+       :on-key-down submit!
+       :autoComplete "off"})
+     (when @*cloud?
+       [:div.flex.flex-col.gap-4
+        (shui/input
+         {:type "password"
+          :default-value @*password
+          :disabled @*creating-db?
+          :placeholder "password"
+          :on-change #(reset! *password %)
+          :on-key-down submit!
+          :autoComplete "new-password"})
+        (shui/input
+         {:type "password"
+          :default-value @*password-confirm
+          :disabled @*creating-db?
+          :placeholder "password confirm"
+          :on-change #(reset! *password-confirm %)
+          :on-key-down submit!
+          :autoComplete "new-password"})])
      (when (user-handler/rtc-group?)
        [:div.flex.flex-row.items-center.gap-1
         (shui/checkbox

+ 1 - 1
src/main/frontend/handler/repo.cljs

@@ -189,7 +189,7 @@
   (let [full-graph-name (string/lower-case (str config/db-version-prefix graph-name))]
     (some #(= (some-> (:url %) string/lower-case) full-graph-name) (state/get-repos))))
 
-(defn- create-db [full-graph-name {:keys [file-graph-import?]}]
+(defn- create-db [full-graph-name {:keys [file-graph-import? password]}]
   (->
    (p/let [config (common-config/create-config-for-db-graph config/config-default-content)
            _ (persist-db/<new full-graph-name