From ed3a3babdb9007bb694caa6b9be01dde43e94b4f Mon Sep 17 00:00:00 2001 From: Neil Richter Date: Mon, 15 Apr 2024 10:27:39 +0200 Subject: [PATCH] feat(useToast): allow updating an existing notification (#1668) --- src/runtime/composables/useToast.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/runtime/composables/useToast.ts b/src/runtime/composables/useToast.ts index b3a23259..1e7143da 100644 --- a/src/runtime/composables/useToast.ts +++ b/src/runtime/composables/useToast.ts @@ -22,8 +22,17 @@ export function useToast () { notifications.value = notifications.value.filter((n: Notification) => n.id !== id) } + function update (id: string, notification: Partial) { + const index = notifications.value.findIndex((n: Notification) => n.id === id) + if (index !== -1) { + const previous = notifications.value[index] + notifications.value.splice(index, 1, { ...previous, ...notification }) + } + } + return { add, - remove + remove, + update } }