瀏覽代碼

fix: make header reactive on :user-groups and :rtc-running?

rcmerci 5 月之前
父節點
當前提交
e7edd933c7

+ 1 - 1
src/main/frontend/components/block.cljs

@@ -3673,7 +3673,7 @@
 
 
      (when-not (or in-whiteboard? table? property?) (dnd-separator-wrapper block children block-id slide? false false))]))
      (when-not (or in-whiteboard? table? property?) (dnd-separator-wrapper block children block-id slide? false false))]))
 
 
-(rum/defc ^:large-vars/cleanup-todo block-container-inner
+(rum/defc block-container-inner
   [container-state repo config* block opts]
   [container-state repo config* block opts]
   (let [container-id (:container-id config*)
   (let [container-id (:container-id config*)
         block-id (:block/uuid block)
         block-id (:block/uuid block)

+ 1 - 1
src/main/frontend/components/cmdk/list_item.cljs

@@ -40,7 +40,7 @@
             highlighted-text (string/replace normal-text query-re "<:hlmarker>$1<:hlmarker>")
             highlighted-text (string/replace normal-text query-re "<:hlmarker>$1<:hlmarker>")
             segs (string/split highlighted-text #"<:hlmarker>")]
             segs (string/split highlighted-text #"<:hlmarker>")]
         (if (seq segs)
         (if (seq segs)
-          (into [:span]
+          (into [:span {:aria-label text-string}]
                 (map-indexed (fn [i seg]
                 (map-indexed (fn [i seg]
                                (if (even? i)
                                (if (even? i)
                                  [:span seg]
                                  [:span seg]

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

@@ -331,10 +331,9 @@
   (when (state/sub :ui/toggle-highlight-recent-blocks?)
   (when (state/sub :ui/toggle-highlight-recent-blocks?)
     (recent-slider-inner)))
     (recent-slider-inner)))
 
 
-(rum/defc ^:large-vars/cleanup-todo header < rum/reactive
+(rum/defc ^:large-vars/cleanup-todo header-aux < rum/reactive
   [{:keys [current-repo default-home new-block-mode]}]
   [{:keys [current-repo default-home new-block-mode]}]
-  (let [_ (state/sub [:user/info :UserGroups])
-        electron-mac? (and util/mac? (util/electron?))
+  (let [electron-mac? (and util/mac? (util/electron?))
         left-menu (left-menu-button {:on-click (fn []
         left-menu (left-menu-button {:on-click (fn []
                                                  (state/set-left-sidebar-open!
                                                  (state/set-left-sidebar-open!
                                                   (not (:ui/left-sidebar-open? @state/state))))})
                                                   (not (:ui/left-sidebar-open? @state/state))))})
@@ -357,13 +356,13 @@
      [:div.l.flex.items-center.drag-region
      [:div.l.flex.items-center.drag-region
       [left-menu
       [left-menu
        (if (mobile-util/native-platform?)
        (if (mobile-util/native-platform?)
-         ;; back button for mobile
+                 ;; back button for mobile
          (when-not (or (state/home?) custom-home-page? (state/whiteboard-dashboard?))
          (when-not (or (state/home?) custom-home-page? (state/whiteboard-dashboard?))
            (ui/with-shortcut :go/backward "bottom"
            (ui/with-shortcut :go/backward "bottom"
              [:button.it.navigation.nav-left.button.icon.opacity-70
              [:button.it.navigation.nav-left.button.icon.opacity-70
               {:title (t :header/go-back) :on-click #(js/window.history.back)}
               {:title (t :header/go-back) :on-click #(js/window.history.back)}
               (ui/icon "chevron-left" {:size 26})]))
               (ui/icon "chevron-left" {:size 26})]))
-         ;; search button for non-mobile
+                 ;; search button for non-mobile
          (when current-repo
          (when current-repo
            (ui/with-shortcut :go/search "right"
            (ui/with-shortcut :go/search "right"
              [:button.button.icon#search-button
              [:button.button.icon#search-button
@@ -421,3 +420,15 @@
       (sidebar/toggle)
       (sidebar/toggle)
 
 
       (updater-tips-new-version t)]]))
       (updater-tips-new-version t)]]))
+
+(def ^:private header-related-flow
+  (m/latest
+   (fn [state rtc-running?]
+     {:user-groups (get-in state [:user/info :UserGroups])
+      :rtc-running? rtc-running?})
+   (m/watch state/state) rtc-flows/rtc-running-flow))
+
+(rum/defc header
+  [opts]
+  (let [_m (hooks/use-flow-state header-related-flow)]
+    (header-aux opts)))

+ 1 - 1
src/main/frontend/components/rtc/indicator.cljs

@@ -51,7 +51,7 @@
                                          :local-tx (:local-tx state)
                                          :local-tx (:local-tx state)
                                          :remote-tx (:remote-tx state)
                                          :remote-tx (:remote-tx state)
                                          :rtc-state (if (:rtc-lock state) :open :close)))
                                          :rtc-state (if (:rtc-lock state) :open :close)))
-                                rtc-flows/rtc-state-stream-flow)))]
+                                rtc-flows/rtc-state-flow)))]
       (reset! *update-detail-info-canceler canceler))))
       (reset! *update-detail-info-canceler canceler))))
 (run-task--update-detail-info)
 (run-task--update-detail-info)
 
 

+ 4 - 4
src/main/frontend/handler/db_based/rtc_flows.cljs

@@ -28,8 +28,8 @@
 (def rtc-state-flow
 (def rtc-state-flow
   (m/watch (:rtc/state @state/state)))
   (m/watch (:rtc/state @state/state)))
 
 
-(def rtc-state-stream-flow
-  (m/stream rtc-state-flow))
+(def rtc-running-flow
+  (m/eduction (map :rtc-lock) rtc-state-flow))
 
 
 (def rtc-online-users-flow
 (def rtc-online-users-flow
   (c.m/throttle
   (c.m/throttle
@@ -40,7 +40,7 @@
                       (:rtc-lock m))
                       (:rtc-lock m))
              (:online-users m))))
              (:online-users m))))
     (dedupe)
     (dedupe)
-    rtc-state-stream-flow)))
+    rtc-state-flow)))
 
 
 (def ^:private network-online-change-flow
 (def ^:private network-online-change-flow
   (m/stream
   (m/stream
@@ -64,7 +64,7 @@ conditions:
   (->> (m/latest
   (->> (m/latest
         (fn [rtc-state _ login-user]
         (fn [rtc-state _ login-user]
           (assoc rtc-state :login-user login-user))
           (assoc rtc-state :login-user login-user))
-        (c.m/continue-flow rtc-state-stream-flow)
+        rtc-state-flow
         (c.m/continue-flow network-online-change-flow)
         (c.m/continue-flow network-online-change-flow)
         flows/current-login-user-flow)
         flows/current-login-user-flow)
        (m/eduction
        (m/eduction

+ 3 - 3
src/main/frontend/worker/rtc/core.cljs

@@ -467,13 +467,13 @@
 (def ^:private create-get-state-flow*
 (def ^:private create-get-state-flow*
   (let [rtc-loop-metadata-flow (m/watch *rtc-loop-metadata)]
   (let [rtc-loop-metadata-flow (m/watch *rtc-loop-metadata)]
     (m/ap
     (m/ap
-      (let [{rtc-lock :*rtc-lock
+      (let [{*rtc-lock' :*rtc-lock
              :keys [repo graph-uuid local-graph-schema-version remote-graph-schema-version
              :keys [repo graph-uuid local-graph-schema-version remote-graph-schema-version
                     user-uuid rtc-state-flow *rtc-auto-push? *rtc-remote-profile?
                     user-uuid rtc-state-flow *rtc-auto-push? *rtc-remote-profile?
                     *online-users *last-stop-exception]}
                     *online-users *last-stop-exception]}
             (m/?< rtc-loop-metadata-flow)]
             (m/?< rtc-loop-metadata-flow)]
         (try
         (try
-          (when (and repo rtc-state-flow *rtc-auto-push? rtc-lock)
+          (when (and repo rtc-state-flow *rtc-auto-push? *rtc-lock')
             (m/?<
             (m/?<
              (m/latest
              (m/latest
               (fn [rtc-state rtc-auto-push? rtc-remote-profile?
               (fn [rtc-state rtc-auto-push? rtc-remote-profile?
@@ -493,7 +493,7 @@
                  :last-stop-exception-ex-data (some-> *last-stop-exception deref ex-data)})
                  :last-stop-exception-ex-data (some-> *last-stop-exception deref ex-data)})
               rtc-state-flow
               rtc-state-flow
               (m/watch *rtc-auto-push?) (m/watch *rtc-remote-profile?)
               (m/watch *rtc-auto-push?) (m/watch *rtc-remote-profile?)
-              (m/watch rtc-lock) (m/watch *online-users)
+              (m/watch *rtc-lock') (m/watch *online-users)
               (client-op/create-pending-block-ops-count-flow repo)
               (client-op/create-pending-block-ops-count-flow repo)
               (rtc-log-and-state/create-local-t-flow graph-uuid)
               (rtc-log-and-state/create-local-t-flow graph-uuid)
               (rtc-log-and-state/create-remote-t-flow graph-uuid))))
               (rtc-log-and-state/create-remote-t-flow graph-uuid))))