Skip to content

Commit 32e22ea

Browse files
Merge branch 'main' into refact/likes-controller
Co-authored-by: Paulo Henrique Meneses <[email protected]>
2 parents 7807902 + 0c3b229 commit 32e22ea

20 files changed

+267
-82
lines changed
+1
Loading

app/assets/images/thumbs-up-solid.svg

+1
Loading

app/assets/stylesheets/application.bootstrap.scss

+20
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,24 @@ input[type="checkbox"]:checked {
7070

7171
.categories{
7272
width: 35% !important;
73+
}
74+
75+
.highlighted {
76+
transform: scale(1.01s);
77+
background-color: hsla(256, 85%, 82%, 0.2);
78+
box-shadow: 0 0 5px 5px rgba(0, 0, 0, 0.2);
79+
transition:
80+
transform 1.5s ease-in-out,
81+
box-shadow 1.5s ease-in-out,
82+
background-color 1.5s ease-in-out;
83+
}
84+
85+
[id^='comment_'] {
86+
transform: reset;
87+
background-color: reset;
88+
box-shadow: reset;
89+
transition:
90+
transform 1s ease-in-out,
91+
box-shadow 1s ease-in-out,
92+
background-color 1s ease-in-out;
7393
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class PostInterestNotificationJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(comment)
5+
post = comment.post
6+
users = post.comments.map(&:user).uniq.excluding(comment.user, post.user)
7+
users.each { |user| Notification.create!(profile: user.profile, notifiable: comment) }
8+
end
9+
end

app/models/comment.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ class Comment < ApplicationRecord
44
belongs_to :user
55
has_many :likes, as: :likeable, dependent: :destroy
66
has_many :reports, as: :reportable, dependent: :destroy
7-
has_one :notification, as: :notifiable, dependent: :destroy
7+
has_many :notifications, as: :notifiable, dependent: :destroy
88

9+
after_create :notify_interested_users
910
after_create :create_notification
1011

1112
private
1213

14+
def notify_interested_users
15+
PostInterestNotificationJob.perform_later(self)
16+
end
17+
1318
def create_notification
1419
comment_author = user.profile
1520
return if comment_author == post.user.profile

app/models/profile.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def self.advanced_search(search_query)
4545
left_outer_joins(:job_categories, :personal_info, :user).where(
4646
'job_categories.name LIKE :term OR
4747
personal_infos.city LIKE :term OR
48-
users.full_name LIKE :term',
48+
users.full_name LIKE :term OR users.search_name LIKE :term',
4949
{ term: "%#{sanitize_sql_like(search_query)}%" }
5050
).public_profile.active.uniq
5151
end

app/models/user.rb

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class User < ApplicationRecord
2323

2424
after_create :'create_profile!'
2525
after_create :subscribe_likes_mailer_job
26+
after_create :update_search_name
2627

2728
def description
2829
if admin?
@@ -105,4 +106,8 @@ def cloned_user
105106
clone.save!
106107
clone
107108
end
109+
110+
def update_search_name
111+
update(search_name: I18n.transliterate(full_name, locale: :en))
112+
end
108113
end

app/views/invitations/show.html.erb

+30-34
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
1-
<div class="container">
2-
<div class="row">
3-
<section>
4-
<h2 class="text-center">Convite</h2>
1+
<h2 class="text-center">Convite</h2>
52

6-
<div class="col-md-6 offset-md-3">
7-
<div class="card shadow rounded">
8-
<div class="card-body">
9-
<h4 class="text-break text-primary"><%= @invitation.project_title %></h4>
3+
<div class="col-md-6 offset-md-3">
4+
<div class="card shadow rounded">
5+
<div class="card-body">
6+
<h4 class="text-break text-primary"><%= @invitation.project_title %></h4>
7+
8+
<p class="card-text"><%= @invitation.project_description %></p>
9+
<p class="card-subtitle mb-2 text-muted">Categoria: <%= @invitation.project_category %></p>
10+
<% if @invitation.message.present? %>
11+
<p class="card-subtitle mb-2 text-muted">Mensagem: <%= @invitation.message %></p>
12+
<% end %>
13+
<% if @invitation.expiration_date.present? %>
14+
<p class="card-subtitle mb-2 text-muted">Expira dia: <%= I18n.l(@invitation.expiration_date) %></p>
15+
<% end %>
1016

11-
<p class="card-text"><%= @invitation.project_description %></p>
12-
<p class="card-subtitle mb-2 text-muted">Categoria: <%= @invitation.project_category %></p>
13-
14-
<% if @invitation.pending? %>
15-
<p class="card-subtitle mb-2 text-muted">Expira dia: <%= I18n.l(@invitation.expiration_date) %></p>
16-
17-
<div class="btn-group">
18-
<div>
19-
<%= link_to 'Aceitar', 'http://localhost:4000', method: :patch, class: 'btn btn-primary me-4' %>
20-
</div>
21-
<div>
22-
<%= button_to 'Recusar', decline_invitation_path(@invitation), method: :patch, class: 'btn btn-secondary' %>
23-
</div>
24-
</div>
25-
26-
<p class="card-subtitle mb-2 text-muted">Mensagem: <%= @invitation.message %></p>
27-
<% end %>
28-
29-
<p class="card-subtitle mb-2 text-success"><%= 'Aceito' if @invitation.accepted? %></p>
30-
<p class="card-subtitle mb-2 text-danger"><%= 'Expirado' if @invitation.expired? %></p>
31-
<p class="card-subtitle mb-2 text-danger"><%= 'Recusado' if @invitation.declined? %></p>
32-
<p class="card-subtitle mb-2 text-dark"><%= 'Cancelado' if @invitation.cancelled? %></p>
33-
<p class="card-subtitle mb-2 text-info"> <%= 'Processando' if @invitation.processing? %></p>
17+
<% if @invitation.pending? %>
18+
<div class="btn-group">
19+
<div>
20+
<%= link_to 'Aceitar', 'http://localhost:3000', class: 'btn btn-primary me-4' %>
21+
</div>
22+
<div>
23+
<%= button_to 'Recusar', decline_invitation_path(@invitation), method: :patch, class: 'btn btn-secondary' %>
3424
</div>
3525
</div>
36-
</div>
37-
</section>
26+
<% end %>
27+
28+
<p class="card-subtitle mb-2 text-success"><%= 'Aceito' if @invitation.accepted? %></p>
29+
<p class="card-subtitle mb-2 text-danger"><%= 'Expirado' if @invitation.expired? %></p>
30+
<p class="card-subtitle mb-2 text-danger"><%= 'Recusado' if @invitation.declined? %></p>
31+
<p class="card-subtitle mb-2 text-dark"><%= 'Cancelado' if @invitation.cancelled? %></p>
32+
<p class="card-subtitle mb-2 text-info"> <%= 'Processando' if @invitation.processing? %></p>
33+
</div>
3834
</div>
39-
</div>
35+
</div>
+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação
1+
<% if notification.notifiable.post.user != current_user %>
2+
<p>
3+
<%= link_to notification.notifiable.user.full_name,
4+
profile_path(notification.notifiable.user.profile) %>
5+
<%= t('notifications.index.commented_on_post') %>
6+
"<%= link_to notification.notifiable.post.title,
7+
post_path(notification.notifiable.post, anchor: "comment_#{notification.notifiable.id}") %>"
8+
<% else %>
9+
<p>
10+
<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> <%= t('notifications.index.commented_on_your_post') %>
11+
<% end %>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p><%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir
1+
<p><%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<p>Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %>
1+
<p>
2+
Você recebeu um convite para
3+
<%= link_to notification.notifiable.project_title,
4+
invitation_path(notification.notifiable) %>
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<div class="container d-flex flex-column align-items-center">
2-
<h2>Notificações</h2>
2+
<h2><%= Notification.model_name.human(count: @notifications.count) %></h2>
33
<% if @notifications&.any? %>
4-
<% @notifications.each do |notification| %>
5-
<div class="list-group">
6-
<%= render(
7-
partial: "#{notification.notifiable.class.name.downcase}" ,
8-
locals: { notification: notification }
9-
)%>
10-
<%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %></p>
11-
</div>
12-
<% end %>
4+
<% @notifications.each do |notification| %>
5+
<div class="list-group">
6+
<%= render(
7+
partial: "#{notification.notifiable.class.name.downcase}" ,
8+
locals: { notification: notification }
9+
)%>
10+
<%= t('.time_ago', time: time_ago_in_words(notification.notifiable.created_at)) %>
11+
</div>
12+
<% end %>
1313
<% else %>
14-
<p>Nenhuma notificação encontrada</p>
14+
<p><%= t('.no_notifications') %></p>
1515
<% end %>
16-
</div>
16+
</div>

app/views/posts/show.html.erb

+44-17
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@
4242
</p>
4343

4444
<div class="btn-group">
45-
<div class="me-2">
45+
<div class="me-2 mt-2">
4646
<%= @likes_count %> <%= Like.model_name.human(count: @likes_count) %>
4747
</div>
4848
<% if @liked %>
49-
<%= button_to 'Descurtir', post_like_path(@post, @liked), method: :delete, class: 'btn btn-danger btn-sm' %>
49+
<%= button_to post_like_path(@post, @liked), method: :delete, class: 'btn btn-sm', id: 'unlike' do %>
50+
<%= image_tag 'thumbs-up-solid', width: '20rem' %>
51+
<% end %>
5052
<% else %>
51-
<%= button_to 'Curtir', post_likes_path(@post), method: :post, class: 'btn btn-primary btn-sm' %>
53+
<%= button_to post_likes_path(@post), method: :post, class: 'btn btn-sm', id: 'like' do %>
54+
<%= image_tag 'thumbs-up-regular', width: '20rem' %>
55+
<% end %>
5256
<% end %>
5357
</div>
5458
</div>
@@ -65,7 +69,7 @@
6569
<%= @post.comments.count %> <%= Comment.model_name.human(count: @post.comments.count) %>
6670
</div>
6771
<% @post.comments.each do |comment| %>
68-
<div class="card-body" id="comment-<%= comment.id%>">
72+
<div class="card-body" id="<%= dom_id(comment) %>">
6973
<blockquote class="blockquote mb-0">
7074
<p><%= comment.message %></p>
7175
<footer class="blockquote-footer">
@@ -74,19 +78,25 @@
7478
</blockquote>
7579

7680
<% if comment.user.deleted_at.nil? %>
77-
<div class="btn-group">
78-
<div class="me-2">
79-
<%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %>
80-
</div>
81+
<div class="btn-group flex-column">
82+
<div class="d-flex">
83+
<div class="mt-2 me-2">
84+
<%= comment.likes.count %> <%= Like.model_name.human(count: comment.likes.count) %>
85+
</div>
8186

82-
<div class="me-2">
83-
<% if user_signed_in? && comment.likes.where(user_id: current_user.id).any? %>
84-
<% like = comment.likes.find_by(user_id: current_user.id) %>
85-
<%= button_to 'Descurtir', comment_like_path(comment, like), method: :delete, class: 'btn btn-danger btn-sm' %>
86-
<% else %>
87-
<%= button_to 'Curtir', comment_likes_path(comment), method: :post, class: 'btn btn-primary btn-sm' %>
88-
<% end %>
89-
</div>
87+
<div class="me-2">
88+
<% if user_signed_in? && comment.likes.where(user_id: current_user.id).any? %>
89+
<% like = comment.likes.find_by(user_id: current_user.id) %>
90+
<%= button_to comment_like_path(comment, like), method: :delete, class: 'btn btn-sm', id: 'unlike' do %>
91+
<%= image_tag 'thumbs-up-solid', width: '20rem', class: 'mb-4' %>
92+
<% end %>
93+
<% else %>
94+
<%= button_to comment_likes_path(comment), method: :post, class: 'btn btn-sm', id: 'like' do %>
95+
<%= image_tag 'thumbs-up-regular', width: '20rem', class: 'mb-2' %>
96+
<% end %>
97+
<% end %>
98+
</div>
99+
</div>
90100

91101
<% if current_user != comment.user %>
92102
<div class="report-link-wrapper">
@@ -97,4 +107,21 @@
97107
<% end %>
98108
</div>
99109
<% end %>
100-
</div>
110+
</div>
111+
112+
<script>
113+
document.addEventListener('turbo:load', () => {
114+
if (window.location.pathname === "/posts/<%= @post.id%>") {
115+
const anchor_tag = window.location.hash;
116+
if (anchor_tag) {
117+
const comment = document.querySelector(anchor_tag);
118+
if (comment) {
119+
comment.classList.add('highlighted');
120+
setTimeout(function() {
121+
comment.classList.remove('highlighted');
122+
}, 4000);
123+
}
124+
}
125+
};
126+
});
127+
</script>

config/locales/notifications.pt-BR.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ pt-BR:
77

88
notifications:
99
new_follower_mail: '%{follower_name} te seguiu'
10-
new_notificaiton: 'Você recebeu uma nova notificação!'
10+
new_notificaiton: 'Você recebeu uma nova notificação!'
11+
index:
12+
no_notifications: 'Nenhuma notificação encontrada'
13+
commented_on_post: 'comentou no post'
14+
commented_on_your_post: 'comentou em sua publicação'
15+
time_ago: 'há %{time}'

config/solid_queue.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default: &default
66
- queues: "*"
77
threads: 1
88
processes: 1
9-
polling_interval: 0.1
9+
polling_interval: 1
1010

1111
development:
1212
<<: *default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddSearchNameToUsers < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :users, :search_name, :string
4+
end
5+
end

db/schema.rb

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)