From 28375170c236f36eb64670974f96498ad7b9c975 Mon Sep 17 00:00:00 2001 From: Kang-Kyu Lee Date: Tue, 2 Jul 2024 00:17:07 -0700 Subject: [PATCH 1/3] Fix updating result vote count --- app/controllers/owner/contestants_controller.rb | 4 ++++ app/views/admin/dashboard/index.html.erb | 2 -- app/views/owner/contestants/result.html.erb | 11 +++++++++++ config/routes.rb | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/views/owner/contestants/result.html.erb diff --git a/app/controllers/owner/contestants_controller.rb b/app/controllers/owner/contestants_controller.rb index 0830360..784b85f 100644 --- a/app/controllers/owner/contestants_controller.rb +++ b/app/controllers/owner/contestants_controller.rb @@ -7,6 +7,10 @@ def index @contestants = @round.contestants.all end + def result + @contestants = @round.contestants.all + end + def create @contestant = @round.contestants.build(contestant_params) if @contestant.save diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index ae0b708..c793569 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -1,4 +1,2 @@ -<%= turbo_stream_from "activity" %> -

<%= pluralize @users, "user" %>

<%= pluralize @rounds, "round" %>

diff --git a/app/views/owner/contestants/result.html.erb b/app/views/owner/contestants/result.html.erb new file mode 100644 index 0000000..61c2f20 --- /dev/null +++ b/app/views/owner/contestants/result.html.erb @@ -0,0 +1,11 @@ +<%= turbo_stream_from "activity" %> + +
+

“<%= link_to @round.title, round_path(@round) %>” round result

+
+ + diff --git a/config/routes.rb b/config/routes.rb index 8eb8410..3bcf97d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ resources :rounds, only: [] do resources :audiences, only: [:index] resources :contestants, only: [:new, :create, :destroy, :index] - get "results" => "contestants#index" + get "results" => "contestants#result" end end From 74dae9ee3d87ea902720ec6774a779c6791b77f8 Mon Sep 17 00:00:00 2001 From: Kang-Kyu Lee Date: Tue, 2 Jul 2024 00:18:21 -0700 Subject: [PATCH 2/3] Add owner name on rounds show page for audiences Add round name on audience vote page Change styling a bit --- app/views/contestants/index.html.erb | 4 +++ app/views/owner/contestants/_votes.html.erb | 0 app/views/owner/contestants/index.html.erb | 11 +++------ app/views/rounds/show.html.erb | 27 ++++++++++++--------- 4 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 app/views/owner/contestants/_votes.html.erb diff --git a/app/views/contestants/index.html.erb b/app/views/contestants/index.html.erb index b2f52c0..1128191 100644 --- a/app/views/contestants/index.html.erb +++ b/app/views/contestants/index.html.erb @@ -1,5 +1,9 @@ <%= turbo_stream_from "audience_contestants" %> +
+

“<%= link_to @round.title, round_path(@round) %>” round contestants

+
+ <%= turbo_frame_tag "contestants" do %> <% if @contestants.any? %> -<% unless current_page?(owner_round_results_path(@round)) %> -
<%= form_with(url: owner_round_contestants_path(@round), method: :post, model: [@round, @round.contestants.build], class: "mt-8 space-y-6") do |f| %>
- <%= f.text_field :name, autofocus: true, required: true, placeholder: "Name", class: "appearance-none rounded-l-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" %> - <%= f.text_field :location, placeholder: "Location", class: "appearance-none rounded-r-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" %> + <%= f.text_field :name, autofocus: true, required: true, placeholder: "Name", class: "appearance-none rounded-l-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-blue-500 focus:border-blue-500 focus:z-10 sm:text-sm" %> + <%= f.text_field :location, placeholder: "Location", class: "appearance-none rounded-r-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-blue-500 focus:border-blue-500 focus:z-10 sm:text-sm" %>
- <%= f.submit "Add", class: "group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %> + <%= f.submit "Add", class: "group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md bg-blue-500 hover:bg-blue-700 text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" %>
<% end %>
- - -<% end %> diff --git a/app/views/rounds/show.html.erb b/app/views/rounds/show.html.erb index fb52917..58b8e01 100644 --- a/app/views/rounds/show.html.erb +++ b/app/views/rounds/show.html.erb @@ -1,16 +1,21 @@

Welcome to “<%= @round.title %>” round

- <% if current_user.owner?(@round) %>
-
-

Owner menu

-
    -
  • <%= link_to "list of audiences", owner_round_audiences_path(@round) %>
  • -
  • <%= link_to "list of contestants", owner_round_contestants_path(@round) %>
  • -
-
+ <% if current_user.owner?(@round) %> +
+

Owner menu

+
    +
  • <%= link_to "list of audiences", owner_round_audiences_path(@round) %>
  • +
  • <%= link_to "list of contestants", owner_round_contestants_path(@round) %>
  • +
+
+ <% else %> +
+

User <%= @round.owner.username %> started it

+ <% if !current_user.audience?(@round) %> + <%= button_to "Join the audience", new_round_audience_path(@round), method: :get, class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4" %> + <% end %> +
+ <% end %>
- <% elsif !current_user.audience?(@round) %> - <%= button_to "Join the audience", new_round_audience_path(@round), method: :get, class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4" %> - <% end %>
From fd21b783e7c9494c71646b538a14fb91568bb8c2 Mon Sep 17 00:00:00 2001 From: Kang-Kyu Lee Date: Tue, 2 Jul 2024 00:22:52 -0700 Subject: [PATCH 3/3] Fix test --- test/integration/owner_flow_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/owner_flow_test.rb b/test/integration/owner_flow_test.rb index 6f203bf..a8e2d96 100644 --- a/test/integration/owner_flow_test.rb +++ b/test/integration/owner_flow_test.rb @@ -60,6 +60,6 @@ class OwnerFlowTest < ActionDispatch::IntegrationTest get owner_round_results_path(round.another_id) assert_response :ok - assert_select "h2.font-semibold", "“concert” round contestants" + assert_select "h2.font-semibold", "“concert” round result" end end