Browse Source

chore: remove unused code

Tienson Qin 2 years ago
parent
commit
4aeaaeb01e

+ 0 - 61
src/main/frontend/handler/editor.cljs

@@ -38,7 +38,6 @@
             [frontend.util.keycode :as keycode]
             [frontend.util.list :as list]
             [frontend.util.marker :as marker]
-            [frontend.util.priority :as priority]
             [frontend.util.property :as property]
             [frontend.util.text :as text-util]
             [frontend.util.thingatpt :as thingatpt]
@@ -756,17 +755,6 @@
                                           (util/format "[#%s]" new-priority))]
     (save-block-if-changed! block new-content)))
 
-(defn cycle-priority!
-  []
-  (when (state/get-edit-block)
-    (let [format (or (db/get-page-format (state/get-current-page))
-                     (state/get-preferred-format))
-          input-id (state/get-edit-input-id)
-          content (state/get-edit-content)
-          new-priority (priority/cycle-priority-state content)
-          new-value (priority/add-or-update-priority content format new-priority)]
-      (state/set-edit-content! input-id new-value))))
-
 (defn delete-block-aux!
   [{:block/keys [uuid repo] :as _block} children?]
   (let [repo (or repo (state/get-current-repo))
@@ -2251,55 +2239,6 @@
                       (state/set-edit-content! (state/get-edit-input-id) value')
                       (cursor/move-cursor-to input cursor'))))))))))))
 
-(defn toggle-list!
-  []
-  (when-not (auto-complete?)
-    (let [{:keys [block]} (get-state)]
-      (when block
-        (let [input (state/get-input)
-              format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format))
-              new-unordered-bullet (case format :org "-" "*")
-              current-pos (cursor/pos input)
-              content (state/get-edit-content)
-              pos (atom current-pos)]
-          (if-let [item (thingatpt/list-item-at-point input)]
-            (let [{:keys [ordered]} item
-                  list-beginning-pos (list/list-beginning-pos input)
-                  list-end-pos (list/list-end-pos input)
-                  list (subs content list-beginning-pos list-end-pos)
-                  items (string/split-lines list)
-                  splitter-reg (if ordered #"[\d]*\.\s*" #"[-\*]{1}\s*")
-                  items-without-bullet (vec (map #(last (string/split % splitter-reg 2)) items))
-                  new-list (string/join "\n"
-                                        (if ordered
-                                          (map #(str new-unordered-bullet " " %) items-without-bullet)
-                                          (map-indexed #(str (inc %1) ". " %2) items-without-bullet)))
-                  index-of-current-item (inc (.indexOf items-without-bullet
-                                                       (last (string/split (:raw-content item) splitter-reg 2))))
-                  numbers-length (->> (map-indexed
-                                       #_:clj-kondo/ignore
-                                       #(str (inc %1) ". ")
-                                       (subvec items-without-bullet 0 index-of-current-item))
-                                      string/join
-                                      count)
-                  pos-diff (- numbers-length (* 2 index-of-current-item))]
-              (delete-and-update input list-beginning-pos list-end-pos)
-              (insert new-list)
-              (reset! pos (if ordered
-                            (- current-pos pos-diff)
-                            (+ current-pos pos-diff))))
-            (let [prev-item (list/get-prev-item input)]
-              (cursor/move-cursor-down input)
-              (cursor/move-cursor-to-line-beginning input)
-              (if prev-item
-                (let [{:keys [bullet ordered]} prev-item
-                      current-bullet (if ordered (str (inc bullet) ".") bullet)]
-                  (insert (str current-bullet " "))
-                  (reset! pos (+ current-pos (count current-bullet) 1)))
-                (do (insert (str new-unordered-bullet " "))
-                    (reset! pos (+ current-pos 2))))))
-          (cursor/move-cursor-to input @pos))))))
-
 (defn toggle-page-reference-embed
   [parent-id]
   (let [{:keys [block]} (get-state)]

+ 3 - 16
src/main/frontend/handler/user.cljs

@@ -103,30 +103,17 @@
 
 
 (defn <refresh-id-token&access-token
-  "refresh id-token and access-token, if refresh_token expired, clear all tokens
-   return true if success, else false"
+  "Refresh id-token and access-token"
   []
   (go
     (when-let [refresh-token (state/get-auth-refresh-token)]
       (let [resp (<! (http/get (str "https://" config/API-DOMAIN "/auth_refresh_token?refresh_token=" refresh-token)
                                {:with-credentials? false}))]
-
-        (cond
-          ;; e.g. api return 500, server internal error
-          ;; we shouldn't clear tokens if they aren't expired yet
-          ;; the `refresh-tokens-loop` will retry soon
-          (and (not (http/unexceptional-status? (:status resp)))
-               (not (-> (state/get-auth-id-token) parse-jwt expired?)))
-          nil                           ; do nothing
-
-          (not (http/unexceptional-status? (:status resp)))
-          (clear-tokens)
-
-          :else                         ; ok
+        (when (and (:id_token (:body resp)) (:access_token (:body resp)))
           (set-tokens! (:id_token (:body resp)) (:access_token (:body resp))))))))
 
 (defn restore-tokens-from-localstorage
-  "restore id-token, access-token, refresh-token from localstorage,
+  "Restore id-token, access-token, refresh-token from localstorage,
   and refresh id-token&access-token if necessary.
   return nil when tokens are not available."
   []

+ 1 - 2
src/main/frontend/mobile/mobile_bar.cljs

@@ -2,7 +2,6 @@
   (:require [dommy.core :as dom]
             [frontend.commands :as commands]
             [frontend.date :as date]
-            [frontend.handler.config :as config-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.history :as history]
             [frontend.handler.page :as page-handler]
@@ -23,7 +22,7 @@
     (ui/icon icon {:size ui/icon-size})]])
 
 (rum/defc command
-  [command-handler icon & [count? event?]]
+  [command-handler icon & [event?]]
   [:div
    [:button.bottom-action
     {:on-mouse-down (fn [e]

+ 3 - 3
src/main/frontend/util/cursor.cljs

@@ -120,9 +120,9 @@
   [input]
   (move-cursor-to input (line-end-pos input)))
 
-(defn move-cursor-to-line-beginning
-  [input]
-  (move-cursor-to input (line-beginning-pos input)))
+;; (defn move-cursor-to-line-beginning
+;;   [input]
+;;   (move-cursor-to input (line-beginning-pos input)))
 
 (defn move-cursor-to-end
   [input]

+ 1 - 39
src/main/frontend/util/list.cljs

@@ -1,44 +1,6 @@
 (ns frontend.util.list
   "High level list operations for use in editor"
-  (:require [frontend.util.thingatpt :as thingatpt]
-            [frontend.util.cursor :as cursor]
-            [clojure.string :as string]))
-
-(defn get-prev-item [& [input]]
-  (when-not (cursor/textarea-cursor-first-row? input)
-    (if-let [item (thingatpt/list-item-at-point input)]
-      (let [{:keys [bullet ordered]} item]
-        (when-not (and ordered (= bullet "1"))
-          (cursor/move-cursor-up input)))
-      (cursor/move-cursor-up input))
-    (thingatpt/list-item-at-point input)))
-
-(defn get-next-item [& [input]]
-  (when-let [item (thingatpt/list-item-at-point input)]
-    (let [{:keys [_bullet _ordered]} item]
-      (when-not (cursor/textarea-cursor-last-row? input)
-        (cursor/move-cursor-down input)
-        (thingatpt/list-item-at-point input)))))
-
-(defn list-beginning-pos [& [input]]
-  (when-let [item (thingatpt/list-item-at-point input)]
-    (let [current-pos (cursor/pos input)
-          item-start (:start item)
-          beginning-pos (atom item-start)]
-      (while (when-let [prev-item (get-prev-item input)]
-               (reset! beginning-pos (:start prev-item))))
-      (cursor/move-cursor-to input current-pos)
-      @beginning-pos)))
-
-(defn list-end-pos [& [input]]
-  (when-let [item (thingatpt/list-item-at-point input)]
-    (let [current-pos (cursor/pos input)
-          item-end (:end item)
-          end-pos (atom item-end)]
-      (while (when-let [next-item (get-next-item input)]
-               (reset! end-pos (:end next-item))))
-      (cursor/move-cursor-to input current-pos)
-      @end-pos)))
+  (:require [clojure.string :as string]))
 
 (defn- newline?
   [line]

+ 0 - 14
src/main/frontend/util/priority.cljs

@@ -4,20 +4,6 @@
             [frontend.util :as util]
             [frontend.util.marker :as marker]))
 
-(defn cycle-priority-state
-  [content]
-  (let [priority-reg #"\[#([ABC]{1})\]\s{1}"
-        priority (last (util/safe-re-find priority-reg content))
-        next-priority (case priority
-                        "A" "B"
-
-                        "B" "C"
-
-                        "C" nil
-
-                        "A")]
-    (and next-priority (util/format "[#%s]" next-priority))))
-
 (defn add-or-update-priority
   [content format priority]
   (let [priority-pattern  #"(\[#[ABC]\])?\s?"