Emails
1 month ago
EngagementChart
1 month ago
MediaHub
1 month ago
Onboarding
1 month ago
Popup
1 month ago
Skeletons
1 week ago
WhatsNew
1 month ago
charts
1 month ago
test
1 month ago
AdminMenuSync.js
1 month ago
ChartEmptyState.js
1 month ago
ChooseDate.js
1 month ago
ColorPicker.js
1 month ago
ExtendPlugins.js
1 month ago
Filters.js
1 month ago
Link.js
1 month ago
Navbar.js
1 week ago
NoFound.js
1 month ago
PageHeader.js
1 month ago
PluginRecommendations.js
1 month ago
PostScheduleField.js
1 month ago
PrestoPlayerIcon.js
1 month ago
ProGateOverlay.js
1 month ago
QuickAccess.js
1 month ago
RankedTable.js
1 month ago
StatCard.js
1 month ago
TopMedia.js
1 month ago
TopPerformingMedia.js
1 month ago
TopUsers.js
1 month ago
TruncatedTitle.js
1 month ago
UpgradeNotice.js
1 month ago
UpgradeToPro.js
1 month ago
VideoModal.js
1 month ago
WelcomeBanner.js
1 month ago
AdminMenuSync.js
45 lines
| 1 | import { useEffect } from "react"; |
| 2 | import { useLocation } from "../router/router"; |
| 3 | |
| 4 | /** |
| 5 | * Syncs the WordPress admin sidebar submenu highlight with the active |
| 6 | * dashboard tab. When the user navigates via the in-app Navbar tabs, |
| 7 | * the URL changes via pushState but the server-rendered sidebar doesn't |
| 8 | * update. This component listens for tab changes and toggles the |
| 9 | * 'current' CSS class on the matching sidebar <li>. |
| 10 | * |
| 11 | * Follows the same pattern as SureDash's AdminMenuSync component. |
| 12 | */ |
| 13 | const AdminMenuSync = () => { |
| 14 | const location = useLocation(); |
| 15 | const currentTab = location.params?.tab; |
| 16 | |
| 17 | useEffect(() => { |
| 18 | const pageSlug = "presto-dashboard"; |
| 19 | // The Dashboard submenu's href has no `tab` param, so treat the |
| 20 | // "Dashboard" tab (and the bare URL) as the same target. |
| 21 | const pageUrl = currentTab && currentTab !== "Dashboard" |
| 22 | ? `admin.php?page=${pageSlug}&tab=${currentTab}` |
| 23 | : `admin.php?page=${pageSlug}`; |
| 24 | |
| 25 | // Find matching sidebar link by href suffix. |
| 26 | const matchingLinks = document.querySelectorAll( |
| 27 | `.wp-submenu-wrap li > a[href$="${pageUrl}"]` |
| 28 | ); |
| 29 | |
| 30 | // Remove 'current' from all submenu items under our menu. |
| 31 | document |
| 32 | .querySelectorAll("#toplevel_page_presto-dashboard .wp-submenu li") |
| 33 | .forEach((li) => li.classList.remove("current")); |
| 34 | |
| 35 | // Add 'current' to matching item(s). |
| 36 | matchingLinks.forEach((a) => { |
| 37 | a.parentElement.classList.add("current"); |
| 38 | }); |
| 39 | }, [currentTab]); |
| 40 | |
| 41 | return null; |
| 42 | }; |
| 43 | |
| 44 | export default AdminMenuSync; |
| 45 |