improve backup button responsiveness and disable handling
All checks were successful
deploy / deploy (push) Successful in 3m35s
All checks were successful
deploy / deploy (push) Successful in 3m35s
Use async message passing for create_backup to update UI immediately. Add phx-throttle and pointer-events:none to fully prevent double-clicks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4ee097596b
commit
0b86cd66ce
@ -187,7 +187,7 @@
|
|||||||
color: var(--t-text-inverse);
|
color: var(--t-text-inverse);
|
||||||
|
|
||||||
&:hover { opacity: 0.85; }
|
&:hover { opacity: 0.85; }
|
||||||
&:disabled { opacity: 0.5; cursor: not-allowed; }
|
&:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin-btn-primary {
|
.admin-btn-primary {
|
||||||
|
|||||||
@ -40,25 +40,11 @@ defmodule BerrypodWeb.Admin.Backup do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("create_backup", _params, socket) do
|
def handle_event("create_backup", _params, socket) do
|
||||||
# Ignore if already creating
|
|
||||||
if socket.assigns.create_backup_status == :saving do
|
if socket.assigns.create_backup_status == :saving do
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
else
|
else
|
||||||
socket = assign(socket, :create_backup_status, :saving)
|
send(self(), :do_create_backup)
|
||||||
|
{:noreply, assign(socket, :create_backup_status, :saving)}
|
||||||
case Backup.create_backup() do
|
|
||||||
{:ok, _path} ->
|
|
||||||
{:noreply,
|
|
||||||
socket
|
|
||||||
|> assign(:backups, Backup.list_backups())
|
|
||||||
|> assign(:create_backup_status, :saved)}
|
|
||||||
|
|
||||||
{:error, error} ->
|
|
||||||
{:noreply,
|
|
||||||
socket
|
|
||||||
|> assign(:create_backup_status, :error)
|
|
||||||
|> put_flash(:error, "Failed to create backup: #{inspect(error)}")}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -186,6 +172,22 @@ defmodule BerrypodWeb.Admin.Backup do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
def handle_info(:do_create_backup, socket) do
|
||||||
|
case Backup.create_backup() do
|
||||||
|
{:ok, _path} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(:backups, Backup.list_backups())
|
||||||
|
|> assign(:create_backup_status, :saved)}
|
||||||
|
|
||||||
|
{:error, error} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(:create_backup_status, :error)
|
||||||
|
|> put_flash(:error, "Failed to create backup: #{inspect(error)}")}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_info(:do_restore, socket) do
|
def handle_info(:do_restore, socket) do
|
||||||
backup_path = socket.assigns.uploaded_backup.path
|
backup_path = socket.assigns.uploaded_backup.path
|
||||||
|
|
||||||
@ -329,6 +331,7 @@ defmodule BerrypodWeb.Admin.Backup do
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
phx-click="create_backup"
|
phx-click="create_backup"
|
||||||
|
phx-throttle="1000"
|
||||||
class="admin-btn admin-btn-primary admin-btn-sm"
|
class="admin-btn admin-btn-primary admin-btn-sm"
|
||||||
disabled={@create_backup_status == :saving}
|
disabled={@create_backup_status == :saving}
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user