| 1 |
/** |
| 2 |
* Content Area Component for Essential SEO |
| 3 |
* |
| 4 |
* Main content area that displays the selected section content |
| 5 |
* |
| 6 |
* @package ThinkRank |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
import { __ } from '@wordpress/i18n'; |
| 11 |
import { Card, CardHeader, CardBody, Button, Flex, FlexItem, Spinner } from '@wordpress/components'; |
| 12 |
import { memo, useMemo } from '@wordpress/element'; |
| 13 |
import { navigationStructure } from './SidebarNavigation'; |
| 14 |
|
| 15 |
// Direct imports - no lazy loading to avoid code splitting |
| 16 |
import SiteIdentityTab from './SiteIdentityTab'; |
| 17 |
import PerformanceTab from './PerformanceTab'; |
| 18 |
import AnalyticsTab from './AnalyticsTab'; |
| 19 |
import IntegrationsTab from './IntegrationsTab'; |
| 20 |
import SchemaTab from './SchemaTab'; |
| 21 |
import SocialMediaTab from './SocialMediaTab'; |
| 22 |
import CrawlingAIIndexingTab from './CrawlingAIIndexingTab'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Section Header Component - Optimized with React.memo |
| 26 |
*/ |
| 27 |
const SectionHeader = memo(({ section, item }) => { |
| 28 |
const sectionData = useMemo(() => |
| 29 |
navigationStructure.find(s => s.id === section), |
| 30 |
[section] |
| 31 |
); |
| 32 |
|
| 33 |
const itemData = useMemo(() => |
| 34 |
sectionData?.items.find(i => i.id === item), |
| 35 |
[sectionData, item] |
| 36 |
); |
| 37 |
|
| 38 |
return ( |
| 39 |
<div style={{ marginBottom: '20px' }}> |
| 40 |
<h2 style={{ margin: 0, fontSize: '20px', fontWeight: '600' }}> |
| 41 |
{sectionData?.title} |
| 42 |
{itemData && ( |
| 43 |
<span style={{ color: '#666', fontWeight: '400' }}> |
| 44 |
{' › ' + itemData.title} |
| 45 |
</span> |
| 46 |
)} |
| 47 |
</h2> |
| 48 |
</div> |
| 49 |
); |
| 50 |
}); |
| 51 |
|
| 52 |
/** |
| 53 |
* Section Content Wrapper - Optimized with React.memo |
| 54 |
*/ |
| 55 |
const SectionContent = memo(({ section, item, children }) => { |
| 56 |
return ( |
| 57 |
<div className="thinkrank-section-content"> |
| 58 |
{children} |
| 59 |
</div> |
| 60 |
); |
| 61 |
}); |
| 62 |
|
| 63 |
/** |
| 64 |
* Content Router - Routes to appropriate section content |
| 65 |
* |
| 66 |
* Direct component rendering without lazy loading or Suspense |
| 67 |
* All components are bundled into the main admin.js file |
| 68 |
*/ |
| 69 |
const ContentRouter = ({ section, item, onNavigate }) => { |
| 70 |
const renderTab = (TabComponent) => ( |
| 71 |
<TabComponent activeSubSection={item} onNavigate={onNavigate} /> |
| 72 |
); |
| 73 |
|
| 74 |
switch (section) { |
| 75 |
case 'site-identity': |
| 76 |
return renderTab(SiteIdentityTab); |
| 77 |
case 'performance': |
| 78 |
return renderTab(PerformanceTab); |
| 79 |
case 'analytics': |
| 80 |
return renderTab(AnalyticsTab); |
| 81 |
case 'integrations': |
| 82 |
return renderTab(IntegrationsTab); |
| 83 |
case 'schema': |
| 84 |
return renderTab(SchemaTab); |
| 85 |
case 'social-media': |
| 86 |
return renderTab(SocialMediaTab); |
| 87 |
case 'crawling-ai-indexing': |
| 88 |
return renderTab(CrawlingAIIndexingTab); |
| 89 |
default: |
| 90 |
return ( |
| 91 |
<Card> |
| 92 |
<CardHeader> |
| 93 |
<h2>{__('Section Not Found', 'thinkrank')}</h2> |
| 94 |
</CardHeader> |
| 95 |
<CardBody> |
| 96 |
<p>{__('The requested section could not be found.', 'thinkrank')}</p> |
| 97 |
</CardBody> |
| 98 |
</Card> |
| 99 |
); |
| 100 |
} |
| 101 |
}; |
| 102 |
|
| 103 |
/** |
| 104 |
* Main Content Area Component - Optimized with React.memo |
| 105 |
*/ |
| 106 |
const ContentArea = memo(({ activeSection, activeItem, onNavigate }) => { |
| 107 |
// Memoize the welcome card to prevent unnecessary re-renders |
| 108 |
const welcomeCard = useMemo(() => ( |
| 109 |
<Card> |
| 110 |
<CardHeader> |
| 111 |
<h2>{__('Welcome to Essential SEO', 'thinkrank')}</h2> |
| 112 |
</CardHeader> |
| 113 |
<CardBody> |
| 114 |
<p>{__('Select a section from the sidebar to get started with your SEO configuration.', 'thinkrank')}</p> |
| 115 |
</CardBody> |
| 116 |
</Card> |
| 117 |
), []); |
| 118 |
|
| 119 |
if (!activeSection) { |
| 120 |
return welcomeCard; |
| 121 |
} |
| 122 |
|
| 123 |
return ( |
| 124 |
<div> |
| 125 |
<SectionHeader |
| 126 |
section={activeSection} |
| 127 |
item={activeItem} |
| 128 |
/> |
| 129 |
|
| 130 |
<SectionContent section={activeSection} item={activeItem}> |
| 131 |
<ContentRouter section={activeSection} item={activeItem} onNavigate={onNavigate} /> |
| 132 |
</SectionContent> |
| 133 |
</div> |
| 134 |
); |
| 135 |
}); |
| 136 |
|
| 137 |
export default ContentArea; |
| 138 |
|