mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-10 18:28:24 +00:00
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
This commit is contained in:
parent
ff43a47716
commit
1bb8429fe5
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -2,7 +2,6 @@
|
||||
<title><%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious</title>
|
||||
<% end %>
|
||||
|
||||
<!-- Search redirection and filtering UI -->
|
||||
<% if count == 0 %>
|
||||
<h3 style="text-align: center">
|
||||
<a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Broken? Try another Invidious Instance!") %></a>
|
||||
@ -21,7 +20,7 @@
|
||||
<% if operator_hash.fetch("date", "all") == date %>
|
||||
<b><%= translate(locale, date) %></b>
|
||||
<% else %>
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?date:[a-z]+/, "") + " date:" + date) %>&page=<%= page %>">
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&date=<%= date %>">
|
||||
<%= translate(locale, date) %>
|
||||
</a>
|
||||
<% end %>
|
||||
@ -36,7 +35,7 @@
|
||||
<% if operator_hash.fetch("content_type", "all") == content_type %>
|
||||
<b><%= translate(locale, content_type) %></b>
|
||||
<% else %>
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?content_type:[a-z]+/, "") + " content_type:" + content_type) %>&page=<%= page %>">
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&content_type=<%= content_type %>">
|
||||
<%= translate(locale, content_type) %>
|
||||
</a>
|
||||
<% end %>
|
||||
@ -51,7 +50,7 @@
|
||||
<% if operator_hash.fetch("duration", "all") == duration %>
|
||||
<b><%= translate(locale, duration) %></b>
|
||||
<% else %>
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?duration:[a-z]+/, "") + " duration:" + duration) %>&page=<%= page %>">
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&duration=<%= duration %>">
|
||||
<%= translate(locale, duration) %>
|
||||
</a>
|
||||
<% end %>
|
||||
@ -66,11 +65,11 @@
|
||||
<% if operator_hash.fetch("features", "all").includes?(feature) %>
|
||||
<b><%= translate(locale, feature) %></b>
|
||||
<% elsif operator_hash.has_key?("features") %>
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/features:/, "features:" + feature + ",")) %>&page=<%= page %>">
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&features=<%= HTML.escape(operator_hash["features"] + ",#{feature}") %>">
|
||||
<%= translate(locale, feature) %>
|
||||
</a>
|
||||
<% else %>
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil! + " features:" + feature) %>&page=<%= page %>">
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&features=<%= feature %>">
|
||||
<%= translate(locale, feature) %>
|
||||
</a>
|
||||
<% end %>
|
||||
@ -85,7 +84,7 @@
|
||||
<% if operator_hash.fetch("sort", "relevance") == sort %>
|
||||
<b><%= translate(locale, sort) %></b>
|
||||
<% else %>
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?sort:[a-z]+/, "") + " sort:" + sort) %>&page=<%= page %>">
|
||||
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&sort=<%= sort %>">
|
||||
<%= translate(locale, sort) %>
|
||||
</a>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user