From 83400b9ed450f81395226def327f962f8ac74525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 23 Dec 2020 14:28:04 +0100 Subject: [PATCH] Display a message when feeds have no items This is a scenario which will likely take place for at least some of the goals. --- app/assets/stylesheets/widgets/feeds/feed.scss | 4 ++++ .../widgets/feeds/feed_component.html.erb | 16 ++++++++++------ config/locales/en/general.yml | 4 ++++ config/locales/es/general.yml | 4 ++++ .../widgets/feeds/feed_component_spec.rb | 9 +++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/widgets/feeds/feed.scss b/app/assets/stylesheets/widgets/feeds/feed.scss index b7e293c7a..a6004d309 100644 --- a/app/assets/stylesheets/widgets/feeds/feed.scss +++ b/app/assets/stylesheets/widgets/feeds/feed.scss @@ -17,4 +17,8 @@ padding: $line-height / 2 0; } } + + .no-items { + margin-top: $line-height; + } } diff --git a/app/components/widgets/feeds/feed_component.html.erb b/app/components/widgets/feeds/feed_component.html.erb index 5eb0352a8..4c8c0d3a1 100644 --- a/app/components/widgets/feeds/feed_component.html.erb +++ b/app/components/widgets/feeds/feed_component.html.erb @@ -3,11 +3,15 @@

<%= t("welcome.feed.most_active.#{kind}") %>

-
- <% feed.items.each do |item| %> - <%= render item_component_class.new(item) %> - <% end %> -
+ <% if feed.items.any? %> +
+ <% feed.items.each do |item| %> + <%= render item_component_class.new(item) %> + <% end %> +
- <%= link_to t("welcome.feed.see_all.#{kind}"), see_all_path, class: "see-all" %> + <%= link_to t("welcome.feed.see_all.#{kind}"), see_all_path, class: "see-all" %> + <% else %> +
<%= t("welcome.feed.no_items.#{kind}") %>
+ <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 05fc01c71..878928629 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -879,6 +879,10 @@ en: debates: See all debates proposals: See all proposals processes: See all processes + no_items: + debates: There are no debates right now + proposals: There are no proposals right now + processes: There are no open processes right now process_label: Process see_process: See process cards: diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index d5f998ecc..2a93e8bfb 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -879,6 +879,10 @@ es: debates: Ver todos los debates proposals: Ver todas las propuestas processes: Ver todos los procesos + no_items: + debates: Ahora mismo no hay debates + proposals: Ahora mismo no hay propuestas + processes: Ahora mismo no hay procesos abiertos process_label: Proceso see_process: Ver proceso cards: diff --git a/spec/components/widgets/feeds/feed_component_spec.rb b/spec/components/widgets/feeds/feed_component_spec.rb index 09974de0b..2e0d990e9 100644 --- a/spec/components/widgets/feeds/feed_component_spec.rb +++ b/spec/components/widgets/feeds/feed_component_spec.rb @@ -1,6 +1,15 @@ require "rails_helper" describe Widgets::Feeds::FeedComponent, type: :component do + it "renders a message when there are no items" do + feed = double(kind: "debates", items: []) + component = Widgets::Feeds::FeedComponent.new(feed) + + render_inline component + + expect(page).to have_content "no debates" + end + describe "#see_all_path" do context "debates" do let(:feed) { Widget::Feed.new(kind: "debates") }