Refactored App component from index.tsx

This commit is contained in:
Przemek Wiech
2019-02-24 23:04:45 +01:00
parent e6be58c20b
commit 4625b0c44c
2 changed files with 43 additions and 33 deletions

40
src/app.tsx Normal file
View File

@@ -0,0 +1,40 @@
import * as React from 'react';
import {ChartView} from './chart_view';
import {Route, RouteComponentProps, Switch} from 'react-router-dom';
import {Intro} from './intro';
import {TopBar} from './top_bar';
export class App extends React.Component<{}, {}> {
chartViewRef?: ChartView;
render() {
return (
<div className="root">
<Route
component={(props: RouteComponentProps) => (
<TopBar
{...props}
onPrint={() => this.chartViewRef && this.chartViewRef.print()}
onDownloadSvg={() =>
this.chartViewRef && this.chartViewRef.downloadSvg()
}
onDownloadPng={() =>
this.chartViewRef && this.chartViewRef.downloadPng()
}
/>
)}
/>
<Switch>
<Route exact path="/" component={Intro} />
<Route
exact
path="/view"
component={(props: RouteComponentProps) => (
<ChartView {...props} ref={(ref) => (this.chartViewRef = ref!)} />
)}
/>
</Switch>
</div>
);
}
}