11import { Button , ExternalLink , Notice , PanelBody } from '@wordpress/components' ;
2- import { useEffect , useState , createInterpolateElement } from '@wordpress/element' ;
2+ import { useEffect , useState , createInterpolateElement , useRef } from '@wordpress/element' ;
33import { plus , rotateRight } from '@wordpress/icons' ;
44import { useDispatch } from '@wordpress/data' ;
55import apiFetch from '@wordpress/api-fetch' ;
@@ -16,13 +16,28 @@ const TCPanel = () => {
1616 const [ isAdding , setIsAdding ] = useState ( false ) ;
1717 const [ status , setStatus ] = useState ( STATUSES . NONE ) ;
1818 const [ syncErrors , setSyncErrors ] = useState ( [ ] ) ;
19-
19+ const [ shouldOpen , setShouldOpen ] = useState ( false ) ;
20+ const panelRef = useRef ( ) ;
2021 const { createNotice } = useDispatch ( 'core/notices' ) ;
2122
2223 useEffect ( ( ) => {
2324 setSources ( getOption ( 'themeisle_template_cloud_sources' ) ) ;
2425 } , [ getOption ( 'themeisle_template_cloud_sources' ) ] ) ;
2526
27+
28+ useEffect ( ( ) => {
29+ const hasURLParam = new URLSearchParams ( window . location . search ) . get ( 'scrollTo' ) === 'tc' ;
30+
31+ if ( hasURLParam ) {
32+ setShouldOpen ( true ) ;
33+
34+ if ( panelRef . current ) {
35+ panelRef . current . scrollIntoView ( { behavior : 'smooth' } ) ;
36+ }
37+ }
38+
39+ } , [ panelRef . current ] ) ;
40+
2641 const syncSources = ( ) => {
2742 setStatus ( STATUSES . SYNCING ) ;
2843
@@ -65,8 +80,9 @@ const TCPanel = () => {
6580
6681 return < >
6782 < PanelBody
83+ ref = { panelRef }
6884 title = { __ ( 'Template Cloud' , 'otter-blocks' ) }
69- initialOpen = { false }
85+ initialOpen = { shouldOpen }
7086 >
7187 < div className = "tc-panel-content-wrap" >
7288 { sources . length < 1 && ! isAdding && (
0 commit comments