Skip to content

Commit

Permalink
Merge pull request #30 from laruby2/kangkyu/fix-updating
Browse files Browse the repository at this point in the history
Fix updating
  • Loading branch information
kangkyu authored Jul 2, 2024
2 parents 9fcf4f0 + fd21b78 commit 8512ee2
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 23 deletions.
4 changes: 4 additions & 0 deletions app/controllers/owner/contestants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions app/views/admin/dashboard/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<%= turbo_stream_from "activity" %>

<p><%= pluralize @users, "user" %></p>
<p><%= pluralize @rounds, "round" %></p>
4 changes: 4 additions & 0 deletions app/views/contestants/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= turbo_stream_from "audience_contestants" %>

<div class="max-w-md mx-auto mt-5">
<h2 class="text-2xl font-semibold mb-4"><%= link_to @round.title, round_path(@round) %>” round contestants</h2>
</div>

<%= turbo_frame_tag "contestants" do %>
<% if @contestants.any? %>
<ul class="w-full text-sm font-medium text-gray-900 bg-white border border-gray-200 dark:bg-gray-700 dark:border-gray-600 dark:text-white" id="audience_contestant">
Expand Down
Empty file.
11 changes: 3 additions & 8 deletions app/views/owner/contestants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
<% end %>
</ul>

<% unless current_page?(owner_round_results_path(@round)) %>

<div class="min-h-full flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
<div class="max-w-md w-full space-y-8">
<%= form_with(url: owner_round_contestants_path(@round), method: :post, model: [@round, @round.contestants.build], class: "mt-8 space-y-6") do |f| %>
<div class="flex space-x-2">
<%= 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" %>
</div>
<div>
<%= 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" %>
</div>
<% end %>
</div>
</div>


<% end %>
11 changes: 11 additions & 0 deletions app/views/owner/contestants/result.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= turbo_stream_from "activity" %>

<div class="max-w-md mx-auto mt-5">
<h2 class="text-2xl font-semibold mb-4"><%= link_to @round.title, round_path(@round) %>” round result</h2>
</div>

<ul class="w-full font-medium text-gray-900 bg-white border border-gray-200 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
<%= turbo_frame_tag "admin_contestants" do %>
<%= render @contestants %>
<% end %>
</ul>
27 changes: 16 additions & 11 deletions app/views/rounds/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<div class="max-w-md mx-auto mt-5">
<h2 class="text-2xl font-semibold mb-4">Welcome to “<%= @round.title %>” round</h2>
<% if current_user.owner?(@round) %>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<p class="text-md font-bold mb-2">Owner menu</p>
<ul class="list-disc list-inside">
<li><%= link_to "list of audiences", owner_round_audiences_path(@round) %></li>
<li><%= link_to "list of contestants", owner_round_contestants_path(@round) %></li>
</ul>
</div>
<% if current_user.owner?(@round) %>
<div>
<p class="text-md font-bold mb-2">Owner menu</p>
<ul class="list-disc list-inside">
<li><%= link_to "list of audiences", owner_round_audiences_path(@round) %></li>
<li><%= link_to "list of contestants", owner_round_contestants_path(@round) %></li>
</ul>
</div>
<% else %>
<div>
<p class="text-md mb-2">User <span class="font-bold"><%= @round.owner.username %></span> started it</p>
<% 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 %>
</div>
<% end %>
</div>
<% 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 %>
</div>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/integration/owner_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8512ee2

Please sign in to comment.