summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Jankowski <matt@jankowski.online>2024-01-11 05:45:26 -0500
committerGitHub <noreply@github.com>2024-01-11 10:45:26 +0000
commit87097a227c2ab24f27b0d87ec6808c07cb13d93a (patch)
tree5bc543e3e167ffea708471c0f51f5130057c7176
parent55802242ce65dcea36b74fffcb3474e8254192f7 (diff)
Clean up `settings/featured_tags/index` view (#28688)
-rw-r--r--app/helpers/settings_helper.rb27
-rw-r--r--app/views/settings/featured_tags/index.html.haml2
-rw-r--r--spec/controllers/settings/featured_tags_controller_spec.rb10
3 files changed, 38 insertions, 1 deletions
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index 3c72b22c666..10863a316c9 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -9,6 +9,19 @@ module SettingsHelper
LanguagesHelper.sorted_locale_keys(I18n.available_locales)
end
+ def featured_tags_hint(recently_used_tags)
+ safe_join(
+ [
+ t('simple_form.hints.featured_tag.name'),
+ safe_join(
+ links_for_featured_tags(recently_used_tags),
+ ', '
+ ),
+ ],
+ ' '
+ )
+ end
+
def session_device_icon(session)
device = session.detection.device
@@ -28,4 +41,18 @@ module SettingsHelper
safe_join([image_tag(account.avatar.url, width: 15, height: 15, alt: '', class: 'avatar'), content_tag(:span, account.acct, class: 'username')], ' ')
end
end
+
+ private
+
+ def links_for_featured_tags(tags)
+ tags.map { |tag| post_link_to_featured_tag(tag) }
+ end
+
+ def post_link_to_featured_tag(tag)
+ link_to(
+ "##{tag.display_name}",
+ settings_featured_tags_path(featured_tag: { name: tag.name }),
+ method: :post
+ )
+ end
end
diff --git a/app/views/settings/featured_tags/index.html.haml b/app/views/settings/featured_tags/index.html.haml
index 22f91801291..c8c9ec4069f 100644
--- a/app/views/settings/featured_tags/index.html.haml
+++ b/app/views/settings/featured_tags/index.html.haml
@@ -12,7 +12,7 @@
.fields-group
= f.input :name,
- hint: safe_join([t('simple_form.hints.featured_tag.name'), safe_join(@recently_used_tags.map { |tag| link_to("##{tag.display_name}", settings_featured_tags_path(featured_tag: { name: tag.name }), method: :post) }, ', ')], ' '),
+ hint: featured_tags_hint(@recently_used_tags),
wrapper: :with_block_label
.actions
diff --git a/spec/controllers/settings/featured_tags_controller_spec.rb b/spec/controllers/settings/featured_tags_controller_spec.rb
index fc25e7aa889..4e1dd529459 100644
--- a/spec/controllers/settings/featured_tags_controller_spec.rb
+++ b/spec/controllers/settings/featured_tags_controller_spec.rb
@@ -43,10 +43,20 @@ describe Settings::FeaturedTagsController do
end
describe 'GET to #index' do
+ let(:tag) { Fabricate(:tag) }
+
+ before do
+ status = Fabricate :status, account: user.account
+ status.tags << tag
+ end
+
it 'responds with success' do
get :index
expect(response).to have_http_status(200)
+ expect(response.body).to include(
+ settings_featured_tags_path(featured_tag: { name: tag.name })
+ )
end
end