Browse Source

fix: table still shows deleted blocks

Tienson Qin 1 year ago
parent
commit
4da4f2b2d5

+ 7 - 8
src/main/frontend/components/right_sidebar.cljs

@@ -37,9 +37,9 @@
   [repo idx block]
   (let [id (:block/uuid block)]
     (page/page-cp {:parameters  {:path {:name (str id)}}
-                :sidebar?    true
-                :sidebar/idx idx
-                :repo        repo})))
+                   :sidebar?    true
+                   :sidebar/idx idx
+                   :repo        repo})))
 
 (rum/defc page-cp < rum/reactive
   [repo page-name]
@@ -56,7 +56,6 @@
   [repo block idx sidebar-key ref?]
   (when-let [block-id (:block/uuid block)]
     [[:.flex.items-center {:class (when ref? "ml-2")}
-      (ui/icon "letter-n" {:class "text-md mr-2"})
       (block/breadcrumb {:id     "block-parent"
                          :block? true
                          :sidebar-key sidebar-key} repo block-id {:indent? false})]
@@ -349,11 +348,11 @@
      [])
 
     (rum/use-effect!
-      (fn []
+     (fn []
         ;; sidebar animation duration
-        (js/setTimeout
-          #(reset! ui-handler/*right-sidebar-resized-at (js/Date.now)) 300))
-      [sidebar-open?])
+       (js/setTimeout
+        #(reset! ui-handler/*right-sidebar-resized-at (js/Date.now)) 300))
+     [sidebar-open?])
 
     [:.resizer
      {:ref              el-ref

+ 27 - 13
src/main/frontend/components/views.cljs

@@ -26,7 +26,8 @@
             [frontend.mixins :as mixins]
             [logseq.shui.table.core :as table-core]
             [logseq.db :as ldb]
-            [frontend.config :as config]))
+            [frontend.config :as config]
+            [frontend.db-mixins :as db-mixins]))
 
 (defn- get-latest-entity
   [e]
@@ -116,11 +117,20 @@
       (reduce + (filter number? col))
       (string/join ", " col))))
 
-(rum/defc block-container < rum/static
-  [config row]
-  (let [container (state/get-component :block/container)]
-    [:div.relative.w-full
-     (container config row)]))
+(rum/defcs block-container < rum/reactive db-mixins/query
+  (rum/local false ::deleted?)
+  [state config row table]
+  (let [*deleted? (::deleted? state)
+        container (state/get-component :block/container)
+        row' (db/sub-block (:db/id row))]
+    (if (nil? row')                    ; this row has been deleted
+      (when-not @*deleted?
+        (when-let [f (get-in table [:data-fns :set-data!])]
+          (f (remove (fn [r] (= (:id r) (:id row))) (:data table)))
+          (reset! *deleted? true)
+          nil))
+      [:div.relative.w-full
+       (container config row')])))
 
 (defn build-columns
   [config properties & {:keys [with-object-name? add-tags-column?]
@@ -144,10 +154,12 @@
               :name "Name"
               :type :string
               :header header-cp
-              :cell (fn [_table row _column]
+              :cell (fn [table row _column]
                       (block-container (assoc config
                                               :raw-title? (ldb/asset? row)
-                                              :table? true) row))
+                                              :table? true)
+                                       row
+                                       table))
               :disable-hide? true})]
           (keep
            (fn [property]
@@ -1077,16 +1089,18 @@
                        :ref? true)))))
 
 (rum/defc gallery-card-item
-  [view-entity block config]
+  [table view-entity block config]
   [:div.ls-card-item.content
    {:key (str "view-card-" (:db/id view-entity) "-" (:db/id block))}
    [:div.-ml-4
     (block-container (assoc config
                             :id (str (:block/uuid block))
-                            :gallery-view? true) block)]])
+                            :gallery-view? true)
+                     block
+                     table)]])
 
 (rum/defcs gallery-view < rum/static mixins/container-id
-  [state config view-entity blocks *scroller-ref]
+  [state config table view-entity blocks *scroller-ref]
   (let [config' (assoc config :container-id (:container-id state))]
     [:div.ls-cards
      (when (seq blocks)
@@ -1096,7 +1110,7 @@
          :custom-scroll-parent (gdom/getElement "main-content-container")
          :item-content (fn [idx]
                          (when-let [block (nth blocks idx)]
-                           (gallery-card-item view-entity block config')))}))]))
+                           (gallery-card-item table view-entity block config')))}))]))
 
 (defn- run-effects!
   [option {:keys [data columns state data-fns]} input input-filters set-input-filters! *scroller-ref gallery?]
@@ -1212,7 +1226,7 @@
        (list-view (:config option) view-entity (:rows table))
 
        :logseq.property.view/type.gallery
-       (gallery-view (:config option) view-entity (:rows table) *scroller-ref)
+       (gallery-view (:config option) table view-entity (:rows table) *scroller-ref)
 
        (table-view table option row-selection add-new-object! *scroller-ref))]))
 

+ 4 - 0
src/main/frontend/modules/outliner/pipeline.cljs

@@ -19,6 +19,10 @@
         tx-report {:tx-meta tx-meta
                    :tx-data tx-data}]
     (when (= repo (state/get-current-repo))
+      (when (seq deleted-block-uuids)
+        (let [ids (map (fn [id] (:db/id (db/entity [:block/uuid id]))) deleted-block-uuids)]
+          (state/sidebar-remove-deleted-block! ids)))
+
       (let [conn (db/get-db repo false)]
         (cond
           initial-pages?

+ 9 - 0
src/main/frontend/state.cljs

@@ -1297,6 +1297,15 @@ Similar to re-frame subscriptions"
   (when (empty? (:sidebar/blocks @state))
     (hide-right-sidebar!)))
 
+(defn sidebar-remove-deleted-block!
+  [ids]
+  (let [ids-set (set ids)]
+    (update-state! :sidebar/blocks (fn [items]
+                                     (remove (fn [[repo id _]]
+                                               (and (= repo (get-current-repo)) (contains? ids-set id))) items)))
+    (when (empty? (:sidebar/blocks @state))
+      (hide-right-sidebar!))))
+
 (defn sidebar-remove-rest!
   [db-id]
   (update-state! :sidebar/blocks (fn [blocks]