mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
implementing snapshots
This commit is contained in:
34
dashboard/composables/useAlert.ts
Normal file
34
dashboard/composables/useAlert.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
export type Alert = {
|
||||
title: string,
|
||||
text: string,
|
||||
icon: string,
|
||||
ms: number,
|
||||
id: number
|
||||
}
|
||||
|
||||
const alerts = ref<Alert[]>([]);
|
||||
|
||||
const idPool = {
|
||||
id: 0,
|
||||
getId() {
|
||||
return idPool.id++;
|
||||
}
|
||||
}
|
||||
|
||||
function createAlert(title: string, text: string, icon: string, ms: number) {
|
||||
const alert: Alert = { title, text, icon, ms, id: idPool.getId() }
|
||||
alerts.value.push(alert);
|
||||
setTimeout(() => {
|
||||
closeAlert(alert.id);
|
||||
}, ms)
|
||||
}
|
||||
|
||||
function closeAlert(id: number) {
|
||||
alerts.value = alerts.value.filter(e => e.id != id);
|
||||
}
|
||||
|
||||
export function useAlert() {
|
||||
return { alerts, createAlert, closeAlert }
|
||||
}
|
||||
Reference in New Issue
Block a user