1
1
import React from 'react' ;
2
+ import { useLocation } from 'react-router-dom' ;
2
3
import discordSdk from '../discordSdk' ;
4
+ import { EventPayloadData } from '@discord/embedded-app-sdk' ;
3
5
4
6
export default function ShareLink ( ) {
5
7
const [ message , setMessage ] = React . useState < string > ( 'Come Play SDK Playground!' ) ;
@@ -9,7 +11,7 @@ export default function ShareLink() {
9
11
const [ hasPressedSend , setHasPressedSend ] = React . useState < boolean > ( false ) ;
10
12
const [ didSend , setDidSend ] = React . useState < boolean > ( false ) ;
11
13
12
- const handleMessageChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
14
+ const handleMessageChange = ( event : React . ChangeEvent < HTMLTextAreaElement > ) => {
13
15
setMessage ( event . target . value ) ;
14
16
} ;
15
17
const handleCustomIdChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
@@ -19,6 +21,21 @@ export default function ShareLink() {
19
21
setReferrerId ( event . target . value ) ;
20
22
} ;
21
23
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
+
22
39
const doShareLink = async ( ) => {
23
40
const { success} = await discordSdk . commands . shareLink ( {
24
41
message,
@@ -32,8 +49,7 @@ export default function ShareLink() {
32
49
return (
33
50
< div style = { { padding : 32 } } >
34
51
< p > Message: </ p >
35
- < input
36
- type = "text"
52
+ < textarea
37
53
value = { message }
38
54
onChange = { handleMessageChange }
39
55
placeholder = "Type a message to include with the link"
0 commit comments