mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-01 18:19:55 +00:00
043b522ff1
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update src/shared/utils/app/convert-comment-sort-type.ts Co-authored-by: SleeplessOne1917 <abias1122@gmail.com> * prettier pass --------- Co-authored-by: SleeplessOne1917 <abias1122@gmail.com>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { isBrowser } from "@utils/browser";
|
|
import { ThemeColor } from "@utils/types";
|
|
import Toastify from "toastify-js";
|
|
import { i18n } from "./i18next";
|
|
|
|
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()) {
|
|
const clickToDeleteText = i18n.t("click_to_delete_picture", { filename });
|
|
const deletePictureText = i18n.t("picture_deleted", {
|
|
filename,
|
|
});
|
|
const failedDeletePictureText = i18n.t("failed_to_delete_picture", {
|
|
filename,
|
|
});
|
|
|
|
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();
|
|
}
|
|
}
|