From 6ce99cc791961c29545a97ecef0b0aabe76291de 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 --- .../views/components/search-filters.ecr | 130 ------------------ .../search-filters/filter-column.ecr | 36 +++++ .../search-filters/search-filters.ecr | 76 ++++++++++ src/invidious/views/search.ecr | 2 +- 4 files changed, 113 insertions(+), 131 deletions(-) delete mode 100644 src/invidious/views/components/search-filters.ecr 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.ecr b/src/invidious/views/components/search-filters.ecr deleted file mode 100644 index c1c168a2..00000000 --- a/src/invidious/views/components/search-filters.ecr +++ /dev/null @@ -1,130 +0,0 @@ -<% operators = operators.not_nil! %> - -
- -

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

-
-
- - <% filter_params = env.request.query_params.to_s.gsub(/q=.+?(?=&|$)/, "") %> - <% base_url = "/search?q=#{HTML.escape(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 operators.fetch("sort", "relevance") == sort %> - <%= translate(locale, sort) %> - <% else %> - "> - <%= translate(locale, sort) %> - - <% end %> -
  • - <% end %> -
-
-
-
\ No newline at end of file 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..7b1048cc --- /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=#{HTML.escape(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 b52df7d4..2c3e60bb 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -22,7 +22,7 @@ <% else %> <% if is_channel_search %> <% else %> - <%= rendered "components/search-filters" %> + <%= rendered "components/search-filters/search-filters" %> <% end %> <% end %>