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.
  • Loading branch information
kimo-k committed Jul 1, 2023
1 parent 04b9414 commit 5167afe
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 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,11 @@
(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)
;; Select the latest event when it arrives, unless the user has selected an older one.
select-latest? (and (seq new-matches)
(or (empty? previous-matches)
(-> 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 +105,7 @@
: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))))
(cond-> select-latest? (assoc-in [:epochs :selected-epoch-id] (last match-ids))))
:dispatch (when quiescent? [::quiescent])})
;; Else
{:db db})))
Expand Down Expand Up @@ -191,4 +194,4 @@
::set-filter
[(rf/path [:epochs :filter-str]) rf/trim-v]
(fn [_ [filter-str]]
filter-str))
filter-str))

0 comments on commit 5167afe

Please sign in to comment.