Skip to content

Commit 6bf6ca5

Browse files
committed
refactor/Move user profile section from vue component
1 parent 50eca05 commit 6bf6ca5

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

app/controllers/users_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,24 @@ def follow
3333
@user = User.find_by(id: params[:id])
3434

3535
if current_user.follow(@user)
36-
render json: { message: "You are now following #{@user.name}." }
36+
flash[:notice] = "You are now following #{@user.name}."
3737
else
38-
render json: { message: "You are already following #{@user.name} you nutter!" }, status: 400
38+
flash[:alert] = "You are already following #{@user.name} you nutter!"
3939
end
40+
41+
redirect_to user_path(@user)
4042
end
4143

4244
def unfollow
4345
@user = User.find_by(id: params[:id])
4446

4547
if current_user.unfollow(@user)
46-
render json: { message: "You are no longer following #{@user.name}." }
48+
flash[:notice] = "You are no longer following #{@user.name}."
4749
else
48-
render json: { message: "You can't unfollow someone you aren't following you nutter!" }, status: 400
50+
flash[:alert] = "You can't unfollow someone you aren't following you nutter!"
4951
end
52+
53+
redirect_to user_path(@user)
5054
end
5155

5256
private

app/views/users/show.html.erb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
<card>
2-
<user-profile
3-
:user="<%= @serialized_user %>"
4-
:is-following="<%= @is_following %>"
5-
/>
6-
</card>
1+
<div class="card--container card--container-padding">
2+
<div class="flex v-center">
3+
<div class="flex flex-column">
4+
<img style="border-radius: 50%;" src="<%= @user.avatar_url %>" height="120" width="120" />
5+
</div>
6+
<div class="margin-left">
7+
<h2 class="users-show--name"><%= @user.name %></h2>
8+
<div style="height: 40px;">
9+
<span><%= @user.bio %></span>
10+
</div>
11+
</div>
12+
</div>
13+
14+
<div class="margin-top flex space-between">
15+
<% if user_signed_in? %>
16+
<% if @user == current_user %>
17+
<%= button_to 'EDIT PROFILE', edit_user_registration_path, method: :get, class: 'button--cta-follow' %>
18+
<% elsif current_user.following?(@user) %>
19+
<%= button_to 'FOLLOWING', unfollow_user_path(@user), class: 'button--cta-unfollow' %>
20+
<% else %>
21+
<%= button_to 'FOLLOW', follow_user_path(@user), class: 'button--cta-follow' %>
22+
<% end %>
23+
<% else %>
24+
<%= button_to 'FOLLOW', new_user_registration_path, method: :get, class: 'button--cta-follow' %>
25+
<% end %>
26+
</div>
27+
</div>
728

829
<div data-controller="tabs">
930
<div class="tabs--headers-container">

0 commit comments

Comments
 (0)