Browse Source

fix(sync): lint

rcmerci 3 years ago
parent
commit
ddbc677cd9

+ 1 - 1
src/main/frontend/commands.cljs

@@ -247,7 +247,7 @@
 
        ["Upload an asset" [[:editor/click-hidden-file-input :id]] "Upload file types like image, pdf, docx, etc.)"]
 
-       (state/logged?)
+       (state/deprecated-logged?)
        ["Upload an image" [[:editor/click-hidden-file-input :id]]])]
 
     (markdown-headings)

+ 6 - 5
src/main/frontend/components/header.cljs

@@ -114,7 +114,7 @@
 
 (rum/defc dropdown-menu < rum/reactive
   [{:keys [current-repo t]}]
-  (let [logged? (user-handler/logged?)
+  (let [;; logged? (user-handler/logged?)
         page-menu (page-menu/page-menu nil)
         page-menu-and-hr (when (seq page-menu)
                            (concat page-menu [{:hr true}]))]
@@ -155,10 +155,11 @@
                   :title (t :discord-title)
                   :target "_blank"}
         :icon (ui/icon "brand-discord")}
-       (when logged?
-         {:title (t :sign-out)
-          :options {:on-click user-handler/sign-out!}
-          :icon svg/logout-sm})]
+       ;; (when logged?
+       ;;   {:title (t :sign-out)
+       ;;    :options {:on-click user-handler/sign-out!}
+       ;;    :icon svg/logout-sm})
+       ]
       (concat page-menu-and-hr)
       (remove nil?))
      {}

+ 1 - 3
src/main/frontend/components/repo.cljs

@@ -17,8 +17,6 @@
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.util :as util]
-            [frontend.util.persist-var :as persist-var]
-            [frontend.fs :as fs]
             [frontend.version :as version]
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]
@@ -58,7 +56,7 @@
             (ui/button
               (t :open-a-directory)
               :on-click #(page-handler/ls-dir-files! shortcut/refresh!))])
-         (when (and (state/logged?) (not (util/electron?)))
+         (when (and (state/deprecated-logged?) (not (util/electron?)))
            (ui/button
              "Add another git repo"
              :href (rfe/href :repo-add nil {:graph-types "github"})

+ 16 - 15
src/main/frontend/components/settings.cljs

@@ -92,7 +92,7 @@
     [:span.flex.w-full.rounded-md.sm:ml-3.sm:w-auto
      [:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
       {:type     "button"
-       :on-click user-handler/delete-account!}
+       :on-click user-handler/deprecated-delete-account!}
       (t :user/delete-account)]]
     [:span.mt-3.flex.w-full.rounded-md.sm:mt-0.sm:w-auto
      [:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
@@ -615,7 +615,7 @@
         developer-mode? (state/sub [:ui/developer-mode?])
         cors-proxy (state/sub [:me :cors_proxy])
         https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])
-        logged? (state/logged?)]
+        logged? (state/deprecated-logged?)]
     [:div.panel-wrap.is-advanced
      (when (and util/mac? (util/electron?)) (app-auto-update-row t))
      (usage-diagnostics-row t instrument-disabled?)
@@ -655,19 +655,20 @@
                 :target "_blank"}
             "https://github.com/isomorphic-git/cors-proxy"]])])
 
-     (when logged?
-       [:div
-        [:hr]
-        [:div.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center.sm:pt-5
-         [:label.block.text-sm.font-medium.leading-5.opacity-70.text-red-600.dark:text-red-400
-          {:for "delete account"}
-          (t :user/delete-account)]
-         [:div.mt-1.sm:mt-0.sm:col-span-2
-          [:div.max-w-lg.rounded-md.sm:max-w-xs
-           (ui/button (t :user/delete-your-account)
-                      :on-click (fn []
-                                  (ui-handler/toggle-settings-modal!)
-                                  (js/setTimeout #(state/set-modal! delete-account-confirm))))]]]])]))
+     ;; (when logged?
+     ;;   [:div
+     ;;    [:hr]
+     ;;    [:div.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center.sm:pt-5
+     ;;     [:label.block.text-sm.font-medium.leading-5.opacity-70.text-red-600.dark:text-red-400
+     ;;      {:for "delete account"}
+     ;;      (t :user/delete-account)]
+     ;;     [:div.mt-1.sm:mt-0.sm:col-span-2
+     ;;      [:div.max-w-lg.rounded-md.sm:max-w-xs
+     ;;       (ui/button (t :user/delete-your-account)
+     ;;                  :on-click (fn []
+     ;;                              (ui-handler/toggle-settings-modal!)
+     ;;                              (js/setTimeout #(state/set-modal! delete-account-confirm))))]]]])
+     ]))
 
 (rum/defcs settings
   < (rum/local [:general :general] ::active)

+ 1 - 2
src/main/frontend/components/sidebar.cljs

@@ -9,7 +9,6 @@
             [frontend.components.theme :as theme]
             [frontend.components.widgets :as widgets]
             [frontend.components.plugins :as plugins]
-            [frontend.components.select :as select]
             [frontend.config :as config]
             [frontend.context.i18n :refer [t]]
             [frontend.db :as db]
@@ -349,7 +348,7 @@
         loading-files? (when current-repo (state/sub [:repo/loading-files? current-repo]))
         journals-length (state/sub :journals-length)
         latest-journals (db/get-latest-journals (state/get-current-repo) journals-length)
-        preferred-format (state/sub [:me :preferred_format])
+        ;; preferred-format (state/sub [:me :preferred_format])
         logged? (user-handler/logged?)]
     [:div
      (cond

+ 1 - 1
src/main/frontend/fs/sync.cljs

@@ -95,7 +95,7 @@
   [graph-uuid *ws remote-changes-chan]
   (reset! *ws {:ws (js/WebSocket. (util/format ws-addr graph-uuid)) :stop false})
   (set! (.-onopen (:ws @*ws)) #(println (util/format "ws opened: graph '%s'" graph-uuid %)))
-  (set! (.-onclose (:ws @*ws)) (fn [e]
+  (set! (.-onclose (:ws @*ws)) (fn [_e]
                                  (when-not (true? (:stop @*ws))
                                    (go
                                      (timeout 1000)

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

@@ -168,7 +168,7 @@
                                nil)))))))
 (defn- get-repos
   []
-  (let [logged? (state/logged?)
+  (let [logged? (state/deprecated-logged?)
         me (state/get-me)]
     (p/let [nfs-dbs (db-persist/get-all-graphs)
             nfs-dbs (map (fn [db]

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

@@ -1,7 +1,7 @@
 (ns frontend.handler.file-sync
   (:require ["path" :as path]
             [cljs-time.coerce :as tc]
-            [cljs.core.async :as async :refer [go timeout go-loop offer! poll! chan <! >!]]
+            [cljs.core.async :as async :refer [go <!]]
             [clojure.string :as string]
             [frontend.config :as config]
             [frontend.db :as db]

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

@@ -13,15 +13,14 @@
             [cljs-time.core :as t]
             [cljs-time.coerce :as tc]
             [cljs-http.client :as http]
-            [cljs.core.async :as async :refer [go go-loop <! >! chan timeout]])
+            [cljs.core.async :as async :refer [go go-loop <! timeout]])
   (:import [goog.format EmailAddress]))
 
 (defn- email? [v]
   (and v
        (.isValid (EmailAddress. v))))
 
-(defn set-email!
-  {:deprecated "-"}
+(defn deprecated-set-email!
   [email]
   (when (email? email)
     (util/post (str config/api "email")
@@ -34,7 +33,6 @@
                                      :error)))))
 
 (defn set-cors!
-  {:deprecated "-"}
   [cors-proxy]
   (util/post (str config/api "cors_proxy")
              {:cors-proxy cors-proxy}
@@ -72,10 +70,9 @@
     ;;              (fn [_e])))
     ))
 
-(defn sign-out!
-  {:deprecated "-"}
+(defn deprecated-sign-out!
   ([]
-   (sign-out! true))
+   (deprecated-sign-out! true))
   ([confirm?]
    (when (or (not confirm?)
              (js/confirm "Your local notes will be completely removed after signing out. Continue?"))
@@ -87,13 +84,12 @@
       (p/finally (fn []
                    (set! (.-href js/window.location) "/logout")))))))
 
-(defn delete-account!
-  {:deprecated "-"}
+(defn deprecated-delete-account!
   []
   (p/let [_ (idb/clear-local-storage-and-idb!)]
     (util/delete (str config/api "account")
                  (fn []
-                   (sign-out! false))
+                   (deprecated-sign-out! false))
                  (fn [error]
                    (log/error :user/delete-account-failed error)))))
 
@@ -115,8 +111,9 @@
    (tc/from-long)
    (t/before? (t/now))))
 
-(defn- almost-expired? [parsed-jwt]
+(defn- almost-expired?
   "return true when jwt will expire after 1h"
+  [parsed-jwt]
   (some->
    (* 1000 (:exp parsed-jwt))
    (tc/from-long)
@@ -160,17 +157,17 @@
   (go
     (let [resp (<! (http/get (str "https://api.logseq.com/auth_callback?code=" code)))]
       (if (= 200 (:status resp))
-        (do
-          (-> resp
+        (-> resp
               (:body)
               (js/JSON.parse)
               (js->clj :keywordize-keys true)
-              (as-> $ (set-tokens! (:id_token $) (:access_token $) (:refresh_token $)))))
+              (as-> $ (set-tokens! (:id_token $) (:access_token $) (:refresh_token $))))
         (debug/pprint "login-callback" resp)))))
 
-(defn refresh-id-token&access-token []
+(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"
+  []
   (when-let [refresh-token (state/get-auth-refresh-token)]
     (go
       (let [resp (<! (http/get (str "https://api.logseq.com/auth_refresh_token?refresh_token=" refresh-token)))]
@@ -195,7 +192,7 @@
   (debug/pprint "start refresh-tokens-loop")
   (go-loop []
     (<! (timeout 60000))
-    (when-some [refresh-token (state/get-auth-refresh-token)]
+    (when (state/get-auth-refresh-token)
       (let [id-token (state/get-auth-id-token)]
         (when (or (nil? id-token)
                   (-> id-token (parse-jwt) (almost-expired?)))

+ 1 - 2
src/main/frontend/state.cljs

@@ -1060,9 +1060,8 @@
   []
   (:name (get-me)))
 
-(defn logged?
+(defn deprecated-logged?
   "Whether the user has logged in."
-  {:deprecated "-"}
   []
   (some? (get-name)))
 

+ 0 - 54
src/test/frontend/fs/sync_test.cljs

@@ -1,54 +0,0 @@
-(ns frontend.fs.sync-test
-  (:require [clojure.string :as string]
-            [cljs.test :refer [deftest is]]
-            [frontend.fs.sync :as sync]))
-
-
-(defn- create-txns [test-txns]
-  (map-indexed (fn [idx [txtype txcontent]]
-          {:TXId idx :TXType txtype :TXContent (string/join "\n" txcontent)})
-        test-txns))
-
-(def txns-1
-  (create-txns
-   [["update_files"
-     ["f1" "f2"]]
-    ["update_files"
-     ["f2" "f1"]]]))
-
-(def txns-2
-  (create-txns
-   [["update_files"
-     ["f1"]]
-    ["delete_files"
-     ["f1"]]]))
-
-(def txns-3
-  (create-txns
-   [["update_files"
-     ["f1"]]
-    ["rename_file"
-     ["f1" "f2"]]
-    ["delete_files"
-     ["f2"]]]))
-
-(def txns-4
-  (create-txns
-   [["delete_files"
-     ["f2" "f3"]]]))
-
-(deftest test-FileTxnSet
-  (is (=
-       (seq (sync/update-txns (.-EMPTY sync/FileTxnSet) txns-1))
-       [(sync/->FileTxn "f1" "f1" true false 0)
-        (sync/->FileTxn "f2" "f2" true false 1)]))
-  (is (=
-       (seq (sync/update-txns (.-EMPTY sync/FileTxnSet) txns-2))
-       [(sync/->FileTxn "f1" "f1" false true 0)]))
-  (is (=
-       (seq (sync/update-txns (.-EMPTY sync/FileTxnSet) txns-3))
-       [(sync/->FileTxn "f1" "f2" false true 0)]))
-  (is (=
-       (seq (sync/update-txns (.-EMPTY sync/FileTxnSet) txns-4))
-       [(sync/->FileTxn "f2" "f2" false true 0)
-        (sync/->FileTxn "f3" "f3" false true 1)])))