diff --git a/lib/algora/accounts/user.ex b/lib/algora/accounts/user.ex index b0d4c30..fe07e8a 100644 --- a/lib/algora/accounts/user.ex +++ b/lib/algora/accounts/user.ex @@ -18,6 +18,7 @@ defmodule Algora.Accounts.User do field :visibility, Ecto.Enum, values: [public: 1, unlisted: 2] field :bounties_count, :integer field :solving_challenge, :boolean, default: false + field :featured, :boolean, default: false embeds_many :tech, Tech do field :name, :string diff --git a/lib/algora/library.ex b/lib/algora/library.ex index 64e86b8..12d7c01 100644 --- a/lib/algora/library.ex +++ b/lib/algora/library.ex @@ -611,7 +611,7 @@ defmodule Algora.Library do } ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end @@ -627,7 +627,7 @@ defmodule Algora.Library do } ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end @@ -644,7 +644,7 @@ defmodule Algora.Library do } ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end @@ -686,7 +686,7 @@ defmodule Algora.Library do where: v.show_id in ^ids ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end @@ -706,7 +706,7 @@ defmodule Algora.Library do } ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end @@ -726,7 +726,7 @@ defmodule Algora.Library do v.user_id == ^channel.user_id ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end @@ -747,16 +747,35 @@ defmodule Algora.Library do v.user_id == ^channel.user_id ) |> Video.not_deleted() - |> order_by_inserted(:desc) + |> order_by_live() |> Repo.all() end - def list_active_channels(opts) do + def list_live_channels(opts) do from(u in Algora.Accounts.User, where: u.is_live and u.visibility == :public, limit: ^Keyword.fetch!(opts, :limit), - order_by: [desc: u.updated_at], - select: struct(u, [:id, :handle, :channel_tagline, :avatar_url, :external_homepage_url]) + order_by: [desc: u.updated_at] + ) + |> Repo.all() + |> Enum.map(&get_channel!/1) + end + + def list_active_channels(opts) do + limit = Keyword.fetch!(opts, :limit) + + from(u in Algora.Accounts.User, + left_join: + v in subquery( + from v in Algora.Library.Video, + where: is_nil(v.deleted_at), + group_by: v.user_id, + select: %{user_id: v.user_id, last_video_at: max(v.inserted_at)} + ), + on: u.id == v.user_id, + where: u.visibility == :public and (u.featured == true or u.is_live == true), + order_by: [desc: u.is_live, desc: v.last_video_at, desc: u.id], + limit: ^limit ) |> Repo.all() |> Enum.map(&get_channel!/1) @@ -816,8 +835,8 @@ defmodule Algora.Library do |> Repo.update() end - defp order_by_inserted(%Ecto.Query{} = query, direction) when direction in [:asc, :desc] do - from(s in query, order_by: [{^direction, s.inserted_at}]) + defp order_by_live(%Ecto.Query{} = query) do + from(s in query, order_by: [desc: s.is_live, desc: s.inserted_at, desc: s.id]) end defp topic(user_id) when is_integer(user_id), do: "channel:#{user_id}" diff --git a/lib/algora_web/components/core_components.ex b/lib/algora_web/components/core_components.ex index a5eefb8..84849ff 100644 --- a/lib/algora_web/components/core_components.ex +++ b/lib/algora_web/components/core_components.ex @@ -136,7 +136,7 @@ defmodule AlgoraWeb.CoreComponents do <%!-- HACK: should use navigate instead of href here --%> <%!-- but it breaks navigating from youtube video to another video --%> <.link class="cursor-pointer truncate" href={~p"/#{@video.channel_handle}/#{@video.id}"}> - <.short_thumbnail video={@video} class="rounded-2xl" /> + <.short_thumbnail video={@video} class="rounded-lg" />
<%= @video.title %>
<%= @video.channel_name %>
<%= Timex.from_now(@video.inserted_at) %>
@@ -151,7 +151,7 @@ defmodule AlgoraWeb.CoreComponents do <%!-- HACK: should use navigate instead of href here --%> <%!-- but it breaks navigating from youtube video to another video --%> <.link class="cursor-pointer truncate" href={~p"/#{@video.channel_handle}/#{@video.id}"}> - <.video_thumbnail video={@video} class="rounded-2xl" /> + <.video_thumbnail video={@video} class="rounded-lg" />
<%= @video.title %>
<%= @video.channel_name %>
<%= Timex.from_now(@video.inserted_at) %>
diff --git a/lib/algora_web/components/layouts/live.html.heex b/lib/algora_web/components/layouts/live.html.heex index ba7f2b4..c2a9856 100644 --- a/lib/algora_web/components/layouts/live.html.heex +++ b/lib/algora_web/components/layouts/live.html.heex @@ -41,7 +41,7 @@
- <.logo /> + <.logo class="w-16 h-auto hidden sm:flex" />