From 2719aa1d7f6fd61ed1aaeb093d989ed762476e49 Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 25 Jun 2021 16:56:05 -0700 Subject: [PATCH] Add channel heading design to channel search (cherry picked from commit 6a12db1fb51f0fc6e560cbb6f2e2867d508f83f9) --- src/invidious/routes/search.cr | 8 ++ .../views/components/channel-information.ecr | 8 +- .../views/components/search-filters.ecr | 130 ++++++++++++++++++ src/invidious/views/search.ecr | 15 +- 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 src/invidious/views/components/search-filters.ecr diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr index 8ee486c0..e7e6003f 100644 --- a/src/invidious/routes/search.cr +++ b/src/invidious/routes/search.cr @@ -67,6 +67,14 @@ module Invidious::Routes::Search # end operator_hash = operators + if operators.fetch("channel", false) && count > 0 + channel = get_about_info(operators.fetch("channel", "Placeholder. This will never get reached!"), locale).not_nil! + if user + user = user.as(User) + subscriptions = user.subscriptions + end + subscriptions ||= [] of String + end env.set "search", query templated "search" diff --git a/src/invidious/views/components/channel-information.ecr b/src/invidious/views/components/channel-information.ecr index 379fbfdc..4685de12 100644 --- a/src/invidious/views/components/channel-information.ecr +++ b/src/invidious/views/components/channel-information.ecr @@ -27,6 +27,11 @@ <% end %> +<% if content_type != 7 %> + <% query = nil %> + <% operators = {} of String => String %> +<% end %> +
@@ -142,8 +147,9 @@
-
<% if content_type == 1 || content_type == 2 %> + <% # We really only need a single
(handled below) outside of content_type 1 or 2 %> +
<% route = content_type == 1 ? "/videos" : "/playlists" %> <% url = "/channel/#{channel.ucid + route}" %> diff --git a/src/invidious/views/components/search-filters.ecr b/src/invidious/views/components/search-filters.ecr new file mode 100644 index 00000000..c1c168a2 --- /dev/null +++ b/src/invidious/views/components/search-filters.ecr @@ -0,0 +1,130 @@ +<% 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/search.ecr b/src/invidious/views/search.ecr index bade46e6..d08395e9 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -1,11 +1,19 @@ -<% - # Satify compiler -%> <% filter_params = nil %> +<% is_channel_search = operators.fetch("channel", false) && channel.is_a? AboutChannel && !subscriptions.nil?%> <% content_for "header" do %> <%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious +<% if is_channel_search %> + +<% end %> +<% end %> + +<% # To satisfy the compiler we're going to need to repeat these two arguments %> +<% if is_channel_search && channel.is_a? AboutChannel && !subscriptions.nil? %> + <% content_type = 7 %> + <% sort_options = Tuple.new %> + <%= rendered "components/channel-information" %> <% end %> <% search_query_encoded = env.get?("search").try { |x| URI.encode_www_form(x.as(String), space_to_plus: true) } %> @@ -25,6 +33,7 @@ <% if count == 0 %>
+<% elsif is_channel_search %> <% else %>
<% end %>