From ac25f46bafca939f843480ed1b974f3d83d45f14 Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Thu, 16 Nov 2023 09:32:43 +0100 Subject: [PATCH] Cancel existing flash timer before setting a new one --- lib/plausible_web/live/sites.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex index 8855fc613..6afb50514 100644 --- a/lib/plausible_web/live/sites.ex +++ b/lib/plausible_web/live/sites.ex @@ -613,9 +613,13 @@ defmodule PlausibleWeb.Live.Sites do }) end - Process.send_after(self(), :clear_flash, 5000) + if flash_timer = socket.assigns[:flash_timer] do + Process.cancel_timer(flash_timer) + end - {:noreply, socket} + flash_timer = Process.send_after(self(), :clear_flash, 5000) + + {:noreply, assign(socket, :flash_timer, flash_timer)} else Sentry.capture_message("Attempting to toggle pin for invalid domain.", extra: %{domain: domain, user: socket.assigns.user.id}