Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-page.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => 'b417b046aaa95efadbbc');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '84a24612c83497314925');
16 changes: 8 additions & 8 deletions build/content-helper/dashboard-page.js

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions src/UI/class-dashboard-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,12 @@ public function add_dashboard_page_to_menu(): void {
30
);

// Register the subpages.
add_submenu_page(
'parsely-dashboard-page',
'Parse.ly Dashboard Page',
'Dashboard',
Parsely::CAPABILITY, // phpcs:ignore WordPress.WP.Capabilities.Undetermined
'parsely-dashboard-page',
'__return_null'
);

add_submenu_page(
'parsely-dashboard-page',
'Parse.ly Traffic Boost',
'Traffic Boost',
'Traffic Boost (beta)',
Parsely::CAPABILITY, // phpcs:ignore WordPress.WP.Capabilities.Undetermined
'parsely-dashboard-page#/traffic-boost',
'parsely-dashboard-page',
'__return_null'
);

Expand Down
58 changes: 9 additions & 49 deletions src/content-helper/dashboard-page/dashboard-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@
* External dependencies
*/
import {
Navigate,
Route,
HashRouter as Router,
Routes,
useLocation,
} from 'react-router';

/**
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';
import { createRoot, useEffect } from '@wordpress/element';
import { createRoot } from '@wordpress/element';

/**
* Internal dependencies
*/
import { DashboardPage, SettingsPage, TrafficBoostPage } from './pages';
import { SettingsPage, TrafficBoostPage } from './pages';
import { TrafficBoostPostPage } from './pages/traffic-boost/single-post-component';

domReady( () => {
// Highlight the Traffic Boost menu item under the Parse.ly menu.
document.querySelector(
'#toplevel_page_parsely-dashboard-page .wp-submenu li.wp-first-item'
)?.classList.add( 'current' );

const root = createRoot(
document.getElementById( 'parsely-dashboard-page' ) as Element
);
Expand All @@ -40,54 +45,9 @@ domReady( () => {
* @class
*/
const ParselyDashboard = () => {
const location = useLocation();

/**
* Replaces the first link to have the hash router link.
*
* @since 3.19.0
*/
useEffect( () => {
const firstLink = document.querySelector(
'#toplevel_page_parsely-dashboard-page .wp-submenu li a.wp-first-item'
);
if ( firstLink ) {
firstLink.setAttribute(
'href', window.location.pathname + window.location.search + '#/'
);
}
}, [] );

/**
* Changes the submenus highlight based on the current page.
*
* @since 3.19.0
*/
useEffect( () => {
const submenuItems = document.querySelectorAll(
'#toplevel_page_parsely-dashboard-page .wp-submenu li'
);

submenuItems.forEach( ( item ) => {
const link = item.querySelector( 'a' );
const hashPath = link?.getAttribute( 'href' )?.split( '#' )[ 1 ];

// Get the base paths for comparison (first segment of the path).
const currentBasePath = location.pathname.split( '/' )[ 1 ];
const menuBasePath = hashPath?.split( '/' )[ 1 ];

if ( currentBasePath === menuBasePath || hashPath === location.pathname ) {
item.classList.add( 'current' );
link?.blur();
} else {
item.classList.remove( 'current' );
}
} );
}, [ location ] );

return (
<Routes>
<Route path="/" element={ <DashboardPage /> } />
<Route path="/" element={ <Navigate to="/traffic-boost" replace /> } />
<Route path="/traffic-boost" element={ <TrafficBoostPage /> } />
<Route path="/traffic-boost/:postId" element={ <TrafficBoostPostPage /> } />
<Route path="/settings" element={ <SettingsPage /> } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const TrafficBoostPage = (): React.JSX.Element => {
return (
<PageContainer name="traffic-boost">
<PageHeader>
<h1>{ __( 'Manage Traffic Boost', 'wp-parsely' ) }</h1>
<h1>{ __( 'Manage Traffic Boost (beta)', 'wp-parsely' ) }</h1>
</PageHeader>
<PageBody>
<div className="traffic-boost-search-container">
Expand Down
Loading