Skip to content

Commit 5083744

Browse files
committed
feature/Make comments notifiable
1 parent 1e102bc commit 5083744

File tree

13 files changed

+82
-18
lines changed

13 files changed

+82
-18
lines changed

app/assets/stylesheets/card.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
border-radius: 2px;
77
position: relative;
88
margin: 16px 0px;
9-
padding: 16px 8px;
109
box-shadow: 0 1px 2px lightgrey;
1110
border: 1px solid lightgrey;
1211

12+
1313
&-padding {
1414
padding: 16px;
1515
}

app/assets/stylesheets/helpers.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// DISPLAY
1616

1717
.block { display: block; }
18+
.inline-block { display: inline-block; }
1819
.hidden { display: none !important; }
1920

2021
// POSITION
@@ -37,6 +38,10 @@
3738
.margin-top {
3839
margin-top: 16px;
3940

41+
&--small {
42+
margin-top: 8px;
43+
}
44+
4045
&--tiny {
4146
margin-top: 4px;
4247
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@import './variables.scss';
2+
3+
.notification {
4+
&--wrapper {
5+
cursor: pointer;
6+
border-bottom: 1px solid lightgrey;
7+
padding: 16px;
8+
9+
&:hover {
10+
background-color: $color-hover;
11+
}
12+
}
13+
14+
&--body {
15+
display: block;
16+
margin-top: 8px;
17+
margin-left: 60px;
18+
}
19+
}

app/assets/stylesheets/user-preview.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
margin: 8px 0px 0px 12px;
1818

1919
&-name {
20-
display: block;
2120
font-weight: 500;
2221
font-size: 16px;
2322
font-family: Helvetica, sans-serif;
2423
overflow: hidden;
2524
text-overflow: ellipsis;
2625
max-width: 130px;
27-
display: block;
2826
}
2927

3028
&-time-ago {

app/controllers/comments_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def create
77
@comment = @snippet.comments.new(comment_params)
88

99
if @comment.save
10+
@comment.notifications.create(user: @snippet.user)
1011
flash[:notice] = 'Comment created!'
1112
redirect_to snippet_path(@snippet)
1213
else

app/helpers/application_helper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ def notification_counter(user)
1717
end
1818
end
1919

20-
def notification_for_display(notification)
20+
def notification_action_text(notification)
2121
case notification.notifiable_type
2222
when 'Follow'
23-
render partial: 'notifications/follow', locals: { notification: notification }
23+
'followed you'
24+
when 'Comment'
25+
'commented on your snippet'
2426
end
2527
end
2628
end

app/models/comment.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class Comment < ApplicationRecord
22
belongs_to :snippet, counter_cache: true
33
belongs_to :user
4+
has_many :notifications, as: :notifiable, dependent: :destroy
45

56
validates_presence_of :body
67

app/models/snippet.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ def private?
6666
end
6767

6868
def visible_to?(user)
69-
self.user_id == user.try(:id)
69+
if private?
70+
self.user_id == user.try(:id)
71+
else
72+
true
73+
end
7074
end
7175

7276
private
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<% commenter = notification.notifiable.user %>
2+
3+
<%= render 'notifications/notification', url: snippet_path(notification.notifiable.snippet), user: commenter, notification: notification do %>
4+
<span class="notification--body"><%= notification.notifiable.body.first(150) %></span>
5+
<% end %>
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
<% follower = notification.notifiable.follower %>
22

3-
<div
4-
class="card--container card--container-padding"
5-
style="cursor: pointer;"
6-
data-controller="navigation"
7-
data-navigation-url-value="<%= user_path(follower) %>"
8-
data-action="click->navigation#navigate"
9-
>
10-
<span><%= follower.name %> followed you</span>
11-
</div>
3+
<%= render 'notifications/notification', url: user_path(follower), user: follower, notification: notification %>

0 commit comments

Comments
 (0)