From f47a4b90c7161960b88f398fda148a79a7b88fc7 Mon Sep 17 00:00:00 2001 From: jamey Date: Fri, 13 Mar 2026 13:37:47 +0000 Subject: [PATCH] prevent double-click on create backup button Co-Authored-By: Claude Opus 4.5 --- lib/berrypod_web/live/admin/backup.ex | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/berrypod_web/live/admin/backup.ex b/lib/berrypod_web/live/admin/backup.ex index c84d071..55b97f4 100644 --- a/lib/berrypod_web/live/admin/backup.ex +++ b/lib/berrypod_web/live/admin/backup.ex @@ -40,18 +40,25 @@ defmodule BerrypodWeb.Admin.Backup do end def handle_event("create_backup", _params, socket) do - case Backup.create_backup() do - {:ok, _path} -> - {:noreply, - socket - |> assign(:backups, Backup.list_backups()) - |> assign(:create_backup_status, :saved)} + # Ignore if already creating + if socket.assigns.create_backup_status == :saving do + {:noreply, socket} + else + socket = assign(socket, :create_backup_status, :saving) - {:error, error} -> - {:noreply, - socket - |> assign(:create_backup_status, :error) - |> put_flash(:error, "Failed to create backup: #{inspect(error)}")} + 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 @@ -323,6 +330,7 @@ defmodule BerrypodWeb.Admin.Backup do type="button" phx-click="create_backup" class="admin-btn admin-btn-primary admin-btn-sm" + disabled={@create_backup_status == :saving} > <.icon name="hero-plus-mini" class="size-4" /> Create backup