/** * WordPress dependencies */ import { Button, DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components'; import { useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { desktop, external, moreVertical, pencil } from '@wordpress/icons'; /** * Internal dependencies */ import { LeafIcon } from '../../../../../common/icons/leaf-icon'; import { HydratedPost } from '../../../../../common/providers/base-wordpress-provider'; import { TrafficBoostLink } from '../../provider'; import { isExternalURL } from '../utils'; import { LinkCounter } from './link-counter'; /** * Props structure for VerticalMoreMenu. * * @since 3.19.0 */ interface VerticalMoreMenuProps { post: HydratedPost; onEditClick: ( post: HydratedPost ) => void; onViewInNewTabClick: ( post: HydratedPost ) => void; onViewInParseLyClick: ( post: HydratedPost ) => void; } /** * VerticalMoreMenu component. * * This component is used to display a dropdown menu with actions for a post. * * @since 3.19.0 * * @param {VerticalMoreMenuProps} props The component's props. */ const VerticalMoreMenu = ( { post, onEditClick, onViewInNewTabClick, onViewInParseLyClick, }: VerticalMoreMenuProps ): React.JSX.Element => { /** * Handles the click event for the dropdown menu items. * * @since 3.19.0 * * @param {string} type The type of action to perform. * @param {Function} onClose The function to call when the action is performed. */ const onClickHandler = ( type: string, onClose: () => void ) => { switch ( type ) { case 'edit': onEditClick( post ); break; case 'view-in-new-tab': onViewInNewTabClick( post ); break; case 'view-in-parse-ly': onViewInParseLyClick( post ); break; } onClose(); }; return ( { ( { onClose } ) => ( onClickHandler( 'edit', onClose ) }> { __( 'Edit Post', 'wp-parsely' ) } onClickHandler( 'view-in-new-tab', onClose ) }> { __( 'View post in a new tab', 'wp-parsely' ) } } onClick={ () => onClickHandler( 'view-in-parse-ly', onClose ) }> { __( 'View in Parse.ly', 'wp-parsely' ) } ) } ); }; /** * Props structure for PreviewHeader. * * @since 3.19.0 */ interface PreviewHeaderProps { isLoading: boolean; activeLink: TrafficBoostLink | null; onOpenPostInNewTab: () => void; onOpenPostEditor: () => void; onOpenParselyDashboard: () => void; isFrontendPreview: boolean; setIsFrontendPreview: ( value: boolean ) => void; } /** * Preview header component for the Traffic Boost feature. * Displays preview header for a selected post. * * @since 3.19.0 * * @param {PreviewHeaderProps} props The component's props. */ export const PreviewHeader = ( { isLoading, activeLink, isFrontendPreview, setIsFrontendPreview, onOpenPostEditor, onOpenPostInNewTab, onOpenParselyDashboard, }: PreviewHeaderProps ): React.JSX.Element => { /** * Toggles the frontend preview state. * * @since 3.19.0 */ const onToggleFrontendPreview = () => { setIsFrontendPreview( ! isFrontendPreview ); }; /** * Toggles the frontend preview state when the active link is external, * so that the iframe is not displayed. * * This prevents issues with cross-origin requests. * * @since 3.19.0 */ useEffect( () => { if ( activeLink && isExternalURL( activeLink ) ) { setIsFrontendPreview( false ); } }, [ activeLink, setIsFrontendPreview ] ); if ( ! activeLink ) { return <>; } return (
{ ! isExternalURL( activeLink ) && false && (
); };