import React, {Component} from 'react'; import {Helmet} from "react-helmet"; import TopAppBar, {TopAppBarFixedAdjust} from '@material/react-top-app-bar'; import Drawer, {DrawerAppContent, DrawerContent, DrawerHeader, DrawerTitle} from '@material/react-drawer'; import List, {ListItem, ListItemGraphic, ListItemText} from '@material/react-list'; import Select from '@material/react-select'; import MaterialIcon from '@material/react-material-icon'; import './App.scss'; class App extends Component { constructor(props) { super(props) this.state = { buildings: [], open: false, selectedBuilding: {}, selectedIndex: 0 } } componentDidMount = () => { fetch('pages.json') .then(r => r.json()) .then(data =>{ // map pages entries const buildings = data.map(entry => ({ label: entry.instance, value: entry.instance.replace(/\s/g, "").toLowerCase(), entries: entry.entries }) ) console.log(buildings) this.setState ({ buildings: buildings, open: false, selectedBuilding: buildings[0], selectedIndex: 0 }) }) } logoImg = Logo; // Drawer navigation navigateToIndex = (index) => { console.log(this.pgs) this.setState({open: false}); this.setState({selectedIndex: index}); } // Building navigation navigateBuilding = (selection) => { const v = selection.target.value; const b = this.state.buildings.find(e => e.value === v ) // ensure selection fits index if(this.state.selectedIndex >= b.entries.length){ this.setState({selectedIndex: 0}); } this.setState({selectedBuilding: b}, () => this.navigateToIndex(this.state.selectedIndex) ); } // Drawer List Elements entries = () => this.state.selectedBuilding.entries.map((entry, index) => } /> ) render() { const {buildings} = this.state return !buildings.length ? ("Loading"):(
Building Manager
this.setState({open: false})}> {this.logoImg} {this.entries()} this.setState({open: !this.state.open})}/>} />
); } } export default App;