Skip to content

Commit

Permalink
refactor: refactor play buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Mar 1, 2022
1 parent b749707 commit 45f30dc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 17 deletions.
5 changes: 0 additions & 5 deletions lib/media_server_web/live/movies_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@ defmodule MediaServerWeb.MoviesLive.Show do
|> assign(:movie, movie)
}
end

@impl true
def handle_event("play", %{"movie" => id}, socket) do
{:noreply, push_redirect(socket, to: Routes.watch_movie_show_path(socket, :show, id))}
end
end
5 changes: 2 additions & 3 deletions lib/media_server_web/live/movies_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
<p><%= @movie["year"] %> - <%= @movie["runtime"] %> minutes</p>
</div>
<div class="mt-4 flex md:mt-0 md:ml-4">
<button phx-click="play" phx-value-movie={@movie["id"]} type="button" class="ml-3 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-slate-600 hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500">
Play
</button>

<%= live_redirect "Play", id: "play-#{ @movie["id"] }", to: Routes.watch_movie_show_path(@socket, :show, @movie["id"]), class: "ml-3 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-slate-600 hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500" %>
</div>
</div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions lib/media_server_web/live/series_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ defmodule MediaServerWeb.SeriesLive.Show do
|> assign(:episodes, Episodes.get_all(id))
}
end

@impl true
def handle_event("play", %{"episode" => id}, socket) do
{:noreply, push_redirect(socket, to: Routes.watch_episode_show_path(socket, :show, id))}
end
end
5 changes: 2 additions & 3 deletions lib/media_server_web/live/series_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@
<p class="mt-2">
<%= item["overview"] %>
</p>
<button id={"play-#{ item["id"] }"} phx-click="play" phx-value-episode={item["id"]} type="button" class="mt-4 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-slate-600 hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500">
Play
</button>

<%= live_redirect "Play", id: "play-#{ item["id"] }", to: Routes.watch_episode_show_path(@socket, :show, item["id"]), class: "mt-4 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-slate-600 hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500" %>
</div>
</div>
</li>
Expand Down
2 changes: 1 addition & 1 deletion test/media_server_web/live/movies_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ defmodule MediaServerWeb.MoviesLiveTest do

{:ok, show_live, _html} = live(conn, Routes.movies_show_path(conn, :show, movie["id"]))

assert show_live |> element("button", "Play") |> render_click()
assert show_live |> element("#play-#{ movie["id"] }", "Play") |> render_click()
end
end

0 comments on commit 45f30dc

Please sign in to comment.