Skip to content

Commit

Permalink
fix: fix minutes remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Mar 2, 2022
1 parent 5d4c0aa commit 94cdace
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib/media_server_web/helpers.ex
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions lib/media_server_web/live/home_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/media_server_web/live/watches_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 94cdace

Please sign in to comment.