From 47bd7812a55534e3443b4ec8ff62946518159636 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 --- src/invidious/routes/search.cr | 9 ++ .../views/components/channel-information.ecr | 8 +- .../views/components/search-filters.ecr | 130 ++++++++++++++++ src/invidious/views/search.ecr | 145 ++---------------- 4 files changed, 163 insertions(+), 129 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 d98c8926..176b6288 100644 --- a/src/invidious/routes/search.cr +++ b/src/invidious/routes/search.cr @@ -57,6 +57,15 @@ class Invidious::Routes::Search < Invidious::Routes::BaseRoute return error_template(500, ex) end + 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" end diff --git a/src/invidious/views/components/channel-information.ecr b/src/invidious/views/components/channel-information.ecr index c8653ed9..d47f13b3 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 %> +
@@ -170,8 +175,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 896ceda6..b52df7d4 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -1,6 +1,18 @@ +<% 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 %> <% if count == 0 %> @@ -8,138 +20,15 @@ "><%= 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=#{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 %> -
-
-
-
+ <% if is_channel_search %> + <% else %> + <%= rendered "components/search-filters" %> + <% end %> <% end %> <% if count == 0 %>
+<% elsif is_channel_search %> <% else %>
<% end %>