improve backup button responsiveness and disable handling
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:
jamey 2026-03-27 10:36:05 +00:00
parent 4ee097596b
commit 0b86cd66ce
2 changed files with 20 additions and 17 deletions

View File

@ -187,7 +187,7 @@
color: var(--t-text-inverse);
&:hover { opacity: 0.85; }
&:disabled { opacity: 0.5; cursor: not-allowed; }
&:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
}
.admin-btn-primary {

View File

@ -40,25 +40,11 @@ defmodule BerrypodWeb.Admin.Backup do
end
def handle_event("create_backup", _params, socket) do
# Ignore if already creating
if socket.assigns.create_backup_status == :saving do
{:noreply, socket}
else
socket = 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
send(self(), :do_create_backup)
{:noreply, assign(socket, :create_backup_status, :saving)}
end
end
@ -186,6 +172,22 @@ defmodule BerrypodWeb.Admin.Backup do
end
@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
backup_path = socket.assigns.uploaded_backup.path
@ -329,6 +331,7 @@ defmodule BerrypodWeb.Admin.Backup do
<button
type="button"
phx-click="create_backup"
phx-throttle="1000"
class="admin-btn admin-btn-primary admin-btn-sm"
disabled={@create_backup_status == :saving}
>