Browse Source

fix(dev): lint

charlie 3 năm trước cách đây
mục cha
commit
d863b10705
1 tập tin đã thay đổi với 116 bổ sung114 xóa
  1. 116 114
      src/main/frontend/state.cljs

+ 116 - 114
src/main/frontend/state.cljs

@@ -22,10 +22,10 @@
 
 (defonce state
   (let [document-mode? (or (storage/get :document/mode?) false)
-        current-graph (let [graph (storage/get :git/current-repo)]
-                        (when graph (ipc/ipc "setCurrentGraph" graph))
-                        graph)]
-    (atom
+       current-graph (let [graph (storage/get :git/current-repo)]
+                       (when graph (ipc/ipc "setCurrentGraph" graph))
+                       graph)]
+   (atom
      {:route-match                           nil
       :today                                 nil
       :system/events                         (async/chan 100)
@@ -41,7 +41,7 @@
       :nfs/user-granted?                     {}
       :nfs/refreshing?                       nil
       :instrument/disabled?                  (storage/get "instrument-disabled")
-        ;; TODO: how to detect the network reliably?
+      ;; TODO: how to detect the network reliably?
       :network/online?                       true
       :indexeddb/support?                    true
       :me                                    nil
@@ -58,7 +58,7 @@
       :search/result                         nil
       :search/graph-filters                  []
 
-        ;; modals
+      ;; modals
       :modal/label                           ""
       :modal/show?                           false
       :modal/panel-content                   nil
@@ -66,7 +66,7 @@
       :modal/close-btn?                      nil
       :modal/subsets                         []
 
-        ;; right sidebar
+      ;; right sidebar
       :ui/fullscreen?                        false
       :ui/settings-open?                     false
       :ui/sidebar-open?                      false
@@ -74,15 +74,15 @@
       :ui/theme                              (or (storage/get :ui/theme) (if (mobile/is-native-platform?) "light" "dark"))
       :ui/system-theme?                      ((fnil identity (or util/mac? util/win32? false)) (storage/get :ui/system-theme?))
       :ui/wide-mode?                         false
-        ;; :show-all, :hide-block-body, :hide-block-children
+      ;; :show-all, :hide-block-body, :hide-block-children
       :ui/cycle-collapse                     :show-all
 
-        ;; ui/collapsed-blocks is to separate the collapse/expand state from db for:
-        ;; 1. right sidebar
-        ;; 2. zoom-in view
-        ;; 3. queries
-        ;; 4. references
-        ;; graph => {:block-id bool}
+      ;; ui/collapsed-blocks is to separate the collapse/expand state from db for:
+      ;; 1. right sidebar
+      ;; 2. zoom-in view
+      ;; 3. queries
+      ;; 4. references
+      ;; graph => {:block-id bool}
       :ui/collapsed-blocks                   {}
       :ui/sidebar-collapsed-blocks           {}
       :ui/root-component                     nil
@@ -92,7 +92,7 @@
       :ui/command-palette-open?              false
       :ui/developer-mode?                    (or (= (storage/get "developer-mode") "true")
                                                  false)
-        ;; remember scroll positions of visited paths
+      ;; remember scroll positions of visited paths
       :ui/paths-scroll-positions             {}
       :ui/shortcut-tooltip?                  (if (false? (storage/get :ui/shortcut-tooltip?))
                                                false
@@ -109,7 +109,7 @@
       :editor/show-page-search?              false
       :editor/show-page-search-hashtag?      false
       :editor/show-date-picker?              false
-        ;; With label or other data
+      ;; With label or other data
       :editor/show-input                     nil
       :editor/show-zotero                    false
       :editor/last-saved-cursor              nil
@@ -130,7 +130,7 @@
 
       :db/last-transact-time                 {}
       :db/last-persist-transact-ids          {}
-        ;; whether database is persisted
+      ;; whether database is persisted
       :db/persisted?                         {}
       :db/latest-txs                         (or (storage/get-transit :db/latest-txs) {})
       :cursor-range                          nil
@@ -138,27 +138,27 @@
       :selection/mode                        false
       :selection/blocks                      []
       :selection/start-block                 nil
-        ;; either :up or :down, defaults to down
-        ;; used to determine selection direction when two or more blocks are selected
+      ;; either :up or :down, defaults to down
+      ;; used to determine selection direction when two or more blocks are selected
       :selection/direction                   :down
       :custom-context-menu/show?             false
       :custom-context-menu/links             nil
 
-        ;; pages or blocks in the right sidebar
-        ;; It is a list of `[repo db-id block-type block-data]` 4-tuple
+      ;; pages or blocks in the right sidebar
+      ;; It is a list of `[repo db-id block-type block-data]` 4-tuple
       :sidebar/blocks                        '()
 
       :preferred-language                    (storage/get :preferred-language)
 
-        ;; electron
+      ;; electron
       :electron/auto-updater-downloaded      false
       :electron/updater-pending?             false
       :electron/updater                      {}
       :electron/user-cfgs                    nil
 
-        ;; plugin
+      ;; plugin
       :plugin/enabled                        (and (util/electron?)
-                                                    ;; true false :theme-only
+                                                  ;; true false :theme-only
                                                   ((fnil identity true) (storage/get :lsp-core-enabled)))
       :plugin/indicator-text                 nil
       :plugin/installed-plugins              {}
@@ -177,15 +177,15 @@
       :plugin/updates-downloading?           false
       :plugin/updates-unchecked              #{}
 
-        ;; pdf
+      ;; pdf
       :pdf/current                           nil
       :pdf/ref-highlight                     nil
 
-        ;; all notification contents as k-v pairs
+      ;; all notification contents as k-v pairs
       :notification/contents                 {}
       :graph/syncing?                        false
 
-        ;; copied blocks
+      ;; copied blocks
       :copy/blocks                           {:copy/content nil :copy/block-tree nil}
 
       :copy/export-block-text-indent-style   (or (storage/get :copy/export-block-text-indent-style)
@@ -196,7 +196,7 @@
 
       :youtube/players                       {}
 
-        ;; command palette
+      ;; command palette
       :command-palette/commands              []
 
       :view/components                       {}
@@ -300,13 +300,13 @@
   (:arweave/gateway (get-config) default-arweave-gateway))
 
 (defonce built-in-macros
-  {"img" "[:img.$4 {:src \"$1\" :style {:width $2 :height $3}}]"})
+         {"img" "[:img.$4 {:src \"$1\" :style {:width $2 :height $3}}]"})
 
 (defn get-macros
   []
   (merge
-   built-in-macros
-   (:macros (get-config))))
+    built-in-macros
+    (:macros (get-config))))
 
 (defn sub-config
   []
@@ -335,7 +335,7 @@
 (defn enable-grammarly?
   []
   (true? (:feature/enable-grammarly?
-          (get (sub-config) (get-current-repo)))))
+           (get (sub-config) (get-current-repo)))))
 
 ;; (defn store-block-id-in-file?
 ;;   []
@@ -344,37 +344,37 @@
 (defn scheduled-deadlines-disabled?
   []
   (true? (:feature/disable-scheduled-and-deadline-query?
-          (get (sub-config) (get-current-repo)))))
+           (get (sub-config) (get-current-repo)))))
 
 (defn enable-timetracking?
   []
   (not (false? (:feature/enable-timetracking?
-                (get (sub-config) (get-current-repo))))))
+                 (get (sub-config) (get-current-repo))))))
 
 (defn enable-journals?
   [repo]
   (not (false? (:feature/enable-journals?
-                (get (sub-config) repo)))))
+                 (get (sub-config) repo)))))
 
 (defn export-heading-to-list?
   []
   (not (false? (:export/heading-to-list?
-                (get (sub-config) (get-current-repo))))))
+                 (get (sub-config) (get-current-repo))))))
 
 (defn enable-encryption?
   [repo]
   (:feature/enable-encryption?
-   (get (sub-config) repo)))
+    (get (sub-config) repo)))
 
 (defn enable-git-auto-push?
   [repo]
   (not (false? (:git-auto-push
-                (get (sub-config) repo)))))
+                 (get (sub-config) repo)))))
 
 (defn enable-block-timestamps?
   []
   (true? (:feature/enable-block-timestamps?
-          (get (sub-config) (get-current-repo)))))
+           (get (sub-config) (get-current-repo)))))
 
 (defn sub-graph-config
   []
@@ -388,7 +388,7 @@
 (defn show-brackets?
   []
   (not (false? (:ui/show-brackets?
-                (get (sub-config) (get-current-repo))))))
+                 (get (sub-config) (get-current-repo))))))
 
 (defn get-default-home
   []
@@ -407,11 +407,11 @@
    (get-preferred-format (get-current-repo)))
   ([repo-url]
    (keyword
-    (or
-     (when-let [fmt (:preferred-format (get-config repo-url))]
-       (string/lower-case (name fmt)))
+     (or
+       (when-let [fmt (:preferred-format (get-config repo-url))]
+         (string/lower-case (name fmt)))
 
-     (get-in @state [:me :preferred_format] "markdown")))))
+       (get-in @state [:me :preferred_format] "markdown")))))
 
 ;; TODO: consider adding a pane in Settings to set this through the GUI (rather
 ;; than having to go through the config.edn file)
@@ -419,8 +419,8 @@
   ([] (get-editor-command-trigger (get-current-repo)))
   ([repo-url]
    (or
-    (:editor/command-trigger (get-config repo-url))        ;; Get from user config
-    "/")))                                                 ;; Set the default
+     (:editor/command-trigger (get-config repo-url))        ;; Get from user config
+     "/")))                                                 ;; Set the default
 
 (defn markdown?
   []
@@ -430,16 +430,16 @@
 (defn get-pages-directory
   []
   (or
-   (when-let [repo (get-current-repo)]
-     (:pages-directory (get-config repo)))
-   "pages"))
+    (when-let [repo (get-current-repo)]
+      (:pages-directory (get-config repo)))
+    "pages"))
 
 (defn get-journals-directory
   []
   (or
-   (when-let [repo (get-current-repo)]
-     (:journals-directory (get-config repo)))
-   "journals"))
+    (when-let [repo (get-current-repo)]
+      (:journals-directory (get-config repo)))
+    "journals"))
 
 (defn org-mode-file-link?
   [repo]
@@ -453,13 +453,13 @@
 (defn get-preferred-workflow
   []
   (keyword
-   (or
-    (when-let [workflow (:preferred-workflow (get-config))]
-      (let [workflow (name workflow)]
-        (if (util/safe-re-find #"now|NOW" workflow)
-          :now
-          :todo)))
-    (get-in @state [:me :preferred_workflow] :now))))
+    (or
+      (when-let [workflow (:preferred-workflow (get-config))]
+        (let [workflow (name workflow)]
+          (if (util/safe-re-find #"now|NOW" workflow)
+            :now
+            :todo)))
+      (get-in @state [:me :preferred_workflow] :now))))
 
 (defn get-preferred-todo
   []
@@ -566,7 +566,7 @@
      ;;                        (remove #(= leader-parent %)))]
      ;;     (prn "followers: " (count followers))
      ;;     ))
-)))
+     )))
 
 (defn get-edit-input-id
   []
@@ -669,6 +669,7 @@
   []
   (get @state :editor/show-input))
 
+
 (defn set-editor-show-zotero!
   [value]
   (set-state! :editor/show-zotero value))
@@ -677,6 +678,7 @@
   []
   (get @state :editor/show-zotero))
 
+
 (defn set-edit-input-id!
   [input-id]
   (swap! state update :editor/editing?
@@ -796,8 +798,8 @@
                       (merge repo {:token token :expires_at expires-at}))
                     (do
                       (when (and
-                             (:url repo)
-                             (string/starts-with? (:url repo) "https://"))
+                              (:url repo)
+                              (string/starts-with? (:url repo) "https://"))
                         (log/error :token/cannot-set-token {:repo-m repo :token-m m}))
                       repo))))
               repos (mapv set-token-f repos)]
@@ -891,13 +893,13 @@
   ([edit-input-id content block cursor-range move-cursor?]
    (when (and edit-input-id block
               (or
-               (publishing-enable-editing?)
-               (not @publishing?)))
+                (publishing-enable-editing?)
+                (not @publishing?)))
      (let [block-element (gdom/getElement (string/replace edit-input-id "edit-block" "ls-block"))
            container (util/get-block-container block-element)
            block (if container
                    (assoc block
-                          :block/container (gobj/get container "id"))
+                     :block/container (gobj/get container "id"))
                    block)
            content (string/trim (or content ""))]
        (swap! state
@@ -905,12 +907,12 @@
                 (-> state
                     (assoc-in [:editor/content edit-input-id] content)
                     (assoc
-                     :editor/block block
-                     :editor/editing? {edit-input-id true}
-                     :editor/last-edit-block-input-id edit-input-id
-                     :editor/last-edit-block block
-                     :editor/last-key-code nil
-                     :cursor-range cursor-range))))
+                      :editor/block block
+                      :editor/editing? {edit-input-id true}
+                      :editor/last-edit-block-input-id edit-input-id
+                      :editor/last-edit-block block
+                      :editor/last-key-code nil
+                      :cursor-range cursor-range))))
 
        (when-let [input (gdom/getElement edit-input-id)]
          (let [pos (count cursor-range)]
@@ -1019,12 +1021,12 @@
   []
   (when (util/electron?)
     (js/window.apis.setUpdatesCallback
-     (fn [_ args]
-       (let [data (bean/->clj args)
-             pending? (not= (:type data) "completed")]
-         (set-state! :electron/updater-pending? pending?)
-         (when pending? (set-state! :electron/updater data))
-         nil)))))
+      (fn [_ args]
+        (let [data (bean/->clj args)
+              pending? (not= (:type data) "completed")]
+          (set-state! :electron/updater-pending? pending?)
+          (when pending? (set-state! :electron/updater data))
+          nil)))))
 
 (defn set-file-component!
   [component]
@@ -1078,14 +1080,14 @@
 (defn get-date-formatter
   []
   (or
-   (when-let [repo (get-current-repo)]
-     (or
-      (get-in @state [:config repo :journal/page-title-format])
+    (when-let [repo (get-current-repo)]
+      (or
+        (get-in @state [:config repo :journal/page-title-format])
         ;; for compatibility
-      (get-in @state [:config repo :date-formatter])))
+        (get-in @state [:config repo :date-formatter])))
     ;; TODO:
-   (get-in @state [:me :settings :date-formatter])
-   "MMM do, yyyy"))
+    (get-in @state [:me :settings :date-formatter])
+    "MMM do, yyyy"))
 
 (defn set-git-status!
   [repo-url value]
@@ -1126,12 +1128,12 @@
 (defn get-default-branch
   [repo-url]
   (or
-   (some->> (get-repos)
-            (filter (fn [m]
-                      (= (:url m) repo-url)))
-            (first)
-            :branch)
-   "master"))
+    (some->> (get-repos)
+             (filter (fn [m]
+                       (= (:url m) repo-url)))
+             (first)
+             :branch)
+    "master"))
 
 (defn get-current-project
   []
@@ -1185,12 +1187,12 @@
            idx (and id (first (keep-indexed #(when (= (:modal/id %2) id) %1)
                                             modals)))
            input (medley/filter-vals
-                  #(not (nil? %1))
-                  {:modal/id            id
-                   :modal/label         (or label (if center? "ls-modal-align-center" ""))
-                   :modal/show?         (if (boolean? show?) show? true)
-                   :modal/panel-content panel-content
-                   :modal/close-btn?    close-btn?})]
+                   #(not (nil? %1))
+                   {:modal/id            id
+                    :modal/label         (or label (if center? "ls-modal-align-center" ""))
+                    :modal/show?         (if (boolean? show?) show? true)
+                    :modal/panel-content panel-content
+                    :modal/close-btn?    close-btn?})]
        (swap! state update-in
               [:modal/subsets (or idx (count modals))]
               merge input)
@@ -1204,7 +1206,7 @@
      (let [id all?-a-id
            modals (:modal/subsets @state)]
        (when-let [idx (if id (first (keep-indexed #(when (= (:modal/id %2) id) %1) modals))
-                          (dec (count modals)))]
+                             (dec (count modals)))]
          (swap! state assoc :modal/subsets (into [] (medley/remove-nth idx modals))))))
    (:modal/subsets @state)))
 
@@ -1265,7 +1267,7 @@
 (defn toggle-left-sidebar!
   []
   (set-left-sidebar-open!
-   (not (get-left-sidebar-open?))))
+    (not (get-left-sidebar-open?))))
 
 (defn set-developer-mode!
   [value]
@@ -1436,11 +1438,11 @@
   [repo]
   (when repo
     (or
-     (when-let [last-time (get-in @state [:editor/last-input-time repo])]
-       (let [now (util/time-ms)]
-         (>= (- now last-time) 500)))
+      (when-let [last-time (get-in @state [:editor/last-input-time repo])]
+        (let [now (util/time-ms)]
+          (>= (- now last-time) 500)))
       ;; not in editing mode
-     (not (get-edit-input-id)))))
+      (not (get-edit-input-id)))))
 
 (defn set-last-persist-transact-id!
   [repo files? id]
@@ -1541,26 +1543,26 @@
 (defn get-start-of-week
   []
   (or
-   (when-let [repo (get-current-repo)]
-     (get-in @state [:config repo :start-of-week]))
-   (get-in @state [:me :settings :start-of-week])
-   6))
+    (when-let [repo (get-current-repo)]
+      (get-in @state [:config repo :start-of-week]))
+    (get-in @state [:me :settings :start-of-week])
+    6))
 
 (defn get-ref-open-blocks-level
   []
   (or
-   (when-let [value (:ref/default-open-blocks-level (get-config))]
-     (when (integer? value)
-       value))
-   2))
+    (when-let [value (:ref/default-open-blocks-level (get-config))]
+      (when (integer? value)
+        value))
+    2))
 
 (defn get-linked-references-collapsed-threshold
   []
   (or
-   (when-let [value (:ref/linked-references-collapsed-threshold (get-config))]
-     (when (integer? value)
-       value))
-   100))
+    (when-let [value (:ref/linked-references-collapsed-threshold (get-config))]
+      (when (integer? value)
+        value))
+    100))
 
 (defn get-events-chan
   []
@@ -1615,7 +1617,7 @@
 (defn logical-outdenting?
   []
   (:editor/logical-outdenting?
-   (get (sub-config) (get-current-repo))))
+    (get (sub-config) (get-current-repo))))
 
 (defn get-editor-args
   []