diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 4fec96c63..09dfc940e 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -5,6 +5,7 @@ class DebatesController < ApplicationController before_action :parse_tag_filter, only: :index before_action :authenticate_user!, except: [:index, :show, :map] + before_action :set_view, only: :index feature_flag :debates @@ -52,4 +53,8 @@ class DebatesController < ApplicationController Debate end + def set_view + @view = (params[:view] == "minimal") ? "minimal" : "default" + end + end diff --git a/app/helpers/debates_helper.rb b/app/helpers/debates_helper.rb index e880f0831..f81d69809 100644 --- a/app/helpers/debates_helper.rb +++ b/app/helpers/debates_helper.rb @@ -12,4 +12,20 @@ module DebatesHelper end end + def debates_minimal_view_path + debates_path(view: debates_secondary_view) + end + + def debates_default_view? + @view == "default" + end + + def debates_current_view + @view + end + + def debates_secondary_view + debates_current_view == "default" ? "minimal" : "default" + end + end diff --git a/app/views/debates/_debate_minimal.html.erb b/app/views/debates/_debate_minimal.html.erb new file mode 100644 index 000000000..f7a3a26af --- /dev/null +++ b/app/views/debates/_debate_minimal.html.erb @@ -0,0 +1,14 @@ +
+
+
+
+
+ <% cache [locale_and_user_status, + 'index_minimal', debate, @debate_votes[debate.id]] do %> +

<%= link_to debate.title, debate %>

+ <% end %> +
+
+
+
+
diff --git a/app/views/debates/_view_mode.html.erb b/app/views/debates/_view_mode.html.erb new file mode 100644 index 000000000..06ec444f6 --- /dev/null +++ b/app/views/debates/_view_mode.html.erb @@ -0,0 +1,30 @@ +
+ + + +
diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index f06f43923..8a0d7d34e 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -46,6 +46,12 @@ <%= render "featured_debates" %> <% end %> +
+
+ <%= render "view_mode" %> +
+
+ <%= render "shared/advanced_search", search_path: debates_path(page: 1) %> <%= render 'shared/order_links', i18n_namespace: "debates.index" %> @@ -55,7 +61,13 @@ <% if @debates.any? || current_user.blank? %> - <%= render @debates %> + <% if debates_default_view? %> + <%= render @debates %> + <% else %> + <% @debates.each do |debate| %> + <%= render partial: 'debates/debate_minimal', locals: { debate: debate } %> + <% end %> + <% end %> <% else %> <%= empty_recommended_debates_message_text(current_user) %> <% end %> diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 31659d655..a0e1c1c5b 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -47,6 +47,34 @@ feature 'Debates' do expect(page).to have_selector('#debates .debate', count: 2) end + scenario 'Index view mode' do + debates = [create(:debate), create(:debate), create(:debate)] + + visit debates_path + + click_button 'View mode' + + click_link 'List' + + debates.each do |debate| + within('#debates') do + expect(page).to have_link debate.title + expect(page).to_not have_content debate.description + end + end + + click_button 'View mode' + + click_link 'Cards' + + debates.each do |debate| + within('#debates') do + expect(page).to have_link debate.title + expect(page).to have_content debate.description + end + end + end + scenario 'Show' do debate = create(:debate)