mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
fix(plugins): simplify header UI items list component
This commit is contained in:
@@ -1254,36 +1254,8 @@
|
||||
|
||||
(rum/defc header-ui-items-list-wrap
|
||||
[children]
|
||||
(let [*wrap-el (rum/use-ref nil)
|
||||
[right-sidebar-resized] (rum-utils/use-atom ui-handler/*right-sidebar-resized-at)]
|
||||
|
||||
(hooks/use-effect!
|
||||
(fn []
|
||||
(when-let [^js wrap-el (rum/deref *wrap-el)]
|
||||
(when-let [^js header-el (.closest wrap-el ".cp__header")]
|
||||
(let [^js header-l (.querySelector header-el "* > .l")
|
||||
^js header-r (.querySelector header-el "* > .r")
|
||||
set-max-width! #(when (number? %) (set! (.-maxWidth (.-style wrap-el)) (str % "px")))
|
||||
calc-wrap-max-width #(let [width-l (.-offsetWidth header-l)
|
||||
width-t (-> (js/document.querySelector "#main-content-container") (.-offsetWidth))
|
||||
children (to-array (.-children header-r))
|
||||
width-c' (reduce (fn [acc ^js e]
|
||||
(when (some-> e (.-classList) (.contains "ui-items-container") (not))
|
||||
(+ acc (or (.-offsetWidth e) 0)))) 0 children)]
|
||||
(when-let [width-t (and (number? width-t)
|
||||
(if-not (state/get-left-sidebar-open?)
|
||||
(- width-t width-l) width-t))]
|
||||
(set-max-width! (max (- width-t width-c' 100) 76))))]
|
||||
(when (util/electron?)
|
||||
(.addEventListener js/window "resize" calc-wrap-max-width)
|
||||
(js/setTimeout calc-wrap-max-width 16))
|
||||
#(when (util/electron?)
|
||||
(.removeEventListener js/window "resize" calc-wrap-max-width))))))
|
||||
[right-sidebar-resized])
|
||||
|
||||
[:div.list-wrap
|
||||
{:ref *wrap-el}
|
||||
children]))
|
||||
(let [*wrap-el (rum/use-ref nil)]
|
||||
[:div.list-wrap {:ref *wrap-el} children]))
|
||||
|
||||
(rum/defcs hook-ui-items < rum/reactive
|
||||
< {:key-fn #(identity "plugin-hook-items")}
|
||||
|
||||
Reference in New Issue
Block a user