implementing snapshots

This commit is contained in:
Emily
2024-07-31 15:34:35 +02:00
parent 4bede171fa
commit 7cb10f5aa1
9 changed files with 196 additions and 31 deletions

View File

@@ -5,7 +5,9 @@ export type Alert = {
text: string,
icon: string,
ms: number,
id: number
id: number,
remaining: number,
transitionStyle: string
}
const alerts = ref<Alert[]>([]);
@@ -18,11 +20,18 @@ const idPool = {
}
function createAlert(title: string, text: string, icon: string, ms: number) {
const alert: Alert = { title, text, icon, ms, id: idPool.getId() }
const alert = reactive<Alert>({
title, text, icon, ms, id: idPool.getId(), remaining: ms,
transitionStyle: 'transition: all 250ms linear;'
});
alerts.value.push(alert);
setTimeout(() => {
closeAlert(alert.id);
}, ms)
const timeout = setInterval(() => {
alert.remaining -= 250;
if (alert.remaining <= 0) {
closeAlert(alert.id);
clearInterval(timeout);
}
}, 250)
}
function closeAlert(id: number) {