From 6276a76cbbf8cd4e464c93dd4e31c2060b41aceb Mon Sep 17 00:00:00 2001 From: Saskia Lindner Date: Mon, 28 Aug 2017 17:18:28 +0200 Subject: [PATCH] Refactor autoscrolling code --- src/day8/re_frame/trace.cljs | 2 +- src/day8/re_frame/trace/components.cljs | 7 +++---- src/day8/re_frame/trace/styles.cljs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/day8/re_frame/trace.cljs b/src/day8/re_frame/trace.cljs index f437544..972111f 100644 --- a/src/day8/re_frame/trace.cljs +++ b/src/day8/re_frame/trace.cljs @@ -227,7 +227,7 @@ (:filter-type item) ": " [:span.filter-item-string (:query item)] [:span.icon-button [components/icon-remove]]]]) @filter-items)]] - [components/autoscroll-list {:class "panel-content-scrollable" :scroll? true} + [components/autoscroll-list {:class "panel-content-scrollable"} [:table {:style {:margin-bottom 10} :cell-spacing "0" :width "100%"} diff --git a/src/day8/re_frame/trace/components.cljs b/src/day8/re_frame/trace/components.cljs index bcaad1b..a5fcd09 100644 --- a/src/day8/re_frame/trace/components.cljs +++ b/src/day8/re_frame/trace/components.cljs @@ -23,7 +23,7 @@ ;; at-end?: element.scrollHeight - element.scrollTop === element.clientHeight (> tolerance (- (.-scrollHeight el) (.-scrollTop el) (.-clientHeight el)))) -(defn autoscroll-list [{:keys [class scroll?] :as opts} childr] +(defn autoscroll-list [{:keys [class]} child] (let [should-scroll (r/atom true)] (r/create-class {:display-name "autoscroll-list" @@ -37,9 +37,8 @@ (reset! should-scroll (scrolled-to-end? n 100)))) :component-did-update (fn [this] - (let [scroll? (:scroll? (r/props this)) - n (r/dom-node this)] - (when (and scroll? @should-scroll) + (let [n (r/dom-node this)] + (when @should-scroll (scroll! n [0 (.-scrollTop n)] [0 (.-scrollHeight n)] 1600)))) :reagent-render (fn [{:keys [class]} child] diff --git a/src/day8/re_frame/trace/styles.cljs b/src/day8/re_frame/trace/styles.cljs index 5b37b8a..b17a848 100644 --- a/src/day8/re_frame/trace/styles.cljs +++ b/src/day8/re_frame/trace/styles.cljs @@ -95,7 +95,7 @@ flex: 1; } #--re-frame-trace-- .panel-content-scrollable { - margin: 10px; + margin: 0 0 10px 5px; overflow: auto; flex: 1 1 auto; }