Skip to content

A platform for community discussion. Free, open, simple.

FIX: Show better error if no bookmarks found from search (#11284)

Martin Brennana6f700d4ef44
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 8beea25b2f2..d97ad5f71e4 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1542,7 +1542,9 @@ class UsersController < ApplicationController
if bookmark_list.bookmarks.empty?
render json: {
bookmarks: [],
- no_results_help: I18n.t("user_activity.no_bookmarks.self")
+ no_results_help: I18n.t(
+ params[:q].present? ? "user_activity.no_bookmarks.search" : "user_activity.no_bookmarks.self"
+ )
}
else
page = params[:page].to_i + 1
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index e519c0f7b92..e753a048dc5 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -954,6 +954,7 @@ en:
others: "No activity."
no_bookmarks:
self: "You have no bookmarked posts; bookmarks allow you to quickly refer to specific posts."
+ search: "No bookmarks found with the provided search query."
others: "No bookmarks."
no_likes_given:
self: "You have not liked any posts."
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index bc0f0a054b5..be4b5eff8fe 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -4561,6 +4561,31 @@ describe UsersController do
get "/u/#{bookmark3.user.username}/bookmarks.json"
expect(response.status).to eq(403)
end
+
+ it "shows a helpful message if no bookmarks are found" do
+ bookmark1.destroy
+ bookmark2.destroy
+ bookmark3.destroy
+ sign_in(user)
+ get "/u/#{user.username}/bookmarks.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body['bookmarks']).to eq([])
+ expect(response.parsed_body['no_results_help']).to eq(
+ I18n.t('user_activity.no_bookmarks.self')
+ )
+ end
+
+ it "shows a helpful message if no bookmarks are found for the search" do
+ sign_in(user)
+ get "/u/#{user.username}/bookmarks.json", params: {
+ q: 'badsearch'
+ }
+ expect(response.status).to eq(200)
+ expect(response.parsed_body['bookmarks']).to eq([])
+ expect(response.parsed_body['no_results_help']).to eq(
+ I18n.t('user_activity.no_bookmarks.search')
+ )
+ end
end
def create_second_factor_security_key