Skip to content

Commit

Permalink
[feature] Only select the latest epoch when it is selected
Browse files Browse the repository at this point in the history
#190

Now, selecting any epoch but the latest one causes the selection to
stay on it, despite any new epochs arriving.

Added a react key to each epoch, since the scroll-to effect doesn't
work in certain edge cases. Now, new epochs always scroll because they
always mount with a clean state.
  • Loading branch information
kimo-k committed Jul 1, 2023
1 parent 04b9414 commit cdcd68d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/day8/re_frame_10x/navigation/epochs/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
(remove (fn [trace]
(or (when drop-reagent (metam/low-level-reagent-trace? trace))
(when drop-re-frame (metam/low-level-re-frame-trace? trace)))))) all-traces)
match-ids (mapv first-match-id retained-matches)]
match-ids (mapv first-match-id retained-matches)
latest-selected? (-> db :epochs :selected-epoch-id #{(first-match-id (last previous-matches))})]
{:db (-> db
(assoc-in [:traces :all] retained-traces)
(update :epochs assoc
Expand All @@ -101,8 +102,11 @@
:parse-state parse-state
:sub-state new-sub-state
:subscription-info subscription-info)
;; Reset selected epoch to the head of the list if we got a new event in.
(cond-> (seq new-matches) (assoc-in [:epochs :selected-epoch-id] (last match-ids))))
;; Select the latest event when it arrives, unless the user has selected an older one.
(cond-> (and (seq new-matches)
(or latest-selected?
(not (seq previous-matches))))
(assoc-in [:epochs :selected-epoch-id] (last match-ids))))
:dispatch (when quiescent? [::quiescent])})
;; Else
{:db db})))
Expand Down Expand Up @@ -191,4 +195,4 @@
::set-filter
[(rf/path [:epochs :filter-str]) rf/trim-v]
(fn [_ [filter-str]]
filter-str))
filter-str))

0 comments on commit cdcd68d

Please sign in to comment.