From 63e3b4b447b11e6dd11a5fe0e680ada4e4a8b02c Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 21 Jan 2021 04:12:13 -0600 Subject: [PATCH] views: factor out FontAwesome icons. Factor out FontAwesome icons into a set of helpers. This is so that it's easier to keep track of which icons we're using and easier to change icons globally. --- app/components/comment_component.rb | 2 +- .../comment_component.html.erb | 12 +- app/components/popup_menu_component.rb | 1 + .../popup_menu_component.html.erb | 2 +- app/components/post_preview_component.rb | 2 +- .../post_preview_component.html.erb | 2 +- app/helpers/forum_topics_helper.rb | 10 ++ app/helpers/icon_helper.rb | 130 ++++++++++++++++++ app/helpers/pagination_helper.rb | 10 +- .../src/styles/common/main_layout.scss | 6 - app/javascript/src/styles/specific/posts.scss | 4 +- app/models/forum_post_vote.rb | 10 -- .../comments/partials/index/_header.html.erb | 2 +- app/views/forum_post_votes/_add_vote.html.erb | 6 +- app/views/forum_post_votes/_vote.html.erb | 4 +- app/views/forum_topics/_listing.html.erb | 8 +- app/views/layouts/default.html.erb | 4 +- app/views/modqueue/_post.html.erb | 2 +- app/views/modqueue/_sidebar.html.erb | 2 +- .../posts/partials/common/_search.html.erb | 2 +- .../posts/partials/index/_options.html.erb | 2 +- app/views/posts/partials/show/_edit.html.erb | 4 +- .../posts/partials/show/_information.html.erb | 4 +- app/views/posts/show.html+tooltip.erb | 8 +- app/views/posts/show.html.erb | 4 +- app/views/sources/_info.html.erb | 2 +- app/views/uploads/new.html.erb | 4 +- app/views/users/_statistics.html.erb | 6 +- app/views/users/show.html+tooltip.erb | 17 +-- 29 files changed, 199 insertions(+), 73 deletions(-) create mode 100644 app/helpers/icon_helper.rb diff --git a/app/components/comment_component.rb b/app/components/comment_component.rb index d4a9427cb..9c0ecd420 100644 --- a/app/components/comment_component.rb +++ b/app/components/comment_component.rb @@ -2,7 +2,7 @@ class CommentComponent < ApplicationComponent attr_reader :comment, :context, :dtext_data, :current_user - delegate :link_to_user, :time_ago_in_words_tagged, :format_text, to: :helpers + delegate :link_to_user, :time_ago_in_words_tagged, :format_text, :edit_icon, :delete_icon, :undelete_icon, :flag_icon, to: :helpers def initialize(comment:, current_user:, context: nil, dtext_data: nil) @comment = comment diff --git a/app/components/comment_component/comment_component.html.erb b/app/components/comment_component/comment_component.html.erb index d931f22b7..1b11545f8 100644 --- a/app/components/comment_component/comment_component.html.erb +++ b/app/components/comment_component/comment_component.html.erb @@ -89,21 +89,18 @@ <% if policy(comment).update? %> <%= menu.item do %> <%= link_to edit_comment_path(comment.id), id: "edit_comment_link_#{comment.id}", class: "edit_comment_link" do %> - - Edit + <%= edit_icon %> Edit <% end %> <% end %> <%= menu.item do %> <% if comment.is_deleted? %> <%= link_to undelete_comment_path(comment.id), method: :post, remote: true do %> - - Undelete + <%= undelete_icon %> Undelete <% end %> <% else %> <%= link_to comment_path(comment.id), "data-confirm": "Are you sure you want to delete this comment?", method: :delete, remote: true do %> - - Delete + <%= delete_icon %> Delete <% end %> <% end %> <% end %> @@ -112,8 +109,7 @@ <% if policy(comment).reportable? %> <%= menu.item do %> <%= link_to new_moderation_report_path(moderation_report: { model_type: "Comment", model_id: comment.id }), remote: true do %> - - Report + <%= flag_icon %> Report <% end %> <% end %> <% end %> diff --git a/app/components/popup_menu_component.rb b/app/components/popup_menu_component.rb index 63463ad02..620a3e33b 100644 --- a/app/components/popup_menu_component.rb +++ b/app/components/popup_menu_component.rb @@ -2,6 +2,7 @@ class PopupMenuComponent < ApplicationComponent include ViewComponent::SlotableV2 + delegate :ellipsis_icon, to: :helpers renders_many :items end diff --git a/app/components/popup_menu_component/popup_menu_component.html.erb b/app/components/popup_menu_component/popup_menu_component.html.erb index 843bf628d..7e4904443 100644 --- a/app/components/popup_menu_component/popup_menu_component.html.erb +++ b/app/components/popup_menu_component/popup_menu_component.html.erb @@ -1,6 +1,6 @@ " @@ -92,7 +92,7 @@ module PaginationHelper html = [] if page == "..." html << "
  • " - html << content_tag(:i, nil, class: "fas fa-ellipsis-h") + html << ellipsis_icon html << "
  • " elsif page == current_page html << "
  • " diff --git a/app/javascript/src/styles/common/main_layout.scss b/app/javascript/src/styles/common/main_layout.scss index 31311a6a2..4a9a0c367 100644 --- a/app/javascript/src/styles/common/main_layout.scss +++ b/app/javascript/src/styles/common/main_layout.scss @@ -5,12 +5,6 @@ div#page { margin: 0 20px; padding: 0 10px; - aside#sidebar { - #options-box i.fa-bookmark { - margin-right: 0.25em; - } - } - aside#sidebar > section { margin-bottom: 1em; } diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index c9e94df39..b0f70c642 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -79,7 +79,7 @@ div#c-posts { } } - #remove-fav-button i.fa-heart { + form#remove-fav-button button:not([disabled]) i.icon { color: var(--remove-favorite-button); } @@ -364,7 +364,7 @@ div#c-posts, div#c-uploads { display: inline-block; } - i.fa-external-link-alt { + i#open-edit-dialog { font-size: var(--text-xs); } diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index 6a2ac7926..d4972e60d 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -36,16 +36,6 @@ class ForumPostVote < ApplicationRecord score == 0 end - def fa_class - if score == 1 - return "fa-thumbs-up" - elsif score == -1 - return "fa-thumbs-down" - else - return "fa-meh" - end - end - def vote_type if score == 1 return "up" diff --git a/app/views/comments/partials/index/_header.html.erb b/app/views/comments/partials/index/_header.html.erb index da2bb9463..ea8d6deac 100644 --- a/app/views/comments/partials/index/_header.html.erb +++ b/app/views/comments/partials/index/_header.html.erb @@ -17,7 +17,7 @@ <%= post.score %> <% if policy(PostVote).create? %> - (vote <%= link_to(content_tag("i", nil, class: "far fa-thumbs-up"), post_post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to(content_tag("i", nil, class: "far fa-thumbs-down"), post_post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>) + (vote <%= link_to upvote_icon, post_post_votes_path(score: "up", post_id: post.id), remote: true, method: :post %>/<%= link_to downvote_icon, post_post_votes_path(score: "down", post_id: post.id), remote: true, method: :post %>) <% end %> diff --git a/app/views/forum_post_votes/_add_vote.html.erb b/app/views/forum_post_votes/_add_vote.html.erb index d8610890e..f0c5b7022 100644 --- a/app/views/forum_post_votes/_add_vote.html.erb +++ b/app/views/forum_post_votes/_add_vote.html.erb @@ -3,9 +3,9 @@ %>
  • - <%= link_to content_tag(:i, nil, class: "far fa-thumbs-up"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=1"}, title: "Vote up" %> + <%= link_to upvote_icon, forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=1"}, title: "Vote up" %> - <%= link_to content_tag(:i, nil, class: "far fa-meh"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=0"}, title: "Vote meh" %> + <%= link_to meh_icon, forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=0"}, title: "Vote meh" %> - <%= link_to content_tag(:i, nil, class: "far fa-thumbs-down"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=-1"}, title: "Vote down" %> + <%= link_to downvote_icon, forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=-1"}, title: "Vote down" %>
  • diff --git a/app/views/forum_post_votes/_vote.html.erb b/app/views/forum_post_votes/_vote.html.erb index a22e093f8..36998b8e3 100644 --- a/app/views/forum_post_votes/_vote.html.erb +++ b/app/views/forum_post_votes/_vote.html.erb @@ -5,10 +5,10 @@
  • <% if policy(forum_post).votable? && vote.creator_id == CurrentUser.id %> - <%= link_to content_tag(:i, nil, class: "far #{vote.fa_class}"), forum_post_vote_path(vote, format: "js"), remote: true, method: :delete %> + <%= link_to forum_post_vote_icon(vote), forum_post_vote_path(vote, format: "js"), remote: true, method: :delete %> <%= link_to_user vote.creator %> <% else %> - <%= content_tag(:i, nil, class: "far #{vote.fa_class}") %> + <%= forum_post_vote_icon(vote) %> <%= link_to_user vote.creator %> <% end %>
  • diff --git a/app/views/forum_topics/_listing.html.erb b/app/views/forum_topics/_listing.html.erb index 8b6baa356..bd04313c1 100644 --- a/app/views/forum_topics/_listing.html.erb +++ b/app/views/forum_topics/_listing.html.erb @@ -8,25 +8,25 @@ <% if topic.is_sticky? %> <%= link_to forum_topics_path(search: { is_sticky: true }) do %> - + <%= sticky_icon(class: "topic-status stickied", title: "Stickied") %> <% end %> <% end %> <% if topic.is_locked? %> <%= link_to forum_topics_path(search: { is_locked: true }) do %> - + <%= lock_icon(class: "topic-status locked", title: "Locked") %> <% end %> <% end %> <% if topic.is_deleted? %> <%= link_to forum_topics_path(search: { is_deleted: true }) do %> - + <%= delete_icon(class: "topic-status deleted", title: "Deleted") %> <% end %> <% end %> <% if topic.is_private? %> <%= link_to forum_topics_path(search: { is_private: true }) do %> - + <%= private_icon(class: "topic-status private", title: "#{User.level_string(topic.min_level)} only") %> <% end %> <% end %> diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 7e8e6d87d..abab235d3 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -53,8 +53,8 @@ <%= link_to Danbooru.config.app_name, root_path, id: "app-name-header", class: "heading" %>
    - - + <%= menu_icon(id: "maintoggle-on") %> + <%= close_icon(id: "maintoggle-off", style: "display: none;") %>