From e62cba0317c89271b5c8922d371868d985b4801f Mon Sep 17 00:00:00 2001 From: Zafer Cesur <17045339+zcesur@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:40:26 +0300 Subject: [PATCH] add route `/:channel_handle/:video_id` (#9) --- assets/js/app.ts | 5 +- assets/js/user_socket.ts | 15 - lib/algora/library.ex | 6 +- lib/algora/library/video.ex | 1 + lib/algora_web/components/core_components.ex | 24 +- .../components/layouts/live.html.heex | 6 - lib/algora_web/live/player_live.ex | 16 +- lib/algora_web/live/side_panel_live.ex | 218 ------- lib/algora_web/live/subtitle_live/index.ex | 2 +- lib/algora_web/live/subtitle_live/show.ex | 2 +- lib/algora_web/live/video_live.ex | 556 ++++++++++++++++++ lib/algora_web/router.ex | 1 + 12 files changed, 579 insertions(+), 273 deletions(-) delete mode 100644 lib/algora_web/live/side_panel_live.ex create mode 100644 lib/algora_web/live/video_live.ex diff --git a/assets/js/app.ts b/assets/js/app.ts index 730f718..5ead5cd 100644 --- a/assets/js/app.ts +++ b/assets/js/app.ts @@ -149,7 +149,6 @@ const Hooks = { this.player.play(); this.player.el().parentElement.classList.remove("hidden"); this.player.el().parentElement.classList.add("flex"); - window.scrollTo(0, 0); if (backdrop) { backdrop.classList.remove("opacity-10"); @@ -157,9 +156,7 @@ const Hooks = { } }; - window.addEventListener("js:play_video", playVideo); - this.handleEvent("js:play_video", playVideo); - + this.handleEvent("play_video", playVideo); this.handleEvent("join_chat", Chat.join); }, }, diff --git a/assets/js/user_socket.ts b/assets/js/user_socket.ts index 9be0898..42e38f2 100644 --- a/assets/js/user_socket.ts +++ b/assets/js/user_socket.ts @@ -6,13 +6,6 @@ const init = () => { let socket = new Socket("/socket", { params: { token: window.userToken } }); socket.connect(); - const main = document.querySelector("body"); - const sidePanel = document.querySelector("#side-panel"); - - if (!main || !sidePanel) { - throw new Error("Could not initialize chat"); - } - let channel: Channel; let chatInput; let chatMessages; @@ -24,10 +17,6 @@ const init = () => { chatInput.value = ""; chatInput.removeEventListener("keypress", handleSend); } - sidePanel.classList.add("lg:w-0"); - sidePanel.classList.remove("lg:w-[24rem]"); - sidePanel.classList.remove("lg:flex"); - main.classList.remove("lg:mr-[24rem]"); }; const join = ({ id }) => { @@ -39,10 +28,6 @@ const init = () => { chatInput = document.querySelector("#chat-input"); chatMessages = document.querySelector("#chat-messages"); chatMessages.scrollTop = chatMessages.scrollHeight; - sidePanel.classList.add("lg:w-[24rem]"); - sidePanel.classList.add("lg:flex"); - sidePanel.classList.remove("lg:w-0"); - main.classList.add("lg:mr-[24rem]"); handleSend = (event) => { if (event.key === "Enter" && chatInput.value.trim()) { diff --git a/lib/algora/library.ex b/lib/algora/library.ex index fc0e42b..076db25 100644 --- a/lib/algora/library.ex +++ b/lib/algora/library.ex @@ -197,7 +197,7 @@ defmodule Algora.Library do v.visibility == :public and is_nil(v.vertical_thumbnail_url) and (v.is_live == true or v.duration >= 120 or v.type == :vod), - select_merge: %{channel_name: u.name} + select_merge: %{channel_handle: u.handle, channel_name: u.name} ) |> order_by_inserted(:desc) |> Repo.all() @@ -209,7 +209,7 @@ defmodule Algora.Library do on: v.user_id == u.id, limit: ^limit, where: v.visibility == :public and not is_nil(v.vertical_thumbnail_url), - select_merge: %{channel_name: u.name} + select_merge: %{channel_handle: u.handle, channel_name: u.name} ) |> order_by_inserted(:desc) |> Repo.all() @@ -220,7 +220,7 @@ defmodule Algora.Library do limit: ^limit, join: u in User, on: v.user_id == u.id, - select_merge: %{channel_name: u.name}, + select_merge: %{channel_handle: u.handle, channel_name: u.name}, where: v.user_id == ^channel.user_id ) |> order_by_inserted(:desc) diff --git a/lib/algora/library/video.ex b/lib/algora/library/video.ex index 647c3ff..ccace1b 100644 --- a/lib/algora/library/video.ex +++ b/lib/algora/library/video.ex @@ -17,6 +17,7 @@ defmodule Algora.Library.Video do field :url, :string field :url_root, :string field :uuid, :string + field :channel_handle, :string, virtual: true field :channel_name, :string, virtual: true field :visibility, Ecto.Enum, values: [public: 1, unlisted: 2] belongs_to :user, Accounts.User diff --git a/lib/algora_web/components/core_components.ex b/lib/algora_web/components/core_components.ex index 4117d60..450da70 100644 --- a/lib/algora_web/components/core_components.ex +++ b/lib/algora_web/components/core_components.ex @@ -75,16 +75,10 @@ defmodule AlgoraWeb.CoreComponents do def short_entry(assigns) do ~H""" -
JS.dispatch("js:play_video", - to: "#video-player", - detail: %{player: %{src: @video.url, type: Library.player_type(@video)}} - ) - } + navigate={~p"/#{@video.channel_handle}/#{@video.id}"} >
@@ -104,7 +98,7 @@ defmodule AlgoraWeb.CoreComponents do
<%= @video.title %>
<%= @video.channel_name %>
<%= Timex.from_now(@video.inserted_at) %>
-
+ """ end @@ -113,16 +107,10 @@ defmodule AlgoraWeb.CoreComponents do def video_entry(assigns) do ~H""" -
JS.dispatch("js:play_video", - to: "#video-player", - detail: %{player: %{src: @video.url, type: Library.player_type(@video)}} - ) - } + navigate={~p"/#{@video.channel_handle}/#{@video.id}"} >
@@ -149,7 +137,7 @@ defmodule AlgoraWeb.CoreComponents do
<%= @video.title %>
<%= @video.channel_name %>
<%= Timex.from_now(@video.inserted_at) %>
-
+ """ end diff --git a/lib/algora_web/components/layouts/live.html.heex b/lib/algora_web/components/layouts/live.html.heex index 53568f0..a52097d 100644 --- a/lib/algora_web/components/layouts/live.html.heex +++ b/lib/algora_web/components/layouts/live.html.heex @@ -126,12 +126,6 @@ <.live_component module={AlgoraWeb.LayoutComponent} id="layout" /> - <%= live_render(@socket, AlgoraWeb.SidePanelLive, - id: "video-side-panel", - session: %{}, - sticky: true - ) %> -
<%= live_render(@socket, AlgoraWeb.PlayerLive, id: "player", session: %{}, sticky: true) %> <%= @inner_content %> diff --git a/lib/algora_web/live/player_live.ex b/lib/algora_web/live/player_live.ex index 7a18b99..43b537d 100644 --- a/lib/algora_web/live/player_live.ex +++ b/lib/algora_web/live/player_live.ex @@ -5,13 +5,15 @@ defmodule AlgoraWeb.PlayerLive do def render(assigns) do ~H""" -