Add ability to remove search filters from UI

This commit is contained in:
syeopite 2021-04-10 01:16:40 -07:00
parent 3a52a1cf4d
commit 9e2438c7dc
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
2 changed files with 124 additions and 73 deletions

View file

@ -21,3 +21,29 @@
content: "[ - ]";
font-size: 1.5em;
}
.remove-filter {
margin-left: 6px;
vertical-align: middle;
}
/* No theme */
.no-theme .remove-filter {
color: #ffffff
}
/* Light theme */
@media (prefers-color-scheme: light) {
.light-theme .remove-filter {
color: #ffffff
}
}
/* Dark theme */
.no-theme .remove-filter {
color: #030303
}

View file

@ -19,7 +19,7 @@
<!-- Grabs all search filters. This is to make sure we don't accidently overwrite something within the
search query later on-->
<% filter_params = env.request.query_params.to_s.gsub(/q=.+?(?=&)/, "") %>
<% filter_params = env.request.query_params.to_s.gsub(/q=.+?(?=&|$)/, "") %>
<% base_url = "/search?q=#{HTML.escape(query.not_nil!)}" %>
<div class="pure-u-1-3 pure-u-md-1-5" id="filter-date">
@ -28,7 +28,10 @@
<% ["hour", "today", "week", "month", "year"].each do |date| %>
<div class="pure-u-1 pure-md-1-5">
<% if operator_hash.fetch("date", "all") == date %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&date=[a-z]+/, "")}"%>">
<b><%= translate(locale, date) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% else %>
<a href="<%= base_url + "#{filter_params.gsub(/&date=[a-z]+/, "")}&date=#{date}"%>">
<%= translate(locale, date) %>
@ -44,7 +47,10 @@
<% ["video", "channel", "playlist", "movie", "show"].each do |content_type| %>
<div class="pure-u-1 pure-md-1-5">
<% if operator_hash.fetch("content_type", "all") == content_type %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&content_type=[a-z]+/, "")}"%>">
<b><%= translate(locale, content_type) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% else %>
<a href="<%= base_url + "#{filter_params.gsub(/&content_type=[a-z]+/, "")}&content_type=#{content_type}"%>">
<%= translate(locale, content_type) %>
@ -60,7 +66,10 @@
<% ["short", "long"].each do |duration| %>
<div class="pure-u-1 pure-md-1-5">
<% if operator_hash.fetch("duration", "all") == duration %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&duration=[a-z]+/, "")}"%>">
<b><%= translate(locale, duration) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% else %>
<a href="<%= base_url + "#{filter_params.gsub(/&duration=[a-z]+/, "")}&duration=#{duration}"%>">
<%= translate(locale, duration) %>
@ -76,7 +85,21 @@
<% ["hd", "subtitles", "creative_commons", "3d", "live", "purchased", "4k", "360", "location", "hdr"].each do |feature| %>
<div class="pure-u-1 pure-md-1-5">
<% if operator_hash.fetch("features", "all").includes?(feature) %>
<% if operator_hash["features"].split(",").size == 1 %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&features=[a-z]+/, "")}"%>">
<b><%= translate(locale, feature) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% else %>
<% data = filter_params.match(/.*features=.*(#{feature}(%2C|&|$)).*/).not_nil! %>
<% start = data.begin(1) %>
<% last = data.end(1) %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params[0...start] + filter_params[last..-1]}"%>">
<b><%= translate(locale, feature) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% end %>
<% elsif operator_hash.has_key?("features") %>
<a href="<%= base_url + filter_params.gsub(/features=/, "features=#{feature},")%>">
<%= translate(locale, feature) %>
@ -96,7 +119,10 @@
<% ["relevance", "rating", "date", "views"].each do |sort| %>
<div class="pure-u-1 pure-md-1-5">
<% if operator_hash.fetch("sort", "relevance") == sort %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&sort=[a-z]+/, "")}"%>">
<b><%= translate(locale, sort) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% else %>
<a href="<%= base_url + "#{filter_params.gsub(/&sort=[a-z]+/, "")}&sort=#{sort}"%>">
<%= translate(locale, sort) %>
@ -105,7 +131,6 @@
</div>
<% end %>
</div>
</div>
</details>
<% end %>