Avoid browser warning about leaving page, handle delete image fail.

This commit is contained in:
sam365724 2022-09-30 22:26:32 +02:00
parent 53e973c140
commit c08d4240e1
2 changed files with 12 additions and 3 deletions

View file

@ -369,6 +369,7 @@ export class MarkdownTextArea extends Component<
pictrsDeleteToast(
i18n.t("click_to_delete_picture"),
i18n.t("picture_deleted"),
i18n.t("fail_picture_deleted").concat('\n(', file.name,')'),
deleteUrl
);
} else {

View file

@ -543,6 +543,7 @@ export function toast(text: string, background = "success") {
export function pictrsDeleteToast(
clickToDeleteText: string,
deletePictureText: string,
failedDeletePictureText: string,
deleteUrl: string
) {
if (isBrowser()) {
@ -555,9 +556,16 @@ export function pictrsDeleteToast(
duration: 10000,
onClick: () => {
if (toast) {
window.location.replace(deleteUrl);
alert(deletePictureText);
fetch(deleteUrl, {})
.then( res => {
console.log(res)
toast.hideToast();
if (res.ok === true){
alert(deletePictureText);
} else{
alert(failedDeletePictureText);
}
})
}
},
close: true,