mirror of https://github.com/logseq/logseq
feat: add rtc sync indicator
parent
c00b970188
commit
c86d29d67d
|
@ -4,7 +4,7 @@
|
||||||
--ls-color-file-sync-idle: var(--color-green-600);
|
--ls-color-file-sync-idle: var(--color-green-600);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cp__file-sync {
|
.cp__file-sync, .cp__rtc-sync {
|
||||||
&-indicator {
|
&-indicator {
|
||||||
a.cloud {
|
a.cloud {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
[frontend.handler :as handler]
|
[frontend.handler :as handler]
|
||||||
[frontend.handler.file-sync :as file-sync-handler]
|
[frontend.handler.file-sync :as file-sync-handler]
|
||||||
[frontend.components.file-sync :as fs-sync]
|
[frontend.components.file-sync :as fs-sync]
|
||||||
|
[frontend.components.rtc.indicator :as rtc-indicator]
|
||||||
[frontend.handler.plugin :as plugin-handler]
|
[frontend.handler.plugin :as plugin-handler]
|
||||||
[frontend.handler.route :as route-handler]
|
[frontend.handler.route :as route-handler]
|
||||||
[frontend.handler.user :as user-handler]
|
[frontend.handler.user :as user-handler]
|
||||||
|
@ -235,6 +236,11 @@
|
||||||
(ui/icon "search" {:size ui/icon-size})])))]]
|
(ui/icon "search" {:size ui/icon-size})])))]]
|
||||||
|
|
||||||
[:div.r.flex.drag-region
|
[:div.r.flex.drag-region
|
||||||
|
(when (and current-repo
|
||||||
|
config/dev?
|
||||||
|
(config/db-based-graph? current-repo))
|
||||||
|
(rtc-indicator/indicator))
|
||||||
|
|
||||||
(when (and current-repo
|
(when (and current-repo
|
||||||
(not (config/demo-graph? current-repo))
|
(not (config/demo-graph? current-repo))
|
||||||
(not (config/db-based-graph? current-repo))
|
(not (config/db-based-graph? current-repo))
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
(ns frontend.components.rtc.indicator
|
||||||
|
"RTC state indicator"
|
||||||
|
(:require [rum.core :as rum]
|
||||||
|
[frontend.ui :as ui]
|
||||||
|
[logseq.shui.ui :as shui]
|
||||||
|
[frontend.state :as state]
|
||||||
|
[frontend.util :as util]))
|
||||||
|
|
||||||
|
(rum/defc details
|
||||||
|
[{:keys [unpushed-block-update-count]}]
|
||||||
|
[:div.cp__rtc-sync-details.text-sm
|
||||||
|
(cond
|
||||||
|
(zero? unpushed-block-update-count)
|
||||||
|
"All local changes have been synced."
|
||||||
|
(pos? unpushed-block-update-count)
|
||||||
|
(str "Unsaved local changes: " unpushed-block-update-count))])
|
||||||
|
|
||||||
|
(rum/defc indicator < rum/reactive
|
||||||
|
[]
|
||||||
|
(let [_ (state/sub :auth/id-token)
|
||||||
|
online? (state/sub :network/online?)
|
||||||
|
{:keys [rtc-state unpushed-block-update-count] :as state}
|
||||||
|
(state/sub :rtc/state)]
|
||||||
|
[:div.cp__rtc-sync
|
||||||
|
[:div.cp__rtc-sync-indicator
|
||||||
|
[:a.button.cloud
|
||||||
|
{:on-click #(shui/popup-show! (.-target %)
|
||||||
|
(details state)
|
||||||
|
{:align "end"})
|
||||||
|
:class (util/classnames [{:on (and online? (= :open rtc-state))
|
||||||
|
:idle (and online? (= :open rtc-state) (zero? unpushed-block-update-count))
|
||||||
|
:queuing (pos? unpushed-block-update-count)}])}
|
||||||
|
[:span.flex.items-center
|
||||||
|
(ui/icon "cloud" {:size ui/icon-size})]]]]))
|
|
@ -14,7 +14,7 @@
|
||||||
[logseq.shui.ui :as shui]
|
[logseq.shui.ui :as shui]
|
||||||
[logseq.db :as ldb]))
|
[logseq.db :as ldb]))
|
||||||
|
|
||||||
(defonce debug-state (atom nil))
|
(defonce debug-state (:rtc/state @state/state))
|
||||||
|
|
||||||
(defn- stop
|
(defn- stop
|
||||||
[]
|
[]
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
(let [repo (state/get-current-repo)
|
(let [repo (state/get-current-repo)
|
||||||
^object worker @db-browser/*worker]
|
^object worker @db-browser/*worker]
|
||||||
(p/let [result (.rtc-get-debug-state worker repo)
|
(p/let [result (.rtc-get-debug-state worker repo)
|
||||||
new-state (bean/->clj result)]
|
new-state (ldb/read-transit-str result)]
|
||||||
(swap! debug-state (fn [old] (merge old new-state)))))))
|
(swap! debug-state (fn [old] (merge old new-state)))))))
|
||||||
(ui/button "graph-list"
|
(ui/button "graph-list"
|
||||||
:icon "refresh"
|
:icon "refresh"
|
||||||
|
|
|
@ -638,7 +638,7 @@
|
||||||
|
|
||||||
(rtc-get-debug-state
|
(rtc-get-debug-state
|
||||||
[_this repo]
|
[_this repo]
|
||||||
(bean/->js (rtc-core/get-debug-state repo)))
|
(ldb/write-transit-str (rtc-core/get-debug-state repo)))
|
||||||
|
|
||||||
(rtc-get-block-update-log
|
(rtc-get-block-update-log
|
||||||
[_this block-uuid]
|
[_this block-uuid]
|
||||||
|
|
|
@ -971,7 +971,7 @@
|
||||||
(state/set-modal! multi-tabs-dialog {:container-overflow-visible? true}))
|
(state/set-modal! multi-tabs-dialog {:container-overflow-visible? true}))
|
||||||
|
|
||||||
(defmethod handle :rtc/sync-state [[_ state]]
|
(defmethod handle :rtc/sync-state [[_ state]]
|
||||||
(swap! rtc-debug-ui/debug-state (fn [old] (merge old state))))
|
(state/update-state! :rtc/state (fn [old] (merge old state))))
|
||||||
|
|
||||||
(defmethod handle :rtc/download-remote-graph [[_ graph-name graph-uuid]]
|
(defmethod handle :rtc/download-remote-graph [[_ graph-name graph-uuid]]
|
||||||
(->
|
(->
|
||||||
|
|
|
@ -286,6 +286,7 @@
|
||||||
:file-sync/graph-state {:current-graph-uuid nil}
|
:file-sync/graph-state {:current-graph-uuid nil}
|
||||||
;; graph-uuid -> ...
|
;; graph-uuid -> ...
|
||||||
|
|
||||||
|
:rtc/state (atom {})
|
||||||
:rtc/graphs []
|
:rtc/graphs []
|
||||||
;; graph-url -> {:in-transaction? Boolean :txs []}
|
;; graph-url -> {:in-transaction? Boolean :txs []}
|
||||||
:rtc/remote-batch-tx-state {}
|
:rtc/remote-batch-tx-state {}
|
||||||
|
|
|
@ -1175,3 +1175,8 @@
|
||||||
(when (or (not= new-state old-state)
|
(when (or (not= new-state old-state)
|
||||||
(= :open (:rtc-state new-state)))
|
(= :open (:rtc-state new-state)))
|
||||||
(worker-util/post-message :rtc-sync-state new-state))))))
|
(worker-util/post-message :rtc-sync-state new-state))))))
|
||||||
|
|
||||||
|
(add-watch op-mem-layer/*ops-store :update-rtc-state
|
||||||
|
(fn [_ _ _ _new]
|
||||||
|
(when (:*repo @*state)
|
||||||
|
(swap! *state update :counter (fnil inc 0)))))
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
(def ops-store-schema-coercer (m/coercer ops-store-schema))
|
(def ops-store-schema-coercer (m/coercer ops-store-schema))
|
||||||
|
|
||||||
|
|
||||||
(defonce ^:private *ops-store (atom {} :validator ops-store-schema-coercer))
|
(defonce *ops-store (atom {} :validator ops-store-schema-coercer))
|
||||||
|
|
||||||
(defn- merge-add-retract-maps
|
(defn- merge-add-retract-maps
|
||||||
[m1 m2]
|
[m1 m2]
|
||||||
|
@ -449,11 +449,13 @@
|
||||||
|
|
||||||
(defn get-unpushed-block-update-count
|
(defn get-unpushed-block-update-count
|
||||||
[repo]
|
[repo]
|
||||||
(some-> (get @*ops-store repo)
|
(or
|
||||||
:current-branch
|
(some-> (get @*ops-store repo)
|
||||||
:block-uuid->ops
|
:current-branch
|
||||||
keys
|
:block-uuid->ops
|
||||||
count))
|
keys
|
||||||
|
count)
|
||||||
|
0))
|
||||||
|
|
||||||
(defn get-unpushed-asset-update-count
|
(defn get-unpushed-asset-update-count
|
||||||
[repo]
|
[repo]
|
||||||
|
|
Loading…
Reference in New Issue