Skip to content

Commit 3974c44

Browse files
committed
feature/Add following + followers to respective pages
1 parent 9b31d7c commit 3974c44

File tree

8 files changed

+58
-9
lines changed

8 files changed

+58
-9
lines changed

app/assets/stylesheets/follow.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import './variables.scss';
2+
3+
.horizontal-line {
4+
padding-top: 16px;
5+
margin-top: 16px;
6+
border-top: 1px solid $color-primary;
7+
}
8+
9+
.follow {
10+
&--description {
11+
display: block;
12+
margin-top: 8px;
13+
}
14+
}

app/assets/stylesheets/user-preview.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99

1010
&--img {
11-
border-radius: 2px;
11+
border-radius: 50%;
1212
}
1313

1414
&--summary {

app/controllers/users_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ def show
66

77
def followers
88
@user = User.find_by(id: params[:id])
9-
@following = current_user.following?(@user)
9+
@serialized_user = @user.serialize.to_json
10+
@is_following = current_user.following?(@user)
11+
@followers = @user.followers
1012
end
1113

1214
def following
1315
@user = User.find_by(id: params[:id])
14-
@following = current_user.following?(@user)
16+
@serialized_user = @user.serialize.to_json
17+
@is_following = current_user.following?(@user)
18+
@following = @user.following
1519
end
1620

1721
def follow

app/javascript/packs/snippet_app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import Snipt from '../snipt.vue'
7777
import SnippetPreview from '../snippet-preview.vue'
7878
import SnippetShow from '../snippet-show.vue'
7979
import Toast from '../toast.vue';
80+
import UserPreview from '../user-preview.vue';
8081
import UserProfile from '../user-profile.vue'
8182

8283
// Vue.use(TurbolinksAdapter)
@@ -110,6 +111,7 @@ document.addEventListener('DOMContentLoaded', () => {
110111
SnippetPreview,
111112
SnippetShow,
112113
Toast,
114+
UserPreview,
113115
UserProfile
114116
},
115117
created() {

app/javascript/user-preview.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<a :href="`/users/${user.id}`">
88
<span class="user-preview--summary-name">{{ user.name }}</span>
99
</a>
10-
<span class="user-preview--summary-time-ago">{{ snippet.created_at }}</span>
10+
<span v-if="snippet" class="user-preview--summary-time-ago">{{ snippet.created_at }}</span>
11+
<span v-else class="user-preview--summary-time-ago">@{{ user.name }}</span>
1112
</div>
1213
</div>
1314
</template>
@@ -16,7 +17,7 @@
1617
export default {
1718
props: {
1819
user: { type: Object, required: true },
19-
snippet: { type: Object, required: true }
20+
snippet: { type: Object, required: false }
2021
}
2122
}
2223
</script>

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class User < ApplicationRecord
2828
#TODO: Add tests for this
2929
after_create :create_default_folder
3030

31+
def description
32+
'Software developer on the Integrated Biodiversity Assessment Tool and founder of Snippet.io. Can often be found playing tennis or riding a bike.'
33+
end
34+
3135
def follow(user)
3236
Follow.create(followed_user_id: user.id, follower_id: id)
3337
end

app/views/users/followers.html.erb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<card>
22
<user-profile
3-
:user="<%= @user.serialize.to_json %>"
4-
:is-following="<%= @following %>"
3+
:user="<%= @serialized_user %>"
4+
:is-following="<%= @is_following %>"
55
/>
66
</card>
7+
8+
<card>
9+
<% @followers.each_with_index do |follower, index| %>
10+
<% if index > 0 %>
11+
<div class="horizontal-line"></div>
12+
<% end %>
13+
<div class="follow--container">
14+
<user-preview :user="<%= @serialized_user %>"></user-preview>
15+
<span class="follow--description"><%= follower.description %></span>
16+
</div>
17+
<% end %>
18+
</card>

app/views/users/following.html.erb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
<%# extract to partial %>
22
<card>
33
<user-profile
4-
:user="<%= @user.serialize.to_json %>"
5-
:is-following="<%= @following %>"
4+
:user="<%= @serialized_user %>"
5+
:is-following="<%= @is_following %>"
66
/>
77
</card>
8+
9+
<card>
10+
<% @following.each_with_index do |follower, index| %>
11+
<% if index > 0 %>
12+
<div class="horizontal-line"></div>
13+
<% end %>
14+
<div class="follow--container">
15+
<user-preview :user="<%= follower.serialize.to_json %>"></user-preview>
16+
<span class="follow--description"><%= follower.description %></span>
17+
</div>
18+
<% end %>
19+
</card>

0 commit comments

Comments
 (0)