From 1bb8429fe5c4b954294c9ab6aa3314bd41e9a11c Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 9 Apr 2021 21:36:16 -0700 Subject: [PATCH] Declutter search bar to only show search query This commit changes the way search filters are parsed. Instead of directly appending the data into the search query and creating k:v pairs, all of the search filters are now a URL parameter. This results in a clear look overall and hides much of the logic from the end user. Closes #1969 --- src/invidious.cr | 4 ---- src/invidious/routes/playlists.cr | 2 +- src/invidious/search.cr | 16 ++++++++-------- src/invidious/views/search.ecr | 13 ++++++------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index f7c8980a..4af87648 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1726,8 +1726,6 @@ get "/channel/:ucid" do |env| count, items = get_60_videos(channel.ucid, channel.author, page, channel.auto_generated, sort_by) items.reject! &.paid - - env.set "search", "channel:#{channel.ucid} " end templated "channel" @@ -1781,7 +1779,6 @@ get "/channel/:ucid/playlists" do |env| items = items.select { |item| item.is_a?(SearchPlaylist) }.map { |item| item.as(SearchPlaylist) } items.each { |item| item.author = "" } - env.set "search", "channel:#{channel.ucid} " templated "playlists" end @@ -1824,7 +1821,6 @@ get "/channel/:ucid/community" do |env| next error_template(500, ex) end - env.set "search", "channel:#{channel.ucid} " templated "community" end diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr index 1f7fa27d..ad19fc98 100644 --- a/src/invidious/routes/playlists.cr +++ b/src/invidious/routes/playlists.cr @@ -267,7 +267,7 @@ class Invidious::Routes::Playlists < Invidious::Routes::BaseRoute query = env.params.query["q"]? if query begin - search_query, count, items, operators = process_search_query(query, page, user, region: nil) + search_query, count, items, operators = process_search_query(env.params.query, query, page, user, region: nil) videos = items.select { |item| item.is_a? SearchVideo }.map { |item| item.as(SearchVideo) } rescue ex videos = [] of SearchVideo diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 662173a0..6d4afc03 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -400,7 +400,7 @@ def produce_channel_search_continuation(ucid, query, page) return continuation end -def process_search_query(query, page, user, region) +def process_search_query(url_params, query, page, user, region) if user user = user.as(User) view_name = "subscriptions_#{sha256(user.email)}" @@ -414,13 +414,13 @@ def process_search_query(query, page, user, region) sort = "relevance" subscriptions = nil - operators = query.split(" ").select { |a| a.match(/\w+:[\w,]+/) } - operators.each do |operator| - key, value = operator.downcase.split(":") + # operators = url_params.split(" ").select { |a| a.match(/\w+:[\,]+/) } + url_params.each do |operator| + key, value = operator case key when "channel", "user" - channel = operator.split(":")[-1] + channel = value when "content_type", "type" content_type = value when "date" @@ -434,11 +434,11 @@ def process_search_query(query, page, user, region) when "subscriptions" subscriptions = value == "true" else - operators.delete(operator) + url_params.delete(key) end end - search_query = (query.split(" ") - operators).join(" ") + search_query = query if channel count, items = channel_search(search_query, page, channel) @@ -463,5 +463,5 @@ def process_search_query(query, page, user, region) count, items = search(search_query, search_params, region).as(Tuple) end - {search_query, count, items, operators} + {search_query, count, items, url_params} end diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index 15389dce..85867bd2 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -2,7 +2,6 @@ <%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious <% end %> - <% if count == 0 %>

"><%= translate(locale, "Broken? Try another Invidious Instance!") %> @@ -21,7 +20,7 @@ <% if operator_hash.fetch("date", "all") == date %> <%= translate(locale, date) %> <% else %> - &page=<%= page %>"> + <%= translate(locale, date) %> <% end %> @@ -36,7 +35,7 @@ <% if operator_hash.fetch("content_type", "all") == content_type %> <%= translate(locale, content_type) %> <% else %> - &page=<%= page %>"> + <%= translate(locale, content_type) %> <% end %> @@ -51,7 +50,7 @@ <% if operator_hash.fetch("duration", "all") == duration %> <%= translate(locale, duration) %> <% else %> - &page=<%= page %>"> + <%= translate(locale, duration) %> <% end %> @@ -66,11 +65,11 @@ <% if operator_hash.fetch("features", "all").includes?(feature) %> <%= translate(locale, feature) %> <% elsif operator_hash.has_key?("features") %> - &page=<%= page %>"> + "> <%= translate(locale, feature) %> <% else %> - &page=<%= page %>"> + <%= translate(locale, feature) %> <% end %> @@ -85,7 +84,7 @@ <% if operator_hash.fetch("sort", "relevance") == sort %> <%= translate(locale, sort) %> <% else %> - &page=<%= page %>"> + <%= translate(locale, sort) %> <% end %>