Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
drusepth committed Nov 13, 2020
1 parent 48b52be commit 7afc34f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions app/controllers/users_controller.rb
@@ -1,15 +1,13 @@
class UsersController < ApplicationController
before_action :set_user, only: [:show, :followers, :following]

def index
redirect_to new_session_path(User)
end

def show
@sidenav_expansion = 'community'

@user = User.find_by(user_params)
return redirect_to(root_path, notice: 'That user does not exist.') if @user.nil?
return redirect_to(root_path, notice: 'That user does not exist.') if @user.private_profile?

@feed = ContentPageShare.where(user_id: @user.id)
.order('created_at DESC')
.includes([:content_page, :secondary_content_page, :user, :share_comments])
Expand All @@ -18,8 +16,6 @@ def show
@content = @user.public_content.select { |type, list| list.any? }
@tabs = @content.keys

@accent_color = @user.favorite_page_type_color
@accent_icon = @user.favorite_page_type_icon
@favorite_content = @user.favorite_page_type? ? @user.send(@user.favorite_page_type.downcase.pluralize).is_public : []
@stream = @user.recent_content_list(limit: 20)

Expand All @@ -31,9 +27,9 @@ def show
Rails.application.config.content_types[:all].each do |content_type|
content_type_name = content_type.name.downcase.pluralize.to_sym # :characters, :items, etc
define_method content_type_name do
set_user

@content_type = content_type
@user = User.find_by(id: params[:id])
return redirect_to(root_path, notice: "This user does not exist") unless @user.present?
@content_list = @user.send(content_type_name).is_public.order(:name)

render :content_list
Expand Down Expand Up @@ -81,21 +77,23 @@ def report_user_deletion_to_slack user
end

def followers
@user = User.find_by(user_params)
@accent_color = @user.favorite_page_type_color
@accent_icon = @user.favorite_page_type_icon
end

def following
end

private

def set_user
@user = User.find_by(user_params)
return redirect_to(root_path, notice: 'That user does not exist.') if @user.nil?
return redirect_to(root_path, notice: 'That user has chosen to hide their profile.') if @user.private_profile?

@accent_color = @user.favorite_page_type_color
@accent_icon = @user.favorite_page_type_icon
end

private

def user_params
# todo is this used anywhere?
params.permit(:id, :username)
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/_document_navbar.html.erb
Expand Up @@ -38,7 +38,7 @@
<i class="material-icons left"><%= Universe.icon %></i>
<span class="black-text">Set in</span>
<span class="js-content-universe-name">
<%= @document.universe_id.nil? ? 'No Universe Set' : @document.universe.name %>
<%= @document.universe.nil? ? 'No Universe Set' : @document.universe.name %>
</span>
<% end %>
</li>
Expand Down

0 comments on commit 7afc34f

Please sign in to comment.