Skip to content

Commit da2f844

Browse files
committed
chore: automatically scroll to TC panel and open it when coming from pattern modal
1 parent 67cfd43 commit da2f844

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/blocks/plugins/patterns-library/cloudLibraryPlaceholder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default () => (
1616
<br/>
1717

1818
<Button
19-
href={`${window.themeisleGutenberg.optionsPath}#integrations`}
19+
href={`${window.themeisleGutenberg.optionsPath}&scrollTo=tc#integrations`}
2020
variant='link'
2121
>
2222
{__('Go to settings to add sources', 'otter-blocks')}

src/dashboard/components/template-cloud/TCPanel.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Button, ExternalLink, Notice, PanelBody } from '@wordpress/components';
2-
import { useEffect, useState, createInterpolateElement } from '@wordpress/element';
2+
import { useEffect, useState, createInterpolateElement, useRef } from '@wordpress/element';
33
import { plus, rotateRight } from '@wordpress/icons';
44
import { useDispatch } from '@wordpress/data';
55
import 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

Comments
 (0)