From 93f3411a308a6bc24d21808987a9c28f1e7d8f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 27 Jun 2021 17:09:25 +0200 Subject: [PATCH] Use anchors in comments order and pagination links It was a bit frustrating to click on one of the order elements or the link to the next page and having to scroll down again until reaching the comments. --- app/components/shared/comments_component.html.erb | 4 ++-- app/components/shared/order_links_component.rb | 7 ++++--- app/views/comments/_comment_tree.html.erb | 4 ++-- spec/system/comments/budget_investments_spec.rb | 3 +++ spec/system/comments/budget_investments_valuation_spec.rb | 1 + spec/system/comments/debates_spec.rb | 3 +++ spec/system/comments/legislation_annotations_spec.rb | 3 +++ spec/system/comments/legislation_questions_spec.rb | 3 +++ spec/system/comments/polls_spec.rb | 3 +++ spec/system/comments/proposals_spec.rb | 3 +++ spec/system/comments/topics_spec.rb | 6 ++++++ 11 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/components/shared/comments_component.html.erb b/app/components/shared/comments_component.html.erb index cb29bf459..3d165703a 100644 --- a/app/components/shared/comments_component.html.erb +++ b/app/components/shared/comments_component.html.erb @@ -9,9 +9,9 @@ <%= render "shared/login_to_comment" %> <% end %> - <%= render "shared/order_links", i18n_namespace: "comments" %> + <%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %> <%= render "comments/comment_list", comments: comment_tree.root_comments %> - <%= paginate comment_tree.root_comments %> + <%= paginate comment_tree.root_comments, params: { anchor: "comments" } %> <% end %> diff --git a/app/components/shared/order_links_component.rb b/app/components/shared/order_links_component.rb index 7baeb20ff..72a82fe4f 100644 --- a/app/components/shared/order_links_component.rb +++ b/app/components/shared/order_links_component.rb @@ -1,9 +1,10 @@ class Shared::OrderLinksComponent < ApplicationComponent - attr_reader :i18n_namespace + attr_reader :i18n_namespace, :anchor delegate :current_path_with_query_params, :current_order, :valid_orders, to: :helpers - def initialize(i18n_namespace) + def initialize(i18n_namespace, anchor: nil) @i18n_namespace = i18n_namespace + @anchor = anchor end private @@ -21,7 +22,7 @@ class Shared::OrderLinksComponent < ApplicationComponent end def link_path(order) - current_path_with_query_params(order: order, page: 1) + current_path_with_query_params(order: order, page: 1, anchor: anchor) end def link_text(order) diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb index 3d058eed2..84204c907 100644 --- a/app/views/comments/_comment_tree.html.erb +++ b/app/views/comments/_comment_tree.html.erb @@ -31,9 +31,9 @@ <%= render "shared/login_to_comment" %> <% end %> - <%= render "shared/order_links", i18n_namespace: "comments" %> + <%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %> <%= render "comments/comment_list", comments: comment_tree.root_comments, valuation: valuation %> - <%= paginate comment_tree.root_comments %> + <%= paginate comment_tree.root_comments, params: { anchor: "comments" } %> diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 590ce6996..33bd1b94d 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -111,12 +111,14 @@ describe "Commenting Budget::Investments" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -184,6 +186,7 @@ describe "Commenting Budget::Investments" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do diff --git a/spec/system/comments/budget_investments_valuation_spec.rb b/spec/system/comments/budget_investments_valuation_spec.rb index 957e73188..eccb8ce26 100644 --- a/spec/system/comments/budget_investments_valuation_spec.rb +++ b/spec/system/comments/budget_investments_valuation_spec.rb @@ -161,6 +161,7 @@ describe "Internal valuation comments on Budget::Investments" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end end diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 723413239..706cd8142 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -127,12 +127,14 @@ describe "Commenting debates" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -200,6 +202,7 @@ describe "Commenting debates" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 51b20e89f..d4f591af5 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -119,12 +119,14 @@ describe "Commenting legislation questions" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -208,6 +210,7 @@ describe "Commenting legislation questions" do end expect(page).to have_css(".comment", count: 3) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 4bd067129..745b94acd 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -113,12 +113,14 @@ describe "Commenting legislation questions" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -186,6 +188,7 @@ describe "Commenting legislation questions" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index a881d8620..0a81d6881 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -107,12 +107,14 @@ describe "Commenting polls" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -180,6 +182,7 @@ describe "Commenting polls" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 49dbab481..5b1b8e43e 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -107,12 +107,14 @@ describe "Commenting proposals" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -180,6 +182,7 @@ describe "Commenting proposals" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index 8541a0a1f..87059ea02 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -114,12 +114,14 @@ describe "Commenting topics from proposals" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -195,6 +197,7 @@ describe "Commenting topics from proposals" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do @@ -658,12 +661,14 @@ describe "Commenting topics from budget investments" do click_link "Newest first" expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) click_link "Oldest first" expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) end @@ -739,6 +744,7 @@ describe "Commenting topics from budget investments" do end expect(page).to have_css(".comment", count: 2) + expect(page).to have_current_path(/#comments/, url: true) end describe "Not logged user" do