diff --git a/lib/media_server_web/helpers.ex b/lib/media_server_web/helpers.ex new file mode 100644 index 00000000..c5576299 --- /dev/null +++ b/lib/media_server_web/helpers.ex @@ -0,0 +1,10 @@ +defmodule MediaServerWeb.Helpers do + + def minutes_remaining_from_seconds(duration, current_time) do + ceil((duration - current_time) / 60) + end + + def percentage_complete_from_seconds(current_time, duration) do + (current_time / duration) * 100 + end +end diff --git a/lib/media_server_web/live/home_live/index.html.heex b/lib/media_server_web/live/home_live/index.html.heex index 5cd42e09..7e47b17a 100644 --- a/lib/media_server_web/live/home_live/index.html.heex +++ b/lib/media_server_web/live/home_live/index.html.heex @@ -49,8 +49,8 @@ id_item: item.id, image_url: item.image_url, title: item.title, - minutes_remaining: floor((item.duration - item.current_time) / 60), - percentage_complete: (item.current_time / item.duration) * 100, + minutes_remaining: MediaServerWeb.Helpers.minutes_remaining_from_seconds(item.duration, item.current_time), + percentage_complete: MediaServerWeb.Helpers.percentage_complete_from_seconds(item.current_time, item.duration), link: Routes.watch_movie_show_path(@socket, :show, item.movie_id, seconds: item.current_time), event: "delete_movie", return_to: Routes.home_index_path(@socket, :index) @@ -65,8 +65,8 @@ id_item: item.id, image_url: item.image_url, title: item.title, - minutes_remaining: floor((item.duration - item.current_time) / 60), - percentage_complete: (item.current_time / item.duration) * 100, + minutes_remaining: MediaServerWeb.Helpers.minutes_remaining_from_seconds(item.duration, item.current_time), + percentage_complete: MediaServerWeb.Helpers.percentage_complete_from_seconds(item.current_time, item.duration), link: Routes.watch_episode_show_path(@socket, :show, item.episode_id, seconds: item.current_time), event: "delete_episode", return_to: Routes.home_index_path(@socket, :index) diff --git a/lib/media_server_web/live/watches_live/index.html.heex b/lib/media_server_web/live/watches_live/index.html.heex index 3fa3a89b..4514a8c4 100644 --- a/lib/media_server_web/live/watches_live/index.html.heex +++ b/lib/media_server_web/live/watches_live/index.html.heex @@ -15,8 +15,8 @@ id_item: item.id, image_url: item.image_url, title: item.title, - minutes_remaining: floor((item.duration - item.current_time) / 60), - percentage_complete: (item.current_time / item.duration) * 100, + minutes_remaining: MediaServerWeb.Helpers.minutes_remaining_from_seconds(item.duration, item.current_time), + percentage_complete: MediaServerWeb.Helpers.percentage_complete_from_seconds(item.current_time, item.duration), link: Routes.watch_movie_show_path(@socket, :show, item.movie_id, seconds: item.current_time), event: "delete_movie", return_to: Routes.watches_index_path(@socket, :index) @@ -31,8 +31,8 @@ id_item: item.id, image_url: item.image_url, title: item.title, - minutes_remaining: floor((item.duration - item.current_time) / 60), - percentage_complete: (item.current_time / item.duration) * 100, + minutes_remaining: MediaServerWeb.Helpers.minutes_remaining_from_seconds(item.duration, item.current_time), + percentage_complete: MediaServerWeb.Helpers.percentage_complete_from_seconds(item.current_time, item.duration), link: Routes.watch_episode_show_path(@socket, :show, item.episode_id, seconds: item.current_time), event: "delete_episode", return_to: Routes.watches_index_path(@socket, :index)