chore: refactoring

pull/9610/head
Konstantinos Kaloutas 2023-06-08 16:59:09 +03:00
parent c6ae7b6ad4
commit d13ba8d9e7
11 changed files with 46 additions and 42 deletions

View File

@ -5,7 +5,6 @@
[datascript.core :as d]
[dommy.core :as dom]
[electron.ipc :as ipc]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
[frontend.db.model :as db-model]
[frontend.fs.sync :as sync]
@ -35,9 +34,7 @@
[]
;; only persist current db!
;; TODO rename the function and event to persist-db
(repo-handler/persist-db! {:before #(notification/show!
(ui/loading (t :graph/persist))
:warning)
(repo-handler/persist-db! {:before #(ui/notify-graph-persist!)
:on-success #(ipc/ipc "persistent-dbs-saved")
:on-error #(ipc/ipc "persistent-dbs-error")}))
@ -139,15 +136,11 @@
;; fire back "broadcastPersistGraphDone" on done
(fn [data]
(let [repo (bean/->clj data)
before-f #(notification/show!
(ui/loading (t :graph/persist))
:warning)
before-f #(ui/notify-graph-persist!)
after-f #(ipc/ipc "broadcastPersistGraphDone")
error-f (fn []
(after-f)
(notification/show!
(t :graph/persist-error)
:error))
(ui/notify-graph-persist-error!))
handlers {:before before-f
:on-success after-f
:on-error error-f}]

View File

@ -88,11 +88,11 @@
:disabled (string/blank? val)
:on-click on-submit)]]))
(rum/defc restart-button [active?]
(when active?
(ui/button (t :plugin/restart)
:on-click #(js/logseq.api.relaunch)
:small? true :intent "logseq")))
(rum/defc restart-button
[]
(ui/button (t :plugin/restart)
:on-click #(js/logseq.api.relaunch)
:small? true :intent "logseq"))
(rum/defcs ^:large-vars/data-var alias-directories
< rum/reactive
@ -215,7 +215,7 @@
#(state/set-assets-alias-enabled! (not alias-enabled?))
true)]
[:span
(restart-button alias-enabled-changed?)]]
(when alias-enabled-changed? (restart-button))]]
(when alias-enabled?
[:div.pt-4

View File

@ -1946,11 +1946,12 @@
(not= "nil" marker))
{:class (str (string/lower-case marker))})
(when bg-color
{:style {:background-color (if (some #{bg-color} ui/block-background-colors)
(str "var(--ls-highlight-color-" bg-color ")")
bg-color)
:color (when-not (some #{bg-color} ui/block-background-colors) "white")}
:class "px-1 with-bg-color"}))
(let [built-in-color? (ui/built-in-color? bg-color)]
{:style {:background-color (if built-in-color?
(str "var(--ls-highlight-color-" bg-color ")")
bg-color)
:color (when-not built-in-color? "white")}
:class "px-1 with-bg-color"})))
;; children
(let [area? (= :area (keyword (:hl-type properties)))

View File

@ -541,7 +541,7 @@
db-restoring?
[:div.mt-20
[:div.ls-center
(ui/loading (t :loading))]]
(ui/loading)]]
:else
[:div

View File

@ -152,7 +152,7 @@
;; wait for content load
(and format
(contains? (gp-config/text-formats) format))
(ui/loading "Loading ...")
(ui/loading)
:else
[:div (t :file/format-not-supported (name format))])]))

View File

@ -598,7 +598,7 @@
[:div.version-list
(if loading?
[:div.p-4 (ui/loading "Loading...")]
[:div.p-4 (ui/loading)]
(for [version version-files]
(let [version-uuid (get-version-key version)
local? (some? (:relative-path version))]
@ -704,7 +704,7 @@
;; ready loading
[:div.flex.items-center.h-full.justify-center.w-full.absolute.ready-loading
(ui/loading "Loading...")]]))
(ui/loading)]]))
(defn pick-page-histories-panel [graph-uuid page-name]
(fn []

View File

@ -1041,7 +1041,7 @@
[:div.r.flex.items-center.justify-between
[:div
(ui/tippy
{:html [:small (str (t :page/show-whiteboards) " ?")]
{:html [:small (t :page/show-whiteboards)]
:arrow true}
[:a.button.whiteboard
{:class (util/classnames [{:active (boolean @*whiteboard?)}])
@ -1049,7 +1049,7 @@
(ui/icon "whiteboard" {:extension? true :style {:fontSize ui/icon-size}})])]
[:div
(ui/tippy
{:html [:small (str (t :page/show-journals) " ?")]
{:html [:small (t :page/show-journals)]
:arrow true}
[:a.button.journal
{:class (util/classnames [{:active (boolean @*journal?)}])

View File

@ -17,8 +17,7 @@
[goog.object :as gobj]
[goog.functions :refer [debounce]]
[rum.core :as rum]
[frontend.mobile.util :as mobile-util]
[frontend.context.i18n :refer [t]]))
[frontend.mobile.util :as mobile-util]))
(def excalidraw (r/adapt-class Excalidraw))
@ -148,8 +147,7 @@
(when (:file option)
(cond
db-restoring?
[:div.ls-center
(ui/loading (t :loading))]
[:div.ls-center (ui/loading)]
(false? loading?)
(draw-inner data option)

View File

@ -6,8 +6,7 @@
[frontend.util :as util]
[frontend.handler.plugin :refer [hook-extensions-enhancer-by-type] :as plugin-handler]
[promesa.core :as p]
[goog.dom :as gdom]
[frontend.context.i18n :refer [t]]))
[goog.dom :as gdom]))
;; TODO: extracted to a rum mixin
(defn loaded? []
@ -62,7 +61,7 @@
[id s block? _display?]
(let [loading? (rum/react *loading?)]
(if loading?
(ui/loading (t :loading))
(ui/loading)
(let [element (if block?
:div.latex
:span.latex-inline)]

View File

@ -165,12 +165,8 @@
;; Parameters for the `persist-db` function, to show the notification messages
(def persist-db-noti-m
{:before #(notification/show!
(ui/loading (t :graph/persist))
:warning)
:on-error #(notification/show!
(t :graph/persist-error)
:error)})
{:before #(ui/notify-graph-persist!)
:on-error #(ui/notify-graph-persist-error!)})
(defn- graph-switch-on-persisted
"Logic for keeping db sync when switching graphs

View File

@ -55,7 +55,7 @@
(defonce icon-size (if (mobile-util/native-platform?) 26 20))
(def block-background-colors
(def built-in-colors
["yellow"
"red"
"pink"
@ -64,11 +64,15 @@
"purple"
"gray"])
(defn built-in-color?
[color]
(some #{color} built-in-colors))
(rum/defc menu-background-color
[add-bgcolor-fn rm-bgcolor-fn]
[:div.flex.flex-row.justify-between.py-1.px-2.items-center
[:div.flex.flex-row.justify-between.flex-1.mx-2.mt-2
(for [color block-background-colors]
(for [color built-in-colors]
[:a
{:title (t (keyword "color" color))
:on-click #(add-bgcolor-fn color)}
@ -716,6 +720,7 @@
(modal-panel show? modal-panel-content state close-fn false close-btn?)))]))))
(defn loading
([] (loading (t :loading)))
([content] (loading content nil))
([content opts]
[:div.flex.flex-row.items-center.inline
@ -723,6 +728,18 @@
(when-not (string/blank? content)
[:span.text.pl-2 content])]]))
(defn notify-graph-persist!
[]
(notification/show!
(loading (t :graph/persist))
:warning))
(defn notify-graph-persist-error!
[]
(notification/show!
(t :graph/persist-error)
:error))
(rum/defc rotating-arrow
[collapsed?]
[:span