diff --git a/sdk-playground/packages/client/src/pages/OpenExternalLink.tsx b/sdk-playground/packages/client/src/pages/OpenExternalLink.tsx index 03d782a..61af08e 100644 --- a/sdk-playground/packages/client/src/pages/OpenExternalLink.tsx +++ b/sdk-playground/packages/client/src/pages/OpenExternalLink.tsx @@ -1,21 +1,52 @@ -import discordSdk from '../discordSdk'; +import * as React from "react"; +import discordSdk from "../discordSdk"; + +enum LinkStatus { + NOT_CLICKED = "NOT_CLICKED", + CLICKED = "CLICKED", + NOT_OPENED = "NOT_OPENED", + OPENED = "OPENED", +} // Note: we're still using the anchor tag, to ensure standard accessibility UX export default function OpenExternalLink() { + const [linkStatus, setLinkStatus] = React.useState(LinkStatus.NOT_CLICKED); + + async function handleLinkClicked( + e: React.MouseEvent + ) { + e.preventDefault(); + setLinkStatus(LinkStatus.CLICKED); + const { opened } = await discordSdk.commands.openExternalLink({ + url: "https://google.com", + }); + if (opened) { + setLinkStatus(LinkStatus.OPENED); + } else { + setLinkStatus(LinkStatus.NOT_OPENED); + } + } + return ( -
+

Open external link

- Click here to go to google:{' '} - { - e.preventDefault(); - discordSdk.commands.openExternalLink({url: 'https://google.com'}); - }}> + Click here to go to google:{" "} + Google!

+
Link Status: {linkStatus}
+
); }