|
|
@@ -21,34 +21,52 @@
|
|
|
;; TODO: temporarily just load the existing folder
|
|
|
(p/resolved (util/node-path.join root dirname)))
|
|
|
|
|
|
+(rum/defc toggle-item
|
|
|
+ [{:keys [on? disabled? title on-toggle]}]
|
|
|
+ (ui/button
|
|
|
+ [:span.flex.items-center.justify-between.w-full.py-1
|
|
|
+ [:strong title]
|
|
|
+ (ui/icon (if on? "toggle-right" "toggle-left"))]
|
|
|
+
|
|
|
+ :class (str "toggle-item " (when on? "is-on"))
|
|
|
+ :intent "logseq"
|
|
|
+ :on-mouse-down #(util/stop %)
|
|
|
+ :on-click #(when (fn? on-toggle)
|
|
|
+ (on-toggle (not on?)))))
|
|
|
+
|
|
|
(rum/defc graph-picker-cp
|
|
|
- [{:keys [onboarding-and-home?]}]
|
|
|
+ [{:keys [onboarding-and-home? logged? native-icloud?] :as opts}]
|
|
|
(let [[step set-step!] (rum/use-state :init)
|
|
|
- *input-ref (rum/create-ref)
|
|
|
- native-ios? (mobile-util/native-ios?)
|
|
|
-
|
|
|
- open-picker #(page-handler/ls-dir-files!
|
|
|
- (fn []
|
|
|
- (shortcut/refresh!)))
|
|
|
- on-create (fn [input-val]
|
|
|
- (let [graph-name (util/safe-sanitize-file-name input-val)]
|
|
|
- (if (string/blank? graph-name)
|
|
|
- (notification/show! "Illegal graph folder name.")
|
|
|
-
|
|
|
- ;; create graph directory under Logseq document folder
|
|
|
- ;; TODO: icloud sync
|
|
|
- (when-let [root (state/get-local-container-root-url)]
|
|
|
- (-> (validate-graph-dirname root graph-name)
|
|
|
- (p/then (fn [graph-path]
|
|
|
- (-> (fs/mkdir! graph-path)
|
|
|
- (p/then (fn []
|
|
|
- (web-nfs/ls-dir-files-with-path! graph-path)
|
|
|
- (notification/show! (str "Create graph: " graph-name) :success))))))
|
|
|
- (p/catch (fn [^js e]
|
|
|
- (notification/show! (str e) :error)
|
|
|
- (js/console.error e)))
|
|
|
- (p/finally
|
|
|
- #()))))))]
|
|
|
+ [sync-mode set-sync-mode!] (rum/use-state
|
|
|
+ (cond
|
|
|
+ logged? :logseq-sync
|
|
|
+ native-icloud? :icloud-sync))
|
|
|
+ icloud-sync-on? (= sync-mode :icloud-sync)
|
|
|
+ logseq-sync-on? (= sync-mode :logseq-sync)
|
|
|
+ *input-ref (rum/create-ref)
|
|
|
+ native-ios? (mobile-util/native-ios?)
|
|
|
+
|
|
|
+ open-picker #(page-handler/ls-dir-files! shortcut/refresh! opts)
|
|
|
+ on-create (fn [input-val]
|
|
|
+ (let [graph-name (util/safe-sanitize-file-name input-val)]
|
|
|
+ (if (string/blank? graph-name)
|
|
|
+ (notification/show! "Illegal graph folder name.")
|
|
|
+
|
|
|
+ ;; create graph directory under Logseq document folder
|
|
|
+ ;; TODO: icloud sync
|
|
|
+ (when-let [root (if icloud-sync-on? (state/get-icloud-container-root-url)
|
|
|
+ (state/get-local-container-root-url))]
|
|
|
+ (-> (validate-graph-dirname root graph-name)
|
|
|
+ (p/then (fn [graph-path]
|
|
|
+ (-> (fs/mkdir! graph-path)
|
|
|
+ (p/then (fn []
|
|
|
+ (web-nfs/ls-dir-files-with-path! graph-path opts)
|
|
|
+ (notification/show! (str "Create graph: " graph-name) :success))))))
|
|
|
+ (p/catch (fn [^js e]
|
|
|
+ (notification/show! (str e) :error)
|
|
|
+ (js/console.error e)))
|
|
|
+ (p/finally
|
|
|
+ #()))))))]
|
|
|
|
|
|
(rum/use-effect!
|
|
|
(fn []
|
|
|
@@ -100,13 +118,14 @@
|
|
|
:ref *input-ref
|
|
|
:placeholder "What's the graph name?"}]
|
|
|
|
|
|
- (ui/button
|
|
|
- [:span.flex.items-center.justify-between.w-full.py-1
|
|
|
- [:strong "Logseq sync"]
|
|
|
- (ui/icon "toggle-right")]
|
|
|
+ (when logged?
|
|
|
+ (toggle-item {:title "Logseq sync"
|
|
|
+ :on? logseq-sync-on?}))
|
|
|
|
|
|
- :intent "logseq"
|
|
|
- :on-click #())
|
|
|
+ (when (and native-icloud? (not logseq-sync-on?))
|
|
|
+ (toggle-item {:title "iCloud sync"
|
|
|
+ :on? icloud-sync-on?
|
|
|
+ :on-toggle #(set-sync-mode! (if % :icloud-sync nil))}))
|
|
|
|
|
|
[:div.flex.justify-between.items-center.pt-2
|
|
|
(ui/button [:span.flex.items-center
|