@@ -35,6 +35,7 @@ import makeHtmlDisplayTabFrom from 'src/commons/sideContent/content/SideContentH
3535import { changeSideContentHeight } from 'src/commons/sideContent/SideContentActions' ;
3636import { useSideContent } from 'src/commons/sideContent/SideContentHelper' ;
3737import { useResponsive , useTypedSelector } from 'src/commons/utils/Hooks' ;
38+ import { showWarningMessage } from 'src/commons/utils/notifications/NotificationsHelper' ;
3839import { convertParamToBoolean , convertParamToInt } from 'src/commons/utils/ParamParseHelper' ;
3940import { IParsedQuery , parseQuery } from 'src/commons/utils/QueryHelper' ;
4041import {
@@ -109,7 +110,10 @@ import { ControlBarEvalButton } from '../../commons/controlBar/ControlBarEvalBut
109110import { ControlBarExecutionTime } from '../../commons/controlBar/ControlBarExecutionTime' ;
110111import { ControlBarGoogleDriveButtons } from '../../commons/controlBar/ControlBarGoogleDriveButtons' ;
111112import { ControlBarSessionButtons } from '../../commons/controlBar/ControlBarSessionButton' ;
112- import { ControlBarShareButton } from '../../commons/controlBar/ControlBarShareButton' ;
113+ import {
114+ ControlBarShareButton ,
115+ requestToShareProgram
116+ } from '../../commons/controlBar/ControlBarShareButton' ;
113117import { ControlBarStepLimit } from '../../commons/controlBar/ControlBarStepLimit' ;
114118import { ControlBarToggleFolderModeButton } from '../../commons/controlBar/ControlBarToggleFolderModeButton' ;
115119import { ControlBarGitHubButtons } from '../../commons/controlBar/github/ControlBarGitHubButtons' ;
@@ -440,25 +444,34 @@ const Playground: React.FC<PlaygroundProps> = props => {
440444 } , [ editorSessionId ] ) ;
441445
442446 const hash = isSicpEditor ? props . initialEditorValueHash : location . hash ;
443- const { uuid } = useParams < string > ( ) ;
447+ const { uuid } = useParams < { uuid : string } > ( ) ;
448+ const config = useUrlEncoder ( ) ;
449+ const tokens = useTypedSelector ( ( state : OverallState ) => ( {
450+ accessToken : state . session . accessToken ,
451+ refreshToken : state . session . refreshToken
452+ } ) ) ;
444453
445454 const handleURL = useCallback (
446- ( uuid : string | undefined ) => {
455+ async ( uuid : string | undefined ) => {
447456 if ( uuid !== undefined ) {
448- fetch ( `${ Constants . backendUrl } /api/shared_programs/${ uuid } ` )
449- . then ( response => response . json ( ) )
450- . then ( resp => {
451- const res : ShareLinkState = new ShareLinkStateDecoder ( resp ) . decodeWith (
452- new JsonDecoderDelegate ( )
453- ) ;
454- resetConfig (
455- res ,
456- { handleChangeExecTime, handleChapterSelect } ,
457- workspaceLocation ,
458- dispatch ,
459- fileSystem
460- ) ;
461- } ) ;
457+ const resp = await requestToShareProgram ( `shared_programs/${ uuid } ` , 'GET' , {
458+ ...tokens
459+ } ) ;
460+ if ( ! resp ) {
461+ return showWarningMessage ( 'Invalid share program link! ' ) ;
462+ }
463+ const respJson = await resp . json ( ) ;
464+ const res : ShareLinkState = new ShareLinkStateDecoder ( respJson ) . decodeWith (
465+ new JsonDecoderDelegate ( )
466+ ) ;
467+ resetConfig (
468+ res ,
469+ { handleChangeExecTime, handleChapterSelect } ,
470+ workspaceLocation ,
471+ dispatch ,
472+ fileSystem
473+ ) ;
474+ return ;
462475 } else {
463476 const config = new ShareLinkStateDecoder ( location . hash ) . decodeWith (
464477 new UrlParamsDecoderDelegate ( )
@@ -470,15 +483,20 @@ const Playground: React.FC<PlaygroundProps> = props => {
470483 dispatch ,
471484 fileSystem
472485 ) ;
486+ return ;
473487 }
474488 } ,
489+ // disabled eslint here since tokens are checked separately, checking single object cause infinite rerender.
490+ // eslint-disable-next-line
475491 [
476492 dispatch ,
477493 fileSystem ,
478494 handleChangeExecTime ,
479495 handleChapterSelect ,
480496 location . hash ,
481- workspaceLocation
497+ workspaceLocation ,
498+ tokens . accessToken ,
499+ tokens . refreshToken
482500 ]
483501 ) ;
484502
@@ -819,8 +837,6 @@ const Playground: React.FC<PlaygroundProps> = props => {
819837 ]
820838 ) ;
821839
822- const config = useUrlEncoder ( ) ;
823-
824840 const shareButton = useMemo ( ( ) => {
825841 const qs = isSicpEditor ? Links . playground + '#' + props . initialEditorValueHash : queryString ;
826842 return (
@@ -830,12 +846,13 @@ const Playground: React.FC<PlaygroundProps> = props => {
830846 handleUpdateShortURL = { s => dispatch ( updateShortURL ( s ) ) }
831847 queryString = { qs }
832848 programConfig = { config }
849+ token = { tokens }
833850 shortURL = { shortURL }
834851 isSicp = { isSicpEditor }
835852 key = "share"
836853 />
837854 ) ;
838- } , [ dispatch , isSicpEditor , props . initialEditorValueHash , queryString , shortURL , config ] ) ;
855+ } , [ dispatch , isSicpEditor , props . initialEditorValueHash , queryString , shortURL , config , tokens ] ) ;
839856
840857 const toggleFolderModeButton = useMemo ( ( ) => {
841858 return (
0 commit comments