Skip to content

Commit

Permalink
add banner toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 1, 2024
1 parent 3621b48 commit d130221
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ linkarooie/

## Gather Script

[GRABIT.SH](https://grabit.sh) was inspired by this script.
- [GRABIT.SH](https://grabit.sh) was inspired by this script.

The `gather.sh` script is a utility for collecting project information:

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ def update
protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :password, :password_confirmation, :username, :full_name, :tags, :avatar, :banner, :description])
devise_parameter_sanitizer.permit(:account_update, keys: [:email, :password, :password_confirmation, :username, :full_name, :tags, :avatar, :banner, :description])
devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :password, :password_confirmation, :username, :full_name, :tags, :avatar, :banner, :description, :banner_enabled])
devise_parameter_sanitizer.permit(:account_update, keys: [:email, :password, :password_confirmation, :username, :full_name, :tags, :avatar, :banner, :description, :banner_enabled])
end

def sign_up_params
params.require(:user).permit(:email, :password, :password_confirmation, :username, :full_name, :tags, :avatar, :banner, :description).tap do |user_params|
params.require(:user).permit(:email, :password, :password_confirmation, :username, :full_name, :tags, :avatar, :banner, :description, :banner_enabled).tap do |user_params|
user_params[:tags] = user_params[:tags].split(',').map(&:strip).to_json if user_params[:tags].present?
end
end

def account_update_params
params.require(:user).permit(:email, :password, :password_confirmation, :current_password, :username, :full_name, :tags, :avatar, :banner, :description, :public_analytics).tap do |user_params|
params.require(:user).permit(:email, :password, :password_confirmation, :current_password, :username, :full_name, :tags, :avatar, :banner, :description, :banner_enabled, :public_analytics).tap do |user_params|
user_params[:tags] = user_params[:tags].split(',').map(&:strip).to_json if user_params[:tags].present?
end
end
Expand Down
5 changes: 5 additions & 0 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<%= f.text_field :banner, class: 'w-full p-1 rounded text-black' %>
</div>

<div class="mb-2">
<%= f.label :banner_enabled, class: 'block text-gray-300 mb-1' %>
<%= f.check_box :banner_enabled, class: 'rounded text-black' %>
</div>

<div class="mb-2">
<%= f.label :description, class: 'block text-gray-300 mb-1' %>
<%= f.text_area :description, class: 'w-full p-1 rounded text-black' %>
Expand Down
19 changes: 12 additions & 7 deletions app/views/links/user_links.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<% set_open_graph_tags(@user) if @user %>

<div class="profile-header max-w-4xl mx-auto px-4 text-center">
<div class="avatar-container flex flex-col items-center">
<div class="profile-header max-w-2xl mx-auto px-4 text-center">
<% if @user.banner_enabled && @user.banner.present? %>
<div class="w-full h-16 md:h-20 lg:h-24 relative overflow-hidden mb-2">
<%= image_tag @user.banner, class: "w-full h-full object-cover object-center" %>
</div>
<% end %>
<div class="avatar-container flex flex-col items-center <%= @user.banner_enabled && @user.banner.present? ? '-mt-16' : 'mt-8' %>">
<div class="avatar">
<% local_avatar_path = "/avatars/#{@user.username}_avatar#{File.extname(@user.avatar)}" %>
<% if File.exist?(Rails.root.join('public' + local_avatar_path)) %>
<%= image_tag local_avatar_path, alt: @user.email, class: "rounded-full border-4 border-white object-cover", style: "width: 8rem; height: auto;" %>
<%= image_tag local_avatar_path, alt: @user.email, class: "rounded-full border-4 border-gray-900 object-cover", style: "width: 8rem; height: 8rem;" %>
<% elsif @user.avatar.present? %>
<%= image_tag @user.avatar, alt: @user.email, class: "rounded-full border-4 border-white object-cover", style: "width: 8rem; height: auto;" %>
<%= image_tag @user.avatar, alt: @user.email, class: "rounded-full border-4 border-gray-900 object-cover", style: "width: 8rem; height: 8rem;" %>
<% else %>
<%= image_tag "greg.jpg", alt: @user.email, class: "rounded-full border-4 border-white object-cover", style: "width: 8rem; height: auto;" %>
<%= image_tag "greg.jpg", alt: @user.email, class: "rounded-full border-4 border-gray-900 object-cover", style: "width: 8rem; height: 8rem;" %>
<% end %>
</div>
<div class="user-info mt-4">
<h1 class="text-xl font-bold text-white text-stroke"><%= @user.full_name %></h1>
<h2 class="text-l font-bold text-white text-stroke"><%= @user.username %></h2>
<h1 class="text-2xl font-bold text-white text-stroke"><%= @user.full_name %></h1>
<h2 class="text-xl font-bold text-white text-stroke"><%= @user.username %></h2>
<div class="tags flex flex-wrap justify-center mt-2">
<% @user.tags.each do |tag| %>
<span class="tag bg-gray-700 text-white rounded px-2 py-1 m-1"><%= tag %></span>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240901125227_add_banner_enabled_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBannerEnabledToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :banner_enabled, :boolean, default: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d130221

Please sign in to comment.