diff --git a/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionCard.tsx b/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionCard.tsx index 6db7762..311531a 100644 --- a/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionCard.tsx +++ b/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionCard.tsx @@ -135,13 +135,15 @@ export function AwesomeArcadeExtensionCard({ setTooltip("Click to copy"); }} onClick={() => { - if (copyTextToClipboard(ext.url)) { - setTooltip("Copied!"); - } else { - setTooltip( - "Failed to copy - did you give us clipboard permission?", - ); - } + copyTextToClipboard(ext.url) + .then(() => { + setTooltip("Copied!"); + }) + .catch(() => { + setTooltip( + "Failed to copy - did you give us clipboard permission?", + ); + }); tippyRef.current?.show(); window.document.documentElement.dispatchEvent( new CustomEvent("clickrepo", { diff --git a/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionOldCard.tsx b/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionOldCard.tsx index dfcdceb..0b38d1b 100644 --- a/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionOldCard.tsx +++ b/src/components/AwesomeArcadeList/Extension/Cards/AwesomeArcadeExtensionOldCard.tsx @@ -109,13 +109,15 @@ export function AwesomeArcadeExtensionOldCard({ setTooltip("Click to copy"); }} onClick={() => { - if (copyTextToClipboard(ext.url)) { - setTooltip("Copied!"); - } else { - setTooltip( - "Failed to copy - did you give us clipboard permission?", - ); - } + copyTextToClipboard(ext.url) + .then(() => { + setTooltip("Copied!"); + }) + .catch(() => { + setTooltip( + "Failed to copy - did you give us clipboard permission?", + ); + }); tippyRef.current?.show(); window.document.documentElement.dispatchEvent( new CustomEvent("clickrepo", { diff --git a/src/components/BuiltInTools/ImageImporter/index.tsx b/src/components/BuiltInTools/ImageImporter/index.tsx new file mode 100644 index 0000000..f77833c --- /dev/null +++ b/src/components/BuiltInTools/ImageImporter/index.tsx @@ -0,0 +1,300 @@ +import React from "react"; +import AutoLink from "@/components/Linkable/AutoLink"; +import { + copyTextToClipboard, + readBlobsFromClipboard, +} from "@/scripts/Utils/Clipboard/clipboard"; +import { NotificationType, notify } from "@/components/Notifications"; +import getElement from "@/scripts/Utils/Element"; +import ImagePreview from "@/components/BuiltInTools/ImagePreview"; + +export type ImageImporterToolInput = { + width?: number | undefined; + height?: number | undefined; + palette?: boolean | undefined; + gif?: boolean | undefined; +}; + +export default function ImageImporterTool(): React.ReactNode { + const [inputBuf, setInputBuf] = React.useState(null); + + const [outputCode, setOutputCode] = React.useState(null); + const [outputBuf, setOutputBuf] = React.useState(null); + + return ( +
+
{ + e.preventDefault(); + }} + > +
+
+ +
+
+
+ { + setInputBuf(null); + // @ts-ignore + const firstFile = e.target.files.item(0); + if (firstFile) { + firstFile + .arrayBuffer() + .then((buf) => { + console.log( + `Selected file ${firstFile.name} with ${buf.byteLength} bytes`, + ); + setInputBuf(buf); + notify( + `Selected file ${firstFile.name}, size ${new Intl.NumberFormat().format(Math.round(buf.byteLength / 1024))} kb`, + NotificationType.Success, + ); + }) + .catch(() => { + console.log( + "Failed to get file, either cancelled or error", + ); + notify("Error selecting file", NotificationType.Error); + }); + } + }} + /> +
+
+ +
+
+
+
+ + Click the choose file button to open a file picker, drag an + image onto the choose file button above, or have an image copied + in your clipboard and press the read from clipboard button. + +
+ + Many common image formats are supported, such as PNG, JPEG, GIF, + BMP, and more. Check out{" "} + + this link + {" "} + to see all supported formats. + +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ + Width + + +
+
+
+
+
+
+ + Height + + +
+
+
+
+
+ + Leave both blank to use the input image{"'"}s original size. + Remember the maximum MakeCode Arcade image size is 512x512! + +
+
+
+
+
+ + +
+
+
+
+ +
+
+
+
+ +