Skip to content

Commit 0737d02

Browse files
Notification
1 parent cae9833 commit 0737d02

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/components/BuiltInTools/ImageImporter/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import AutoLink from "@/components/Linkable/AutoLink";
33
import {
44
copyTextToClipboard,
55
readBlobsFromClipboard,
6-
} from "@/scripts/Utils/Clipboard/clipboard";
7-
import { NotificationType, notify } from "@/components/Notifications";
6+
} from "@/scripts/Utils/Clipboard";
7+
import {
8+
loadingNotify,
9+
NotificationType,
10+
notify,
11+
} from "@/components/Notifications";
812
import getElement from "@/scripts/Utils/Element";
913
import ImagePreview from "@/components/BuiltInTools/ImagePreview";
1014
import PaletteEditor from "@/components/BuiltInTools/PaletteEditor";
1115
import { makeNaNUndefined } from "@/scripts/Utils/TypeHelp/NullUndefined";
16+
import { LoadingNotifyReturn } from "@/components/Notifications/notifications";
1217

1318
export type ImageImporterToolInput = {
1419
width?: number | undefined;
@@ -33,6 +38,7 @@ export default function ImageImporterTool(): React.ReactNode {
3338
const [outputBuf, setOutputBuf] = React.useState<ArrayBuffer | null>(null);
3439

3540
const [iframeReady, setIframeReady] = React.useState(false);
41+
const notifyCbs = React.useRef<LoadingNotifyReturn | null>();
3642

3743
const handleMessage = React.useCallback((e: MessageEvent) => {
3844
let data = e.data;
@@ -50,6 +56,7 @@ export default function ImageImporterTool(): React.ReactNode {
5056
setOutputCode(data.output_image_code);
5157
setOutputBuf(Buffer.from(data.output_preview_img, "base64"));
5258
setIframeReady(true);
59+
notifyCbs.current?.successCallback();
5360
} catch (e) {
5461
console.warn(e);
5562
}
@@ -78,6 +85,12 @@ export default function ImageImporterTool(): React.ReactNode {
7885
setIframeReady(false);
7986
setOutputCode(null);
8087
setOutputBuf(null);
88+
notifyCbs.current = loadingNotify(
89+
"Converting image...",
90+
"Conversion complete!",
91+
"Failed to convert!",
92+
"Canceled conversion.",
93+
);
8194
setTimeout(() => {
8295
iframe.contentWindow!.postMessage(
8396
JSON.stringify({
@@ -247,7 +260,6 @@ export default function ImageImporterTool(): React.ReactNode {
247260
aria-describedby="width-label"
248261
placeholder="Leave blank to auto-calculate from height and keep aspect ratio"
249262
onChange={(e) => {
250-
const v = e.target.value.trim();
251263
setOptions({
252264
...options,
253265
width: makeNaNUndefined(parseInt(e.target.value.trim())),
@@ -272,7 +284,6 @@ export default function ImageImporterTool(): React.ReactNode {
272284
aria-describedby="height-label"
273285
placeholder="Leave blank to auto-calculate from width and keep aspect ratio"
274286
onChange={(e) => {
275-
const v = e.target.value.trim();
276287
setOptions({
277288
...options,
278289
height: makeNaNUndefined(parseInt(e.target.value.trim())),

src/components/Notifications/notifications.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export function promiseNotify(
9393
);
9494
}
9595

96-
type LoadingNotifyReturn = {
96+
export type LoadingNotifyReturn = {
9797
successCallback: () => void;
9898
errorCallback: () => void;
99-
canceledCallback: () => void;
99+
cancelCallback: () => void;
100100
};
101101

102102
export function loadingNotify(
@@ -123,7 +123,7 @@ export function loadingNotify(
123123
autoClose: 5000,
124124
});
125125
},
126-
canceledCallback: () => {
126+
cancelCallback: () => {
127127
toast.update(id, {
128128
render: canceledText,
129129
type: "default",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export {
22
copyTextToClipboard,
33
readTextFromClipboard,
4-
copyBlobToClipboard,
4+
copyBlobsToClipboard,
5+
readBlobsFromClipboard,
56
} from "./clipboard";

0 commit comments

Comments
 (0)