Skip to content

Commit b389bd5

Browse files
committed
Move existing link highlight-specific code to useExistingLinkHighlight()
1 parent 816fa3a commit b389bd5

File tree

5 files changed

+380
-149
lines changed

5 files changed

+380
-149
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '2bf214d8db4f3289591c');
1+
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '1584528d4b5b04a117a7');

build/content-helper/dashboard-page.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/content-helper/dashboard-page/pages/traffic-boost/preview/components/preview-iframe.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { TextSelection } from '../preview';
1919
import { getContentArea, isExternalURL } from '../utils';
2020
import { PreviewActions } from './preview-actions';
2121
import { TextSelectionTooltip } from './text-selection-tooltip';
22+
import { useExistingLinkHighlight } from '../hooks/use-existing-link-highlight';
2223

2324
/**
2425
* Props structure for PreviewIframe.
@@ -92,16 +93,18 @@ export const PreviewIframe = ( {
9293
}, [ previewUrl ] );
9394

9495
// Create an actions bar to be mounted in the iframe with useIframeHighlight().
95-
const actionsBar = <PreviewActions
96-
activeLink={ activeLink }
97-
onAccept={ onAccept }
98-
onDiscard={ onDiscard }
99-
onUpdateLink={ onUpdateLink }
100-
onRemove={ onRemove }
101-
onRestoreOriginal={ onRestoreOriginal }
102-
selectedText={ selectedText ?? null }
103-
iframeRef={ iframeRef }
104-
/>;
96+
const actionsBar = useMemo( () => (
97+
<PreviewActions
98+
activeLink={ activeLink }
99+
onAccept={ onAccept }
100+
onDiscard={ onDiscard }
101+
onUpdateLink={ onUpdateLink }
102+
onRemove={ onRemove }
103+
onRestoreOriginal={ onRestoreOriginal }
104+
selectedText={ selectedText ?? null }
105+
iframeRef={ iframeRef }
106+
/>
107+
), [ activeLink, onAccept, onDiscard, onUpdateLink, onRemove, onRestoreOriginal, selectedText, iframeRef ] );
105108

106109
/**
107110
* Highlights the smart link in the iframe.
@@ -111,7 +114,6 @@ export const PreviewIframe = ( {
111114
const {
112115
injectHighlightStyles,
113116
highlightSmartLink,
114-
highlightLinkType,
115117
removeSmartLinkHighlights,
116118
} = useIframeHighlight( {
117119
iframeRef,
@@ -123,6 +125,15 @@ export const PreviewIframe = ( {
123125
actionsBar,
124126
} );
125127

128+
const {
129+
injectExistingLinkHighlightStyles,
130+
highlightExistingLinkType,
131+
} = useExistingLinkHighlight( {
132+
iframeRef,
133+
contentAreaRef,
134+
activeLink,
135+
} );
136+
126137
/**
127138
* Hides the admin bar from the iframe if the preview is in frontend mode.
128139
*
@@ -298,6 +309,7 @@ export const PreviewIframe = ( {
298309
}
299310

300311
injectHighlightStyles( iframe );
312+
injectExistingLinkHighlightStyles( iframe );
301313

302314
// Updates the content area ref to the iframe's content area.
303315
const contentArea = getContentArea( iframe.contentDocument );
@@ -311,19 +323,17 @@ export const PreviewIframe = ( {
311323
}
312324

313325
hideAdminBar( iframe );
314-
highlightLinkType( iframe, selectedLinkType );
315326
disableNavigation( iframe );
316327

317328
onLoadingChange( false );
318329
jumpToSmartLink( iframe );
319330
}, [ contentAreaRef,
320331
disableNavigation,
321332
hideAdminBar,
322-
highlightLinkType,
323333
injectHighlightStyles,
334+
injectExistingLinkHighlightStyles,
324335
jumpToSmartLink,
325336
onLoadingChange,
326-
selectedLinkType,
327337
] );
328338

329339
/**
@@ -399,8 +409,8 @@ export const PreviewIframe = ( {
399409
return;
400410
}
401411

402-
highlightLinkType( iframe, selectedLinkType );
403-
}, [ contentAreaRef, highlightLinkType, isLoading, selectedLinkType ] );
412+
highlightExistingLinkType( iframe, selectedLinkType );
413+
}, [ contentAreaRef, highlightExistingLinkType, isLoading, selectedLinkType ] );
404414

405415
return (
406416
<div className="wp-parsely-preview">

0 commit comments

Comments
 (0)