DEV: Introduce history-store service (#24486)

This commit extracts the storage part of the route-scroll-manager into a dedicated service. This provides a key/value store which will reset for each navigation, and restore previous values when the user uses the back/forward buttons in their browser.

This gives us a reliable replacement for the old `DiscourseRoute.isPoppedState` function, which would not work under all situations.

Previously reverted in e6370decfdcb87737e76b21fe1bbe033af08afaa. This version has been significantly refactored, and includes an additional system spec for the issue we identified.
This commit is contained in:
David Taylor
2023-11-22 14:25:52 +00:00
committed by GitHub
parent d0117ff6e3
commit ed1dece517
11 changed files with 185 additions and 60 deletions

View File

@ -81,4 +81,26 @@ describe "Topic list focus", type: :system do
expect(page).to have_css("body.navigation-topics")
expect(focussed_topic_id).to eq(nil)
end
it "refocusses properly when there are multiple pages of topics" do
extra_topics = Fabricate.times(25, :post).map(&:topic)
oldest_topic = Fabricate(:post).topic
oldest_topic.update(bumped_at: 1.day.ago)
visit("/latest")
# Scroll to bottom for infinite load
page.execute_script <<~JS
document.querySelectorAll('.topic-list-item')[24].scrollIntoView(true);
JS
# Click a topic
discovery.topic_list.visit_topic(oldest_topic)
expect(topic).to have_topic_title(oldest_topic.title)
# Going back to the topic-list should re-focus
page.go_back
expect(page).to have_css("body.navigation-topics")
expect(focussed_topic_id).to eq(oldest_topic.id)
end
end