PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.0.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.0.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / src / admin / components / App.js

App.js in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.0.0, at src/admin/components/App.js

186 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Main Admin App Component
3 *
4 * Router component for admin interface
5 *
6 * @package ThinkRank
7 * @since 1.0.0
8 */
9
10 import { useState, useEffect } from '@wordpress/element';
11 import { __ } from '@wordpress/i18n';
12 import { Spinner, Notice } from '@wordpress/components';
13
14 // Page Components
15 import Dashboard from './pages/Dashboard';
16 import EssentialSEO from './pages/EssentialSEO';
17 import AITools from './pages/AITools';
18 import Settings from './pages/Settings';
19 import UsageAnalytics from './pages/UsageAnalytics';
20
21 // Common Components
22 import Header from './common/Header';
23 import ErrorBoundary from './common/ErrorBoundary';
24
25 /**
26 * Main App Component
27 *
28 * @param {Object} props Component props
29 * @param {string} props.page Current page identifier
30 */
31 const App = ({ page = 'dashboard' }) => {
32 const [currentPage, setCurrentPage] = useState(page);
33 const [isLoading, setIsLoading] = useState(true);
34
35 // Simplified state - remove store dependency for now
36 const [isInitialized, setIsInitialized] = useState(false);
37 const [hasError, setHasError] = useState(false);
38 const [errorMessage, setErrorMessage] = useState('');
39 const userCapabilities = {};
40
41 // Initialize app
42 useEffect(() => {
43 const initializeApp = async () => {
44 try {
45 // Simple initialization without store dependencies
46 await new Promise(resolve => setTimeout(resolve, 500));
47 setIsInitialized(true);
48 setIsLoading(false);
49 } catch (error) {
50 console.error('ThinkRank: App initialization failed', error);
51 setHasError(true);
52 setErrorMessage(error.message);
53 setIsLoading(false);
54 }
55 };
56
57 initializeApp();
58 }, []);
59
60 // Handle page changes
61 const handlePageChange = (newPage) => {
62 if (userCapabilities[newPage] !== false) {
63 setCurrentPage(newPage);
64 }
65 };
66
67 // Render loading state
68 if (isLoading || !isInitialized) {
69 return (
70 <div className="thinkrank-loading">
71 <Spinner />
72 <p>{__('Loading ThinkRank...', 'thinkrank')}</p>
73 </div>
74 );
75 }
76
77 // Render error state
78 if (hasError) {
79 return (
80 <div className="thinkrank-error">
81 <Notice status="error" isDismissible={false}>
82 <strong>{__('ThinkRank Error:', 'thinkrank')}</strong>
83 <br />
84 {errorMessage}
85 </Notice>
86 </div>
87 );
88 }
89
90 // Get page information for header
91 const getPageInfo = (page) => {
92 switch (page) {
93 case 'dashboard':
94 return {
95 title: __('Dashboard', 'thinkrank'),
96 description: __('Overview of your SEO optimization progress', 'thinkrank'),
97 showHelp: true
98 };
99 case 'essential-seo':
100 return {
101 title: __('Essential SEO', 'thinkrank'),
102 description: __('Configure your site-wide SEO settings with AI-powered optimization', 'thinkrank'),
103 showHelp: true
104 };
105 case 'ai-tools':
106 return {
107 title: __('AI Tools', 'thinkrank'),
108 description: __('AI-powered content tools including Content Planner and Metadata Generator', 'thinkrank'),
109 showHelp: true
110 };
111 case 'settings':
112 return {
113 title: __('Settings', 'thinkrank'),
114 description: __('Configure your AI API keys and plugin preferences', 'thinkrank'),
115 showHelp: false
116 };
117 case 'analytics':
118 return {
119 title: __('Usage Analytics', 'thinkrank'),
120 description: __('Track your AI usage, costs, and plugin performance analytics', 'thinkrank'),
121 showHelp: true
122 };
123 default:
124 return {
125 title: __('ThinkRank', 'thinkrank'),
126 description: __('AI-powered SEO optimization for WordPress', 'thinkrank'),
127 showHelp: false
128 };
129 }
130 };
131
132 const pageInfo = getPageInfo(currentPage);
133
134 return (
135 <ErrorBoundary>
136 <div className="thinkrank-app thinkrank-ui">
137 <Header
138 pageTitle={pageInfo.title}
139 pageDescription={pageInfo.description}
140 showHelp={pageInfo.showHelp}
141 />
142
143 <div className="thinkrank-main">
144 <div className="thinkrank-content">
145 {renderCurrentPage(currentPage)}
146 </div>
147 </div>
148 </div>
149 </ErrorBoundary>
150 );
151 };
152
153 /**
154 * Render current page component
155 *
156 * @param {string} page Current page
157 * @return {JSX.Element} Page component
158 */
159 function renderCurrentPage(page) {
160 switch (page) {
161 case 'dashboard':
162 return <Dashboard />;
163
164 case 'essential-seo':
165 return <EssentialSEO />;
166
167 case 'ai-tools':
168 return <AITools />;
169
170 case 'settings':
171 return <Settings />;
172
173 case 'analytics':
174 return <UsageAnalytics />;
175
176 default:
177 return (
178 <Notice status="warning">
179 {__('Page not found. Redirecting to dashboard...', 'thinkrank')}
180 </Notice>
181 );
182 }
183 }
184
185 export default App;
186