From 22b0c04cf4107b80f737c86287d357bf68c200cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 23 Oct 2024 00:22:23 +0200 Subject: [PATCH] Use a component to render poll results We're also renaming the `poll-results-stats` class to `poll-results`. The former name was confusing because it had nothing to do with stats. --- app/assets/stylesheets/participation.scss | 3 ++- .../polls/results_component.html.erb | 22 ++++++++++++++++++ app/components/polls/results_component.rb | 7 ++++++ app/views/polls/results.html.erb | 23 +------------------ app/views/polls/stats.html.erb | 2 +- 5 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 app/components/polls/results_component.html.erb create mode 100644 app/components/polls/results_component.rb diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index d89822de3..73ad32cdd 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1409,7 +1409,8 @@ // 09. Polls results and stats // --------------------------- -.polls-results-stats { +.polls-results, +.polls-stats { table { table-layout: fixed; diff --git a/app/components/polls/results_component.html.erb b/app/components/polls/results_component.html.erb new file mode 100644 index 000000000..a112b9dc2 --- /dev/null +++ b/app/components/polls/results_component.html.erb @@ -0,0 +1,22 @@ +<% provide :title, poll.name %> + +
+ <%= render Polls::PollHeaderComponent.new(poll) %> + + <%= render "poll_subnav" %> + +
+ + +
+ <%= render Polls::Results::QuestionComponent.with_collection(poll.questions) %> +
+
+
diff --git a/app/components/polls/results_component.rb b/app/components/polls/results_component.rb new file mode 100644 index 000000000..9da3eb130 --- /dev/null +++ b/app/components/polls/results_component.rb @@ -0,0 +1,7 @@ +class Polls::ResultsComponent < ApplicationComponent + attr_reader :poll + + def initialize(poll) + @poll = poll + end +end diff --git a/app/views/polls/results.html.erb b/app/views/polls/results.html.erb index 8f6cddd44..44af3685a 100644 --- a/app/views/polls/results.html.erb +++ b/app/views/polls/results.html.erb @@ -1,22 +1 @@ -<% provide :title, @poll.name %> - -
- <%= render Polls::PollHeaderComponent.new(@poll) %> - - <%= render "poll_subnav" %> - -
- - -
- <%= render Polls::Results::QuestionComponent.with_collection(@poll.questions) %> -
-
-
+<%= render Polls::ResultsComponent.new(@poll) %> diff --git a/app/views/polls/stats.html.erb b/app/views/polls/stats.html.erb index b99052f48..8c1766181 100644 --- a/app/views/polls/stats.html.erb +++ b/app/views/polls/stats.html.erb @@ -1,6 +1,6 @@ <% provide :title, @poll.name %> -
+
<%= render Polls::PollHeaderComponent.new(@poll) %> <%= render "poll_subnav" %>