Skip to content

Commit

Permalink
Style/Adiciona ícones para like e dislike
Browse files Browse the repository at this point in the history
Co-authored-by: Caique Arruda <[email protected]>
  • Loading branch information
gmkoeb and caiquedv committed Feb 12, 2024
1 parent aad513a commit 589987f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
1 change: 1 addition & 0 deletions app/assets/images/thumbs-up-regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/images/thumbs-up-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 24 additions & 15 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
</p>

<div class="btn-group">
<div class="me-2">
<div class="me-2 mt-2">
<%= @likes_count %> <%= Like.model_name.human(count: @likes_count) %>
</div>
<% if @liked %>
<%= button_to 'Descurtir', like_path(post_like_id: @liked), method: :delete, class: 'btn btn-danger btn-sm' %>
<%= button_to like_path(post_like_id: @liked), method: :delete, class: 'btn btn-sm', id: 'unlike' do %>
<%= image_tag 'thumbs-up-solid', width: '20rem' %>
<% end %>
<% else %>
<%= button_to 'Curtir', likes_path(post_id: @post), method: :post, class: 'btn btn-primary btn-sm' %>
<%= button_to likes_path(post_id: @post), method: :post, class: 'btn btn-sm', id: 'like' do %>
<%= image_tag 'thumbs-up-regular', width: '20rem' %>
<% end %>
<% end %>
</div>
</div>
Expand All @@ -74,20 +78,25 @@
</blockquote>

<% if comment.user.deleted_at.nil? %>
<div class="btn-group">
<div class="me-2">
<%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %>
</div>
<div class="btn-group flex-column">
<div class="d-flex">
<div class="mt-2 me-2">
<%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %>
</div>

<div class="me-2">
<% if user_signed_in? && comment.likes.where(user_id: current_user.id).any? %>
<% like = comment.likes.find_by(user_id: current_user.id) %>
<%= button_to 'Descurtir', like_path(comment_like_id: like.id), method: :delete, class: 'btn btn-danger btn-sm' %>
<% else %>
<%= button_to 'Curtir', likes_path(comment_id: comment.id), method: :post, class: 'btn btn-primary btn-sm' %>
<% end %>
<div class="me-2">
<% if user_signed_in? && comment.likes.where(user_id: current_user.id).any? %>
<% like = comment.likes.find_by(user_id: current_user.id) %>
<%= button_to like_path(comment_like_id: like.id), method: :delete, class: 'btn btn-sm', id: 'unlike' do %>
<%= image_tag 'thumbs-up-solid', width: '20rem', class: 'mb-4' %>
<% end %>
<% else %>
<%= button_to likes_path(comment_id: comment.id), method: :post, class: 'btn btn-sm', id: 'like' do %>
<%= image_tag 'thumbs-up-regular', width: '20rem', class: 'mb-2' %>
<% end %>
<% end %>
</div>
</div>

<% if current_user != comment.user %>
<div class="report-link-wrapper">
<%= link_to t('reports.report_btn'), new_report_path(reportable: comment, reportable_type: comment.class), class: 'btn btn-secondary btn-sm' %>
Expand Down
20 changes: 10 additions & 10 deletions spec/system/likes/user_likes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

login_as user
visit post_path(post)
click_on 'Curtir'
click_button id: 'like'

expect(page).to have_content('1 Curtida')
expect(page).not_to have_content('Curtir')
expect(page).to have_content('Descurtir')
expect(page).not_to have_selector('#like')
expect(page).to have_selector('#unlike')
end

it 'e deixa de curtir' do
like = create(:like, :for_post)

login_as like.user
visit post_path(like.likeable)
click_on 'Descurtir'
click_button id: 'unlike'

expect(page).to have_content '0 Curtida'
expect(page).to have_content 'Curtir'
expect(page).to have_selector '#like'
expect(Like.count).to eq 0
end
end
Expand All @@ -37,14 +37,14 @@
login_as user
visit post_path(post)
within '#comments' do
click_on 'Curtir'
click_button id: 'like'
end

expect(page).to have_content('1 Curtida')
within '#comments' do
expect(page).not_to have_content('Curtir')
expect(page).not_to have_selector('#like')
end
expect(page).to have_content('Descurtir')
expect(page).to have_selector('#unlike')
end

it 'e deixa de curtir' do
Expand All @@ -53,10 +53,10 @@
login_as like.user
visit post_path(like.likeable.post)
within '#comments' do
click_on 'Descurtir'
click_button id: 'unlike'

expect(page).to have_content '0 Curtida'
expect(page).to have_content 'Curtir'
expect(page).to have_selector '#like'
end
expect(Like.count).to eq 0
end
Expand Down

0 comments on commit 589987f

Please sign in to comment.