feat(useToast): allow updating an existing notification (#1668)

This commit is contained in:
Neil Richter
2024-04-15 10:27:39 +02:00
committed by GitHub
parent 4415d4111e
commit ed3a3babdb

View File

@@ -22,8 +22,17 @@ export function useToast () {
notifications.value = notifications.value.filter((n: Notification) => n.id !== id)
}
function update (id: string, notification: Partial<Notification>) {
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
}
}