fix lint warnings

pull/3941/head
Tienson Qin 2022-01-23 18:59:05 +08:00
parent e7331f33b0
commit 1870f44f9a
12 changed files with 68 additions and 160 deletions

View File

@ -648,7 +648,7 @@
block-type (keyword (get-in block [:block/properties :ls-type]))
hl-type (get-in block [:block/properties :hl-type])
repo (state/get-current-repo)]
(if block
(if (and block (:block/content block))
(let [title [:span {:class "block-ref"}
(block-content (assoc config :block-ref? true)
block nil (:block/uuid block)

View File

@ -18,7 +18,6 @@
[frontend.mixins :as mixins]
[frontend.modules.shortcut.core :as shortcut]
[frontend.state :as state]
[frontend.search.db :as search-db]
[frontend.ui :as ui]
[frontend.util :as util]
[frontend.util.cursor :as cursor]

View File

@ -12,7 +12,6 @@
[frontend.extensions.pdf.assets :as pdf-assets]
[frontend.ui :as ui]
[frontend.state :as state]
[frontend.search.db :as search-db]
[frontend.mixins :as mixins]
[frontend.config :as config]
[clojure.string :as string]

View File

@ -91,7 +91,7 @@
([tx-data]
(transact! (state/get-current-repo) tx-data))
([repo-url tx-data]
(transact! (state/get-current-repo) tx-data nil))
(transact! repo-url tx-data nil))
([repo-url tx-data tx-meta]
(when-not config/publishing?
(let [tx-data (->> (util/remove-nils tx-data)

View File

@ -418,26 +418,6 @@
content
(property/->new-properties content))))
(defn- remove-indentations
[format level element]
(if (= format :org)
element
(case (first element)
"Paragraph"
["Paragraph"
(let [level (if (= (ffirst (second element)) "Plain")
(count (re-find #"^[\s\t]+" (second (first (second element)))))
level)]
(->> (partition-by #(contains? #{["Break_Line"] ["Hard_Break_Line"]} %) (second element))
(map (fn [c]
(if (and (= (ffirst c) "Plain")
(>= (count (re-find #"^[\s\t]+" (second (first c)))) level))
(cons ["Plain" (subs (second (first c)) level)] (rest c))
c)))
(apply concat)))]
element)))
(defn get-custom-id-or-new-id
[properties]
(or (when-let [custom-id (or (get-in properties [:properties :custom-id])
@ -523,8 +503,7 @@
(cond
(paragraph-timestamp-block? block)
(let [timestamps (extract-timestamps block)
timestamps' (merge timestamps timestamps)
[timestamps others] (split-with #(= "Timestamp" (first %)) (second block))]
timestamps' (merge timestamps timestamps)]
(recur headings (rest blocks) timestamps' properties last-pos last-level children (conj block-all-content block-content)))
(property/properties-ast? block)

View File

@ -10,8 +10,8 @@
[medley.core :as medley]
["mldoc" :as mldoc :refer [Mldoc]]
[linked.core :as linked]
[promesa.core :as p]
[frontend.util.pool :as pool]))
;; [frontend.util.pool :as pool]
))
(defonce parseJson (gobj/get Mldoc "parseJson"))
(defonce parseInlineJson (gobj/get Mldoc "parseInlineJson"))

View File

@ -10,12 +10,9 @@
[frontend.format.mldoc :as mldoc]
[frontend.state :as state]
[frontend.text :as text]
[frontend.utf8 :as utf8]
[frontend.util :as util]
[frontend.util.property :as property]
[lambdaisland.glogi :as log]
[promesa.core :as p]
[frontend.mobile.util :as mobile]))
[lambdaisland.glogi :as log]))
(defn get-page-name
[file ast]

View File

@ -104,24 +104,6 @@
(log/error :nfs/load-files-error repo-url)
(log/error :exception error))))))
(defn- remove-non-exists-refs!
[data]
(let [block-ids (->> (map :block/uuid data)
(remove nil?)
(set))
keep-block-ref-f (fn [refs]
(filter (fn [ref]
(cond
(and (vector? ref) (= :block/uuid (first ref)))
(let [id (second ref)]
(or (contains? block-ids id)
(db/entity [:block/uuid id])))
:else
true)) refs))]
(map (fn [item]
(update item :block/refs keep-block-ref-f))
data)))
(defn- page-exists-in-another-file
"Conflict of files towards same page"
[repo-url page file]
@ -159,41 +141,41 @@
new? (nil? (db/entity [:file/path file]))]
(db/set-file-content! repo-url file content)
(let [format (format/get-format file)
file-content [{:file/path file}]]
(let [tx (if (contains? config/mldoc-support-formats format)
(let [[pages blocks] (extract-handler/extract-blocks-pages repo-url file content)
first-page (first pages)
delete-blocks (->
(concat
(db/delete-file-blocks! repo-url file)
(when first-page (db/delete-page-blocks repo-url (:block/name first-page))))
(distinct))
_ (when-let [current-file (page-exists-in-another-file repo-url first-page file)]
(when (not= file current-file)
(let [error (str "Page already exists with another file: " current-file ", current file: " file)]
(state/pub-event! [:notification/show
{:content error
:status :error
:clear? false}]))))
block-ids (map (fn [block] {:block/uuid (:block/uuid block)}) blocks)
block-refs-ids (->> (mapcat :block/refs blocks)
(filter (fn [ref] (and (vector? ref)
(= :block/uuid (first ref)))))
(map (fn [ref] {:block/uuid (second ref)}))
(seq))
;; To prevent "unique constraint" on datascript
block-ids (set/union (set block-ids) (set block-refs-ids))
pages (extract-handler/with-ref-pages pages blocks)
pages-index (map #(select-keys % [:block/name]) pages)]
;; does order matter?
(concat file-content pages-index delete-blocks pages block-ids blocks))
file-content)]
(let [tx (concat tx [(let [t (tc/to-long (t/now))] ;; TODO: use file system timestamp?
(cond->
{:file/path file}
new?
(assoc :file/created-at t)))])]
(db/transact! repo-url tx (when new-graph? {:new-graph? true}))))))))
file-content [{:file/path file}]
tx (if (contains? config/mldoc-support-formats format)
(let [[pages blocks] (extract-handler/extract-blocks-pages repo-url file content)
first-page (first pages)
delete-blocks (->
(concat
(db/delete-file-blocks! repo-url file)
(when first-page (db/delete-page-blocks repo-url (:block/name first-page))))
(distinct))
_ (when-let [current-file (page-exists-in-another-file repo-url first-page file)]
(when (not= file current-file)
(let [error (str "Page already exists with another file: " current-file ", current file: " file)]
(state/pub-event! [:notification/show
{:content error
:status :error
:clear? false}]))))
block-ids (map (fn [block] {:block/uuid (:block/uuid block)}) blocks)
block-refs-ids (->> (mapcat :block/refs blocks)
(filter (fn [ref] (and (vector? ref)
(= :block/uuid (first ref)))))
(map (fn [ref] {:block/uuid (second ref)}))
(seq))
;; To prevent "unique constraint" on datascript
block-ids (set/union (set block-ids) (set block-refs-ids))
pages (extract-handler/with-ref-pages pages blocks)
pages-index (map #(select-keys % [:block/name]) pages)]
;; does order matter?
(concat file-content pages-index delete-blocks pages block-ids blocks))
file-content)
tx (concat tx [(let [t (tc/to-long (t/now))] ;; TODO: use file system timestamp?
(cond->
{:file/path file}
new?
(assoc :file/created-at t)))])]
(db/transact! repo-url tx (when new-graph? {:new-graph? true}))))))
;; TODO: Remove this function in favor of `alter-files`
(defn alter-file
@ -208,24 +190,24 @@
#(fs/write-file! repo (config/get-repo-dir repo) path content
(assoc (when original-content {:old-content original-content})
:skip-compare? skip-compare?)))]
(let [_ (if reset?
(do
(when-let [page-id (db/get-file-page-id path)]
(db/transact! repo
[[:db/retract page-id :block/alias]
[:db/retract page-id :block/tags]]))
(reset-file! repo path content new-graph?))
(db/set-file-content! repo path content))]
(util/p-handle (write-file!)
(fn [_]
(when (= path (config/get-config-path repo))
(restore-config! repo true))
(when (= path (config/get-custom-css-path repo))
(ui-handler/add-style-if-exists!))
(when re-render-root? (ui-handler/re-render-root!)))
(fn [error]
(println "Write file failed, path: " path ", content: " content)
(log/error :write/failed error))))))
(if reset?
(do
(when-let [page-id (db/get-file-page-id path)]
(db/transact! repo
[[:db/retract page-id :block/alias]
[:db/retract page-id :block/tags]]))
(reset-file! repo path content new-graph?))
(db/set-file-content! repo path content))
(util/p-handle (write-file!)
(fn [_]
(when (= path (config/get-config-path repo))
(restore-config! repo true))
(when (= path (config/get-custom-css-path repo))
(ui-handler/add-style-if-exists!))
(when re-render-root? (ui-handler/re-render-root!)))
(fn [error]
(println "Write file failed, path: " path ", content: " content)
(log/error :write/failed error)))))
(defn set-file-content!
[repo path new-content]

View File

@ -5,7 +5,6 @@
[frontend.config :as config]
[frontend.date :as date]
[frontend.db :as db]
[frontend.db.model :as db-model]
[frontend.dicts :as dicts]
[frontend.encrypt :as encrypt]
[frontend.format :as format]
@ -27,7 +26,6 @@
[lambdaisland.glogi :as log]
[promesa.core :as p]
[shadow.resource :as rc]
[clojure.set :as set]
[frontend.mobile.util :as mobile-util]
[frontend.db.persist :as db-persist]
[electron.ipc :as ipc]))
@ -145,35 +143,6 @@
_ (create-custom-theme repo-url)]
(state/pub-event! [:page/create-today-journal repo-url])))))
(defn- remove-non-exists-refs!
[data all-block-ids]
(let [block-ids (->> (->> (map :block/uuid data)
(remove nil?)
(set))
(set/union (set all-block-ids)))
keep-block-ref-f (fn [refs]
(filter (fn [ref]
(if (and (vector? ref)
(= :block/uuid (first ref)))
(contains? block-ids (second ref))
ref)) refs))]
(map (fn [item]
(if (and (map? item)
(:block/uuid item))
(update item :block/refs keep-block-ref-f)
item)) data)))
(defn- reset-contents-and-blocks!
[repo-url files blocks-pages delete-files delete-blocks refresh?]
(db/transact-files-db! repo-url files)
(let [files (map #(select-keys % [:file/path :file/last-modified-at]) files)
all-data (-> (concat delete-files delete-blocks files blocks-pages)
(util/remove-nils))
all-data (if refresh?
(remove-non-exists-refs! all-data (db-model/get-all-block-uuids))
(remove-non-exists-refs! all-data nil))]
(db/transact! repo-url all-data)))
(defn- load-pages-metadata!
[repo file-paths files]
(try
@ -201,14 +170,18 @@
(defn- parse-files-and-create-default-files-inner!
[repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts]
(let [refresh? (:refresh? opts)
parsed-files (filter
(let [parsed-files (filter
(fn [file]
(let [format (format/get-format (:file/path file))]
(contains? config/mldoc-support-formats format)))
files)
parsed-files (sort-by :file/path parsed-files)
new-graph? (:new-graph? opts)]
new-graph? (:new-graph? opts)
delete-data (->> (concat delete-files delete-blocks)
(remove nil?))]
(when delete-data
(js/console.dir delete-data))
(when (seq delete-data) (db/transact! repo-url delete-data))
(doseq [file parsed-files]
(file-handler/alter-file repo-url
(:file/path file)
@ -261,8 +234,7 @@
(parse-files-and-create-default-files! repo-url files delete-files delete-blocks file-paths first-clone? db-encrypted? re-render? re-render-opts metadata opts))))
(defn load-repo-to-db!
[repo-url {:keys [first-clone? diffs nfs-files refresh? new-graph?]
:as opts}]
[repo-url {:keys [first-clone? diffs nfs-files refresh? new-graph?]}]
(spec/validate :repos/url repo-url)
(when (= :repos (state/get-current-route))
(route-handler/redirect-to-home!))

View File

@ -38,20 +38,6 @@
[:block/uuid left-id])
(block)))
(defn- index-blocks-by-left-id
[blocks]
(reduce
(fn [acc block]
(assert (tree/satisfied-inode? block) "Block should match satisfied-inode?.")
(let [left-id (tree/-get-left-id block)]
(when (get acc left-id)
(prn "acc: " acc)
(prn "block: " (:data block))
(throw (js/Error. "There are two blocks have the same left-id")))
(assoc acc left-id block)))
{}
blocks))
(defn- block-with-timestamps
[block]
(let [updated-at (util/time-ms)
@ -202,7 +188,6 @@
(-get-children [this]
(let [parent-id (tree/-get-id this)
parent-data (get-data this)
children (db-model/get-block-immediate-children (state/get-current-repo) parent-id)]
(map block children))))

View File

@ -156,7 +156,7 @@
(merge
{:type "button"
:class (str (util/hiccup->class klass) " " class)}
(dissoc option :background :class :small?)
(dissoc option :background :class :small? :large?)
(when href
{:on-click (fn []
(util/open-url href)

View File

@ -6702,11 +6702,6 @@ react-grid-layout@0.16.6:
react-draggable "3.x"
react-resizable "1.x"
react-icon-base@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/react-icon-base/-/react-icon-base-2.1.0.tgz#a196e33fdf1e7aaa1fda3aefbb68bdad9e82a79d"
integrity sha1-oZbjP98eeqof2jrvu2i9rZ6Cp50=
react-icons@2.2.7:
version "2.2.7"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"