49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
| import { defineStore } from 'pinia';
 | |
| import { v4 as uuidv4 } from 'uuid';
 | |
| 
 | |
| 
 | |
| interface Popup {
 | |
|     id: string;
 | |
|     title: string;
 | |
|     body: string;
 | |
|     icon: string|null;
 | |
|     confirmButton: string;
 | |
|     cancelButton: string;
 | |
|     resolve: (id: string) => void;
 | |
|     reject: (id: string) => void;
 | |
| }
 | |
| 
 | |
| export default defineStore('swal', {
 | |
|     state: () => ({
 | |
|         popups: [] as Popup[],
 | |
|     }),
 | |
|     actions: {
 | |
|         confirm(title: string, body: string): Promise<void> {
 | |
|             return new Promise((resolve, reject) =>  {
 | |
|                 new Promise<string>((resolve, reject) => {
 | |
|                     this.popups.push({
 | |
|                         title,
 | |
|                         body,
 | |
|                         confirmButton: 'Okay',
 | |
|                         cancelButton: 'Abbrechen',
 | |
|                         resolve,
 | |
|                         reject,
 | |
|                         id: uuidv4(),
 | |
|                         icon: 'warning-triangle-light',
 | |
|                     });
 | |
|                 }).then((id) => {
 | |
|                     this.remove(id);
 | |
|                     resolve();
 | |
|                 }).catch((id) => {
 | |
|                     this.remove(id);
 | |
|                     reject();
 | |
|                 });
 | |
|             });
 | |
|         },
 | |
| 
 | |
|         remove(id: string) {
 | |
|             this.popups = this.popups.filter(p => p.id !== id);
 | |
|         }
 | |
|     },
 | |
| });
 |