2023-06-21 22:28:24 +00:00
|
|
|
import { isBrowser } from "@utils/browser";
|
|
|
|
import { ThemeColor } from "@utils/types";
|
|
|
|
import Toastify from "toastify-js";
|
2023-06-22 00:54:35 +00:00
|
|
|
import { I18NextService } from "./services";
|
2023-06-21 22:28:24 +00:00
|
|
|
|
|
|
|
export function toast(text: string, background: ThemeColor = "success") {
|
|
|
|
if (isBrowser()) {
|
|
|
|
const backgroundColor = `var(--bs-${background})`;
|
|
|
|
Toastify({
|
|
|
|
text: text,
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
gravity: "bottom",
|
|
|
|
position: "left",
|
|
|
|
duration: 5000,
|
|
|
|
}).showToast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function pictrsDeleteToast(filename: string, deleteUrl: string) {
|
|
|
|
if (isBrowser()) {
|
2023-06-22 00:54:35 +00:00
|
|
|
const clickToDeleteText = I18NextService.i18n.t("click_to_delete_picture", {
|
2023-06-21 22:28:24 +00:00
|
|
|
filename,
|
|
|
|
});
|
2023-06-22 00:54:35 +00:00
|
|
|
const deletePictureText = I18NextService.i18n.t("picture_deleted", {
|
2023-06-21 22:28:24 +00:00
|
|
|
filename,
|
|
|
|
});
|
2023-06-22 00:54:35 +00:00
|
|
|
const failedDeletePictureText = I18NextService.i18n.t(
|
|
|
|
"failed_to_delete_picture",
|
|
|
|
{
|
|
|
|
filename,
|
|
|
|
}
|
|
|
|
);
|
2023-06-21 22:28:24 +00:00
|
|
|
|
|
|
|
const backgroundColor = `var(--bs-light)`;
|
|
|
|
|
|
|
|
const toast = Toastify({
|
|
|
|
text: clickToDeleteText,
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
gravity: "top",
|
|
|
|
position: "right",
|
|
|
|
duration: 10000,
|
|
|
|
onClick: () => {
|
|
|
|
if (toast) {
|
|
|
|
fetch(deleteUrl).then(res => {
|
|
|
|
toast.hideToast();
|
|
|
|
if (res.ok === true) {
|
|
|
|
alert(deletePictureText);
|
|
|
|
} else {
|
|
|
|
alert(failedDeletePictureText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
toast.showToast();
|
|
|
|
}
|
|
|
|
}
|