UNPKG

@adobe/generator-aio-app

Version:

Adobe I/O application yeoman code generator

93 lines (84 loc) 3.06 kB
/* <% if (false) { %> Copyright 2019 Adobe. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. <% } %> * <license header> */ import React from 'react' import { Provider, defaultTheme, Grid, View } from '@adobe/react-spectrum' import ErrorBoundary from 'react-error-boundary' import { HashRouter as Router, Switch, Route } from 'react-router-dom' import SideBar from './SideBar' import ActionsForm from './ActionsForm' import { Home } from './Home' import { About } from './About' function App (props) { console.log('runtime object:', props.runtime) console.log('ims object:', props.ims) // use exc runtime event handlers // respond to configuration change events (e.g. user switches org) props.runtime.on('configuration', ({ imsOrg, imsToken, locale }) => { console.log('configuration change', { imsOrg, imsToken, locale }) }) // respond to history change events props.runtime.on('history', ({ type, path }) => { console.log('history change', { type, path }) }) return ( <ErrorBoundary onError={onError} FallbackComponent={fallbackComponent}> <Router> <Provider theme={defaultTheme} colorScheme={`light`}> <Grid areas={['sidebar content']} columns={['256px', '3fr']} rows={['auto']} height='100vh' gap='size-100' > <View gridArea='sidebar' backgroundColor='gray-200' padding='size-200' > <SideBar></SideBar> </View> <View gridArea='content' padding='size-200'> <Switch> <Route exact path='/'> <Home></Home> </Route> <Route path='/actions'> <ActionsForm runtime={props.runtime} ims={props.ims} /> </Route> <Route path='/about'> <About></About> </Route> </Switch> </View> </Grid> </Provider> </Router> </ErrorBoundary> ) // Methods // error handler on UI rendering failure function onError (e, componentStack) { } // component to show if UI fails rendering function fallbackComponent ({ componentStack, error }) { return ( <React.Fragment> <h1 style={{ textAlign: 'center', marginTop: '20px' }}> Something went wrong :( </h1> <pre>{componentStack + '\n' + error.message}</pre> </React.Fragment> ) } } export default App