| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  | 	import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte'; | 
					
						
							|  |  |  | 	import { | 
					
						
							|  |  |  | 		NotificationType, | 
					
						
							|  |  |  | 		notificationController | 
					
						
							|  |  |  | 	} from '$lib/components/shared-components/notification/notification'; | 
					
						
							|  |  |  | 	import { api } from '@api'; | 
					
						
							|  |  |  | 	import DeleteOutline from 'svelte-material-icons/DeleteOutline.svelte'; | 
					
						
							|  |  |  | 	import { OnAssetDelete, getAssetControlContext } from '../asset-select-control-bar.svelte'; | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 	import ConfirmDialogue from '$lib/components/shared-components/confirm-dialogue.svelte'; | 
					
						
							|  |  |  | 	import { handleError } from '../../../utils/handle-error'; | 
					
						
							| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	export let onAssetDelete: OnAssetDelete; | 
					
						
							|  |  |  | 	const { getAssets, clearSelect } = getAssetControlContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 	let confirm = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const handleDelete = async () => { | 
					
						
							| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | 		try { | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 			let count = 0; | 
					
						
							| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 			const { data: deletedAssets } = await api.assetApi.deleteAsset({ | 
					
						
							| 
									
										
										
										
											2023-05-28 04:52:22 +03:00
										 |  |  | 				deleteAssetDto: { | 
					
						
							|  |  |  | 					ids: Array.from(getAssets()).map((a) => a.id) | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (const asset of deletedAssets) { | 
					
						
							|  |  |  | 				if (asset.status === 'SUCCESS') { | 
					
						
							|  |  |  | 					onAssetDelete(asset.id); | 
					
						
							|  |  |  | 					count++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			notificationController.show({ message: `Deleted ${count}`, type: NotificationType.Info }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			clearSelect(); | 
					
						
							| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | 		} catch (e) { | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | 			handleError(e, 'Error deleting assets'); | 
					
						
							| 
									
										
										
										
											2023-05-16 16:13:20 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-26 09:11:10 -04:00
										 |  |  | <CircleIconButton title="Delete" logo={DeleteOutline} on:click={() => (confirm = true)} /> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {#if confirm} | 
					
						
							|  |  |  | 	<ConfirmDialogue | 
					
						
							|  |  |  | 		prompt="Are you sure you want to delete {getAssets() | 
					
						
							|  |  |  | 			.size} assets? This step also deletes assets in the album(s) to which they belong. You can not undo this action!" | 
					
						
							|  |  |  | 		title="Delete assets?" | 
					
						
							|  |  |  | 		confirmText="Delete" | 
					
						
							|  |  |  | 		on:confirm={handleDelete} | 
					
						
							|  |  |  | 		on:cancel={() => (confirm = false)} | 
					
						
							|  |  |  | 	/> | 
					
						
							|  |  |  | {/if} |