| 1 |
import React, { useState, useLayoutEffect, useEffect } from 'react' |
| 2 |
import { Router } from 'react-router-dom'; |
| 3 |
|
| 4 |
import { history } from '~betterdocs/utils/history'; |
| 5 |
import Routes from './Routes'; |
| 6 |
|
| 7 |
const AdminPanel = () => { |
| 8 |
const [state, setState] = useState({ |
| 9 |
action: history.action, |
| 10 |
location: history.location, |
| 11 |
}); |
| 12 |
|
| 13 |
useLayoutEffect(() => history.listen((location, action) => { |
| 14 |
setState({ action, location }); |
| 15 |
}), [history]); |
| 16 |
|
| 17 |
useEffect(() => { |
| 18 |
let instantAnswer = document.getElementsByClassName('betterdocs-ia'); |
| 19 |
|
| 20 |
if (instantAnswer.length === 0) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
//related I/A settings preview |
| 25 |
if( ! ( state?.location?.pathname == '/betterdocs-settings' && betterdocsAdminSettings?.values?.enable_disable ) ) { //inverse or negate the condition |
| 26 |
instantAnswer[0].style.display = 'none'; |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
//related I/A settings preview |
| 31 |
if( ! ( state?.location?.pathname == '/betterdocs-settings' && betterdocsAdminSettings?.values?.ia_enable_preview ) ) { //inverse or negate the condition |
| 32 |
instantAnswer[0].style.display = 'none'; |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
//related I/A settings preview |
| 37 |
instantAnswer[0].style.display = 'block'; |
| 38 |
|
| 39 |
}, [state]); |
| 40 |
|
| 41 |
return ( |
| 42 |
<Router |
| 43 |
location={state.location} |
| 44 |
basename="/" |
| 45 |
navigator={history} |
| 46 |
navigationType={state.action}> |
| 47 |
<Routes /> |
| 48 |
</Router> |
| 49 |
) |
| 50 |
} |
| 51 |
|
| 52 |
export default AdminPanel |
| 53 |
|