2018-05-10 18:35:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-05-24 16:03:03 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2020-11-03 00:57:49 +00:00
|
|
|
import { useEffect, useRef } from '@wordpress/element';
|
2018-07-09 15:46:31 +00:00
|
|
|
import classnames from 'classnames';
|
2018-07-23 20:14:40 +00:00
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
2020-08-27 01:46:53 +00:00
|
|
|
import { useUserPreferences } from '@woocommerce/data';
|
2020-10-06 20:42:46 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
|
|
|
import { __experimentalText as Text } from '@wordpress/components';
|
2018-11-05 21:02:04 +00:00
|
|
|
|
2018-05-10 18:35:55 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2018-09-21 15:19:05 +00:00
|
|
|
import ActivityPanel from './activity-panel';
|
2020-08-27 01:46:53 +00:00
|
|
|
import { MobileAppBanner } from '../mobile-banner';
|
2020-11-03 00:57:49 +00:00
|
|
|
import useIsScrolled from '../hooks/useIsScrolled';
|
2018-05-10 18:35:55 +00:00
|
|
|
|
2020-08-23 22:46:18 +00:00
|
|
|
export const Header = ( { sections, isEmbedded = false, query } ) => {
|
|
|
|
const headerElement = useRef( null );
|
|
|
|
const siteTitle = getSetting( 'siteTitle', '' );
|
2020-10-06 20:42:46 +00:00
|
|
|
const pageTitle = sections.slice( -1 )[ 0 ];
|
2020-11-03 00:57:49 +00:00
|
|
|
const isScrolled = useIsScrolled();
|
2020-08-27 01:46:53 +00:00
|
|
|
const { updateUserPreferences, ...userData } = useUserPreferences();
|
|
|
|
|
|
|
|
const isModalDismissed = userData.android_app_banner_dismissed === 'yes';
|
2020-01-20 17:34:24 +00:00
|
|
|
|
2020-08-23 22:46:18 +00:00
|
|
|
const className = classnames( 'woocommerce-layout__header', {
|
|
|
|
'is-scrolled': isScrolled,
|
|
|
|
} );
|
2020-01-20 17:34:24 +00:00
|
|
|
|
2020-08-23 22:46:18 +00:00
|
|
|
useEffect( () => {
|
|
|
|
if ( ! isEmbedded ) {
|
2020-08-27 01:46:53 +00:00
|
|
|
const documentTitle = sections
|
2020-08-23 22:46:18 +00:00
|
|
|
.map( ( section ) => {
|
|
|
|
return Array.isArray( section ) ? section[ 1 ] : section;
|
|
|
|
} )
|
|
|
|
.reverse()
|
|
|
|
.join( ' ‹ ' );
|
|
|
|
|
|
|
|
const decodedTitle = decodeEntities(
|
|
|
|
sprintf(
|
|
|
|
/* translators: 1: document title. 2: page title */
|
|
|
|
__(
|
|
|
|
'%1$s ‹ %2$s — WooCommerce',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
documentTitle,
|
|
|
|
siteTitle
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( document.title !== decodedTitle ) {
|
|
|
|
document.title = decodedTitle;
|
|
|
|
}
|
|
|
|
}
|
2020-08-27 01:46:53 +00:00
|
|
|
}, [ isEmbedded, sections, siteTitle ] );
|
|
|
|
|
|
|
|
const dismissHandler = () => {
|
|
|
|
updateUserPreferences( {
|
|
|
|
android_app_banner_dismissed: 'yes',
|
|
|
|
} );
|
|
|
|
};
|
2020-08-23 22:46:18 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ className } ref={ headerElement }>
|
2020-08-27 01:46:53 +00:00
|
|
|
{ ! isModalDismissed && (
|
|
|
|
<MobileAppBanner
|
|
|
|
onDismiss={ dismissHandler }
|
|
|
|
onInstall={ dismissHandler }
|
|
|
|
/>
|
|
|
|
) }
|
2020-10-06 20:42:46 +00:00
|
|
|
|
|
|
|
<Text
|
|
|
|
className="woocommerce-layout__header-heading"
|
|
|
|
as="h1"
|
|
|
|
variant="subtitle.small"
|
|
|
|
>
|
|
|
|
{ decodeEntities( pageTitle ) }
|
|
|
|
</Text>
|
2020-08-23 22:46:18 +00:00
|
|
|
{ window.wcAdminFeatures[ 'activity-panels' ] && (
|
2020-12-18 13:17:07 +00:00
|
|
|
<ActivityPanel
|
|
|
|
isEmbedded={ isEmbedded }
|
|
|
|
query={ query }
|
|
|
|
userPreferencesData={ {
|
|
|
|
...userData,
|
|
|
|
updateUserPreferences,
|
|
|
|
} }
|
|
|
|
/>
|
2020-08-23 22:46:18 +00:00
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
);
|
2018-05-22 15:19:56 +00:00
|
|
|
};
|