Skip to content

Commit 82a0430

Browse files
authored
fix: convert share link input into textarea (#52)
1 parent 6a56225 commit 82a0430

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

sdk-playground/packages/client/src/App.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,12 @@ function RootedApp(): React.ReactElement {
252252
const navigate = useNavigate();
253253

254254
React.useEffect(() => {
255-
if (navigateOnInit && discordSdk.customId === 'PAGE_GET_SKUS') {
256-
navigate('/get-skus');
255+
if (navigateOnInit === false || typeof discordSdk.customId !== 'string') {
256+
return;
257+
}
258+
259+
if (routes.hasOwnProperty(discordSdk.customId) && 'path' in routes[discordSdk.customId]) {
260+
navigate(routes[discordSdk.customId].path);
257261
navigateOnInit = false;
258262
}
259263
}, [navigate]);

sdk-playground/packages/client/src/pages/ShareLink.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
2+
import {useLocation} from 'react-router-dom';
23
import discordSdk from '../discordSdk';
4+
import {EventPayloadData} from '@discord/embedded-app-sdk';
35

46
export default function ShareLink() {
57
const [message, setMessage] = React.useState<string>('Come Play SDK Playground!');
@@ -9,7 +11,7 @@ export default function ShareLink() {
911
const [hasPressedSend, setHasPressedSend] = React.useState<boolean>(false);
1012
const [didSend, setDidSend] = React.useState<boolean>(false);
1113

12-
const handleMessageChange= (event: React.ChangeEvent<HTMLInputElement>) => {
14+
const handleMessageChange= (event: React.ChangeEvent<HTMLTextAreaElement>) => {
1315
setMessage(event.target.value);
1416
};
1517
const handleCustomIdChange = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -19,6 +21,21 @@ export default function ShareLink() {
1921
setReferrerId(event.target.value);
2022
};
2123

24+
const location = useLocation();
25+
26+
React.useEffect(() => {
27+
const {channelId} = discordSdk;
28+
if (!channelId) return;
29+
30+
const handleCurrentUserUpdate = (currentUserEvent: EventPayloadData<'CURRENT_USER_UPDATE'>) => {
31+
setReferrerId(currentUserEvent.id);
32+
};
33+
discordSdk.subscribe('CURRENT_USER_UPDATE', handleCurrentUserUpdate);
34+
return () => {
35+
discordSdk.unsubscribe('CURRENT_USER_UPDATE', handleCurrentUserUpdate);
36+
};
37+
}, [location.search]);
38+
2239
const doShareLink = async () => {
2340
const { success} = await discordSdk.commands.shareLink({
2441
message,
@@ -32,8 +49,7 @@ export default function ShareLink() {
3249
return (
3350
<div style={{padding: 32}}>
3451
<p> Message: </p>
35-
<input
36-
type="text"
52+
<textarea
3753
value={message}
3854
onChange={handleMessageChange}
3955
placeholder="Type a message to include with the link"

0 commit comments

Comments
 (0)