settings.js
| 1 | import { render } from '@wordpress/element'; |
| 2 | import { BrowserRouter as Router, useLocation } from 'react-router-dom'; |
| 3 | |
| 4 | import Header from './Header'; |
| 5 | import Navigation from './Navigation'; |
| 6 | import Component from './Component'; |
| 7 | import './styles.scss'; |
| 8 | |
| 9 | function useQuery() { |
| 10 | return new URLSearchParams( useLocation().search ); |
| 11 | } |
| 12 | |
| 13 | function QueryScreen() { |
| 14 | const query = useQuery(); |
| 15 | return <Component path={ query.get( 'tab' ) } />; |
| 16 | } |
| 17 | |
| 18 | const Settings = () => { |
| 19 | return ( |
| 20 | <Router> |
| 21 | <Header /> |
| 22 | <div className="srfm-flex srfm-flex-row srfm-h-[100vh] srfm-bg-transparent"> |
| 23 | <Navigation /> |
| 24 | <QueryScreen /> |
| 25 | </div> |
| 26 | </Router> |
| 27 | ); |
| 28 | }; |
| 29 | |
| 30 | export default Settings; |
| 31 | |
| 32 | ( function () { |
| 33 | const app = document.getElementById( 'srfm-settings-container' ); |
| 34 | |
| 35 | function renderApp() { |
| 36 | if ( null !== app ) { |
| 37 | render( <Settings />, app ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | document.addEventListener( 'DOMContentLoaded', renderApp ); |
| 42 | }() ); |
| 43 |