Skip to content

Commit 94a6b7e

Browse files
committed
partial for the puzzles table
1 parent 3e9ad54 commit 94a6b7e

File tree

2 files changed

+42
-90
lines changed

2 files changed

+42
-90
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>Question</th>
5+
<th>Answer</th>
6+
<th>Explanation</th>
7+
<th>Link</th>
8+
<th>Actions</th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
<% puzzles.each do |puzzle| %>
13+
<tr>
14+
<td><%= puzzle.question %></td>
15+
<td><%= puzzle.answer %></td>
16+
<td><%= puzzle.explanation %></td>
17+
<td>
18+
<% if puzzle.link.present? %>
19+
<%= link_to 'View', puzzle.link, target: '_blank' %>
20+
&nbsp;
21+
<% end %>
22+
</td>
23+
<td>
24+
<% if actions == :pending %>
25+
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'approve-btn' %>
26+
<%= button_to 'Reject', puzzle_state_path(puzzle, state: :rejected), method: :patch, form_class: 'inline-form', class: 'reject-btn' %>
27+
<% elsif actions == :approved %>
28+
<%= button_to 'Reject', puzzle_state_path(puzzle, state: :rejected), method: :patch, form_class: 'inline-form', class: 'reject-btn' %>
29+
<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'pending-btn' %>
30+
<% elsif actions == :rejected %>
31+
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'approve-btn' %>
32+
<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'pending-btn' %>
33+
<% end %>
34+
</td>
35+
</tr>
36+
<% end %>
37+
</tbody>
38+
</table>

app/views/puzzles/index.html.erb

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,14 @@
11
<% if session[:user_token] %>
22
<%= link_to 'Logout', session_path(1), data: { turbo_method: :delete } %>
3+
34
<h1>Pending Puzzles</h1>
4-
<table>
5-
<thead>
6-
<tr>
7-
<th>Question</th>
8-
<th>Answer</th>
9-
<th>Explanation</th>
10-
<th>Link</th>
11-
<th>Actions</th>
12-
</tr>
13-
</thead>
14-
<tbody>
15-
<% @pending_puzzles.each do |puzzle| %>
16-
<tr>
17-
<td><%= puzzle.question %></td>
18-
<td><%= puzzle.answer %></td>
19-
<td><%= puzzle.explanation %></td>
20-
<td>
21-
<% if puzzle.link.present? %>
22-
<%= link_to 'View', puzzle.link, target: '_blank' %>
23-
&nbsp;
24-
<% end %>
25-
</td>
26-
<td>
27-
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'approve-btn' %>
28-
<%= button_to 'Reject', puzzle_state_path(puzzle, state: :rejected), method: :patch, form_class: 'inline-form', class: 'reject-btn' %>
29-
</td>
30-
</tr>
31-
<% end %>
32-
</tbody>
33-
</table>
5+
<%= render partial: 'puzzles_table', locals: { puzzles: @pending_puzzles, actions: :pending } %>
346

357
<h1>Approved Puzzles</h1>
36-
<table>
37-
<thead>
38-
<tr>
39-
<th>Question</th>
40-
<th>Answer</th>
41-
<th>Explanation</th>
42-
<th>Link</th>
43-
<th>Actions</th>
44-
</tr>
45-
</thead>
46-
<tbody>
47-
<% @approved_puzzles.each do |puzzle| %>
48-
<tr>
49-
<td><%= puzzle.question %></td>
50-
<td><%= puzzle.answer %></td>
51-
<td><%= puzzle.explanation %></td>
52-
<td>
53-
<% if puzzle.link.present? %>
54-
<%= link_to 'View', puzzle.link, target: '_blank' %>
55-
&nbsp;
56-
<% end %>
57-
</td>
58-
<td>
59-
<%= button_to 'Reject', puzzle_state_path(puzzle, state: :rejected), method: :patch, form_class: 'inline-form', class: 'reject-btn' %>
60-
<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'pending-btn' %>
61-
</td>
62-
</tr>
63-
<% end %>
64-
</tbody>
65-
</table>
8+
<%= render partial: 'puzzles_table', locals: { puzzles: @approved_puzzles, actions: :approved } %>
669

6710
<h1>Rejected Puzzles</h1>
68-
<table>
69-
<thead>
70-
<tr>
71-
<th>Question</th>
72-
<th>Answer</th>
73-
<th>Explanation</th>
74-
<th>Link</th>
75-
<th>Actions</th>
76-
</tr>
77-
</thead>
78-
<tbody>
79-
<% @rejected_puzzles.each do |puzzle| %>
80-
<tr>
81-
<td><%= puzzle.question %></td>
82-
<td><%= puzzle.answer %></td>
83-
<td><%= puzzle.explanation %></td>
84-
<td>
85-
<% if puzzle.link.present? %>
86-
<%= link_to 'View', puzzle.link, target: '_blank' %>
87-
&nbsp;
88-
<% end %>
89-
</td>
90-
<td>
91-
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'approve-btn' %>
92-
<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'pending-btn' %>
93-
</td>
94-
</tr>
95-
<% end %>
96-
</tbody>
97-
</table>
11+
<%= render partial: 'puzzles_table', locals: { puzzles: @rejected_puzzles, actions: :rejected } %>
9812
<% else %>
9913
<%= link_to 'Login with Google', '/auth/google_oauth2' %>
10014
<% end %>

0 commit comments

Comments
 (0)