From 62d7abdd9e699779a7e74ed5569aa6d631004210 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 6 Apr 2022 22:23:22 +0200 Subject: [PATCH] Add a user friendly message for when no results are found --- assets/css/search.css | 9 +++++++++ locales/en-US.json | 4 +++- src/invidious/frontend/misc.cr | 14 ++++++++++++++ src/invidious/views/search.ecr | 31 ++++++++++++++++++------------- 4 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/invidious/frontend/misc.cr diff --git a/assets/css/search.css b/assets/css/search.css index 226207a5..a5996362 100644 --- a/assets/css/search.css +++ b/assets/css/search.css @@ -69,6 +69,15 @@ fieldset, legend { #filters-apply { text-align: end; } +/* Error message */ + +.no-results-error { + text-align: center; + line-height: 180%; + font-size: 110%; + padding: 15px 15px 125px 15px; +} + /* Responsive rules */ @media only screen and (max-width: 800px) { diff --git a/locales/en-US.json b/locales/en-US.json index 03df88b6..58098929 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -175,7 +175,9 @@ "Show less": "Show less", "Watch on YouTube": "Watch on YouTube", "Switch Invidious Instance": "Switch Invidious Instance", - "Broken? Try another Invidious Instance": "Broken? Try another Invidious Instance", + "search_message_no_results": "No results found.", + "search_message_change_filters_or_query": "Try widening your search query and/or changing the filters.", + "search_message_use_another_instance": " You can also search on another instance.", "Hide annotations": "Hide annotations", "Show annotations": "Show annotations", "Genre: ": "Genre: ", diff --git a/src/invidious/frontend/misc.cr b/src/invidious/frontend/misc.cr new file mode 100644 index 00000000..43ba9f5c --- /dev/null +++ b/src/invidious/frontend/misc.cr @@ -0,0 +1,14 @@ +module Invidious::Frontend::Misc + extend self + + def redirect_url(env : HTTP::Server::Context) + prefs = env.get("preferences").as(Preferences) + + if prefs.automatic_instance_redirect + current_page = env.get?("current_page").as(String) + redirect_url = "/redirect?referer=#{current_page}" + else + redirect_url = "https://redirect.invidious.io#{env.request.resource}" + end + end +end diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index f1f6ab20..7110703e 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -9,18 +9,13 @@ url_prev_page = "/search?q=#{search_query_encoded}&#{filter_params}&page=#{query.page - 1}" url_next_page = "/search?q=#{search_query_encoded}&#{filter_params}&page=#{query.page + 1}" + + redirect_url = Invidious::Frontend::Misc.redirect_url(env) -%> -<% if videos.size == 0 %> -

- "><%= translate(locale, "Broken? Try another Invidious Instance!") %> -

-<%- else -%> - <%= Invidious::Frontend::SearchFilters.generate(query.filters, query.text, query.page, locale) %> -<%- end -%> - -<% if videos.size == 0 %>
<% else %>
<% end %> +<%= Invidious::Frontend::SearchFilters.generate(query.filters, query.text, query.page, locale) %> +
@@ -36,11 +31,21 @@
-
- <% videos.each do |item| %> - <%= rendered "components/item" %> - <% end %> +<%- if videos.empty? -%> +
+
+ <%= translate(locale, "search_message_no_results") %>

+ <%= translate(locale, "search_message_change_filters_or_query") %>

+ <%= translate(locale, "search_message_use_another_instance", redirect_url) %> +
+<%- else -%> +
+ <%- videos.each do |item| -%> + <%= rendered "components/item" %> + <%- end -%> +
+<%- end -%>