From 9a18699746c72ee6f55ef2bf7fc92b3bfac8507d Mon Sep 17 00:00:00 2001 From: syeopite Date: Sat, 26 Jun 2021 14:51:43 -0700 Subject: [PATCH] Split search filter columns into a component (cherry picked from commit 84732f29a5f258a4aca0b390dc55ed9aa35aeb7a) --- .../search-filters/filter-column.ecr | 36 +++++ .../search-filters/search-filters.ecr | 76 ++++++++++ src/invidious/views/search.ecr | 130 +----------------- 3 files changed, 113 insertions(+), 129 deletions(-) create mode 100644 src/invidious/views/components/search-filters/filter-column.ecr create mode 100644 src/invidious/views/components/search-filters/search-filters.ecr diff --git a/src/invidious/views/components/search-filters/filter-column.ecr b/src/invidious/views/components/search-filters/filter-column.ecr new file mode 100644 index 00000000..71a5015b --- /dev/null +++ b/src/invidious/views/components/search-filters/filter-column.ecr @@ -0,0 +1,36 @@ +<% + # Almost all of the filter columns are basically the same so we'll define it here as a component. + # Uses five values + # - filter_params: The URL params containing only the search filters. + # - base_url: The path to the /search endpoint of Invidious with the current search query passed inn + # - operators: containing all of the search filters currently applied + # - filters: the array of filters within the column we're creating + # - filter_name: name of the filter + # - selected_default: default selected filter +-%> + +
+ <%= translate(locale, filter_name) %> +
+ + + +
\ No newline at end of file diff --git a/src/invidious/views/components/search-filters/search-filters.ecr b/src/invidious/views/components/search-filters/search-filters.ecr new file mode 100644 index 00000000..b88a80d7 --- /dev/null +++ b/src/invidious/views/components/search-filters/search-filters.ecr @@ -0,0 +1,76 @@ +<% operators = operators.not_nil! %> + +
+ +

<%= translate(locale, "filter") %>

+
+ +
+ <% # 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=.+?(?=&|$)/, "") %> + <% base_url = "/search?q=#{URI.encode_www_form(query.not_nil!)}" -%> + + <% filters = ["hour", "today", "week", "month", "year"] %> + <% filter_name = "date" %> + <% selected_default = "NotNeeded" %> + <%= rendered "components/search-filters/filter-column" -%> + + <% filters = ["video", "channel", "playlist", "movie", "show"] %> + <% filter_name = "content_type" %> + <% selected_default = "NotNeeded" %> + <%= rendered "components/search-filters/filter-column" -%> + + <% filters = ["short", "long"] %> + <% filter_name = "duration" %> + <%= rendered "components/search-filters/filter-column" -%> + + <% + # Since the feature filter column is unqiue (multiple filters can be applied), + # we'll have to define it manually. + %> +
+ <%= translate(locale, "features") %> +
+ + +
+ + <% filters = ["relevance", "rating", "date", "views"] %> + <% filter_name = "sort" %> + <% selected_default = "relevance" %> + <%= rendered "components/search-filters/filter-column" -%> + +
+
\ No newline at end of file diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index cd6705cb..3d2bb691 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -11,135 +11,7 @@ "><%= translate(locale, "Broken? Try another Invidious Instance!") %> <% else %> -
- -

<%= translate(locale, "filter") %>

-
-
- - - <% filter_params = env.request.query_params.to_s.gsub(/q=.+?(?=&)/, "") %> - <% base_url = "/search?q=#{URI.encode_www_form(query.not_nil!)}" %> - -
- <%= translate(locale, "date") %> -
- -
- -
- <%= translate(locale, "content_type") %> -
- -
- -
- <%= translate(locale, "duration") %> -
- -
- -
- <%= translate(locale, "features") %> -
- -
- -
- <%= translate(locale, "sort") %> -
- <% ["relevance", "rating", "date", "views"].each do |sort| %> -
- <% if operator_hash.fetch("sort", "relevance") == sort %> - "> - <%= translate(locale, sort) %> - - - <% else %> - "> - <%= translate(locale, sort) %> - - <% end %> -
- <% end %> -
-
+ <%= rendered "components/search-filters/search-filters" %> <% end %> <% if count == 0 %>