mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
Add download in-page without page refresh
This commit is contained in:
parent
a8c080ffd5
commit
37ef79e6ef
2 changed files with 45 additions and 10 deletions
|
|
@ -6,6 +6,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
|||
alias Pinchflat.Utils.NumberUtils
|
||||
alias PinchflatWeb.CustomComponents.TextComponents
|
||||
|
||||
alias Pinchflat.Media
|
||||
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||
|
||||
@limit 5
|
||||
|
||||
def render(%{records: []} = assigns) do
|
||||
|
|
@ -29,7 +32,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
|||
<div class="max-w-full overflow-x-auto">
|
||||
<.table rows={@records} table_class="text-white">
|
||||
<:col :let={media_item} label="Title" class="max-w-xs">
|
||||
<section class="flex items-center space-x-1">
|
||||
<section class="flex items-center space-x-1 gap-2">
|
||||
<.tooltip
|
||||
:if={media_item.last_error}
|
||||
tooltip={media_item.last_error}
|
||||
|
|
@ -38,6 +41,17 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
|||
>
|
||||
<.icon name="hero-exclamation-circle-solid" class="text-red-500" />
|
||||
</.tooltip>
|
||||
|
||||
<.icon_button
|
||||
icon_name="hero-arrow-down-tray"
|
||||
class="h-10 w-10"
|
||||
phx-click="force_download"
|
||||
phx-value-source-id={media_item.source_id}
|
||||
phx-value-media-id={media_item.id}
|
||||
data-confirm="Are you sure you force a download of this media?"
|
||||
:if={media_item.media_downloaded_at === nil}
|
||||
/>
|
||||
|
||||
<span class="truncate">
|
||||
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item.id}"}>
|
||||
{media_item.title}
|
||||
|
|
@ -90,6 +104,15 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
|||
{:noreply, assign(socket, new_assigns)}
|
||||
end
|
||||
|
||||
def handle_event("force_download", %{ "source-id" => source_id, "media-id" => media_id }, socket) do
|
||||
IO.puts("source_id: #{source_id}, media_id: #{media_id}")
|
||||
|
||||
media_item = Media.get_media_item!(media_id)
|
||||
MediaDownloadWorker.kickoff_with_task(media_item, %{force: true})
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp fetch_pagination_attributes(base_query, page) do
|
||||
total_record_count = Repo.aggregate(base_query, :count, :id)
|
||||
total_pages = max(ceil(total_record_count / @limit), 1)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
|||
alias Pinchflat.Sources
|
||||
alias Pinchflat.Utils.NumberUtils
|
||||
|
||||
alias Pinchflat.Media
|
||||
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||
|
||||
@limit 10
|
||||
|
||||
def render(%{total_record_count: 0} = assigns) do
|
||||
|
|
@ -47,7 +50,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
|||
</header>
|
||||
<.table rows={@records} table_class="text-white">
|
||||
<:col :let={media_item} label="Title" class="max-w-xs">
|
||||
<section class="flex items-center space-x-1">
|
||||
<section class="flex items-center space-x-1 gap-2">
|
||||
<.tooltip
|
||||
:if={media_item.last_error}
|
||||
tooltip={media_item.last_error}
|
||||
|
|
@ -57,15 +60,15 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
|||
<.icon name="hero-exclamation-circle-solid" class="text-red-500" />
|
||||
</.tooltip>
|
||||
|
||||
<.link
|
||||
href={~p"/sources/#{@source.id}/media/#{media_item.id}/force_download"}
|
||||
:if={@media_state !== "downloaded"}
|
||||
method="post"
|
||||
target="_blank"
|
||||
<.icon_button
|
||||
icon_name="hero-arrow-down-tray"
|
||||
class="h-10 w-10"
|
||||
phx-click="force_download"
|
||||
phx-value-source-id={@source.id}
|
||||
phx-value-media-id={media_item.id}
|
||||
data-confirm="Are you sure you force a download of this media?"
|
||||
>
|
||||
<.icon name="hero-arrow-down-tray" />
|
||||
</.link>
|
||||
:if={@media_state !== "downloaded"}
|
||||
/>
|
||||
|
||||
<span class="truncate">
|
||||
<.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}>
|
||||
|
|
@ -128,6 +131,15 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
|||
{:noreply, assign(socket, new_assigns)}
|
||||
end
|
||||
|
||||
def handle_event("force_download", %{ "source-id" => source_id, "media-id" => media_id }, socket) do
|
||||
IO.puts("source_id: #{source_id}, media_id: #{media_id}")
|
||||
|
||||
media_item = Media.get_media_item!(media_id)
|
||||
MediaDownloadWorker.kickoff_with_task(media_item, %{force: true})
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
# This, along with the handle_info below, is a pattern to reload _all_
|
||||
# tables on page rather than just the one that triggered the reload.
|
||||
def handle_event("reload_page", _params, socket) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue