import React from 'react'; import ReactDOM from 'react-dom'; import { Router } from '@reach/router'; import { siteRoot } from '../../utils/constants'; import SidePanel from './side-panel'; import MainPanel from './main-panel'; import FileScanRecords from './file-scan-records'; import WorkWeixinDepartments from './work-weixin-departments'; import Info from './info'; import DesktopDevices from './devices/desktop-devices'; import MobileDevices from './devices/mobile-devices'; import DeviceErrors from './devices/devices-errors'; import AllRepos from './repos/all-repos'; import SystemRepo from './repos/system-repo'; import TrashRepos from './repos/trash-repos'; import DirView from './repos/dir-view'; import '../../assets/css/fa-solid.css'; import '../../assets/css/fa-regular.css'; import '../../assets/css/fontawesome.css'; import '../../css/layout.css'; import '../../css/toolbar.css'; class SysAdmin extends React.Component { constructor(props) { super(props); this.state = { isSidePanelClosed: false, currentTab: 'file-scan', }; } componentDidMount() { let href = window.location.href.split('/'); let currentTab = href[href.length - 2]; const pageList = [ { tab: 'devices', urlPartList: ['desktop-devices', 'mobile-devices', 'device-errors'] }, { tab: 'libraries', urlPartList: ['all-libraries', 'system-library', 'trash-libraries', 'libraries/'] }, ]; const tmpTab = this.getCurrentTabForPageList(pageList); currentTab = tmpTab ? tmpTab : currentTab; this.setState({currentTab: currentTab}); } getCurrentTabForPageList = (pageList) => { let urlPartList, tab; const urlBase = `${siteRoot}sys/`; for (let i = 0, len = pageList.length; i < len; i++) { urlPartList = pageList[i].urlPartList; tab = pageList[i].tab; for (let j = 0, jlen = urlPartList.length; j < jlen; j++) { if (location.href.indexOf(`${urlBase}${urlPartList[j]}`) != -1) { return tab; } } } } onCloseSidePanel = () => { this.setState({isSidePanelClosed: !this.state.isSidePanelClosed}); } tabItemClick = (param) => { this.setState({currentTab: param}); } render() { let { currentTab, isSidePanelClosed } = this.state; return (