@@ -11,6 +11,7 @@ import {
1111 trackUploadProgress ,
1212 updateFileInformation ,
1313} from "WoltLabSuite/Core/Component/File/Helper" ;
14+ import { confirmationFactory } from "../Confirmation" ;
1415
1516export type FileProcessorData = {
1617 attachmentID : number ;
@@ -108,7 +109,9 @@ function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFile
108109 }
109110
110111 const listItem = document . createElement ( "li" ) ;
111- listItem . append ( getDeleteAttachButton ( fileId , ( data as FileProcessorData ) . attachmentID , editor , element ) ) ;
112+ listItem . append (
113+ getDeleteAttachButton ( fileId , ( data as FileProcessorData ) . attachmentID , editor , element , file . filename ) ,
114+ ) ;
112115 dropdownMenu . append ( listItem ) ;
113116
114117 const moreOptions = document . createElement ( "button" ) ;
@@ -137,21 +140,25 @@ function getDeleteAttachButton(
137140 attachmentId : number ,
138141 editor : HTMLElement ,
139142 element : HTMLElement ,
143+ filename : string | undefined ,
140144) : HTMLButtonElement {
141145 const button = document . createElement ( "button" ) ;
142146 button . type = "button" ;
143147 button . textContent = getPhrase ( "wcf.global.button.delete" ) ;
144148
145- button . addEventListener ( "click" , ( ) => {
146- void deleteFile ( fileId ) . then ( ( result ) => {
147- result . unwrap ( ) ;
149+ button . addEventListener ( "click" , async ( ) => {
150+ const confirmationResult = await confirmationFactory ( ) . delete ( filename ) ;
151+ if ( ! confirmationResult ) {
152+ return ;
153+ }
148154
149- dispatchToCkeditor ( editor ) . removeAttachment ( {
150- attachmentId,
151- } ) ;
155+ ( await deleteFile ( fileId ) ) . unwrap ( ) ;
152156
153- element . remove ( ) ;
157+ dispatchToCkeditor ( editor ) . removeAttachment ( {
158+ attachmentId,
154159 } ) ;
160+
161+ element . remove ( ) ;
155162 } ) ;
156163
157164 return button ;
0 commit comments