mirror of
https://github.com/SomboChea/ui
synced 2024-11-05 06:04:28 +07:00
72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
/* eslint react/jsx-max-depth:0 */
|
|
|
|
import React, { Component, ReactElement } from 'react';
|
|
import { Router, Route, Switch } from 'react-router-dom';
|
|
import { AppContextConsumer, AppStateInterface } from './App/App';
|
|
|
|
import { asyncComponent } from './utils/asyncComponent';
|
|
import history from './history';
|
|
import Header from './components/Header';
|
|
|
|
const NotFound = asyncComponent(() => import('./components/NotFound'));
|
|
const VersionPackage = asyncComponent(() => import('./pages/version/Version'));
|
|
const HomePage = asyncComponent(() => import('./pages/home'));
|
|
|
|
interface RouterAppProps {
|
|
onLogout: () => void;
|
|
onToggleLoginModal: () => void;
|
|
}
|
|
|
|
class RouterApp extends Component<RouterAppProps> {
|
|
public render(): ReactElement<HTMLDivElement> {
|
|
return (
|
|
<Router history={history}>
|
|
<>
|
|
{this.renderHeader()}
|
|
<Switch>
|
|
<Route exact={true} path={'/'} render={this.renderHomePage} />
|
|
<Route exact={true} path={'/-/web/detail/@:scope/:package'} render={this.renderVersionPage} />
|
|
<Route exact={true} path={'/-/web/detail/:package'} render={this.renderVersionPage} />
|
|
<Route component={NotFound} />
|
|
</Switch>
|
|
</>
|
|
</Router>
|
|
);
|
|
}
|
|
|
|
public renderHeader = (): ReactElement<HTMLDivElement> => {
|
|
const { onLogout, onToggleLoginModal } = this.props;
|
|
|
|
return (
|
|
<AppContextConsumer>
|
|
{function renderConsumerVersionPage({ logoUrl, scope = '', user }: Partial<AppStateInterface>) {
|
|
return <Header logo={logoUrl} onLogout={onLogout} onToggleLoginModal={onToggleLoginModal} scope={scope} username={user && user.username} />;
|
|
}}
|
|
</AppContextConsumer>
|
|
);
|
|
};
|
|
|
|
public renderHomePage = (): ReactElement<HTMLDivElement> => {
|
|
return (
|
|
<AppContextConsumer>
|
|
{function renderConsumerVersionPage({ isUserLoggedIn, packages }: Partial<AppStateInterface>) {
|
|
// @ts-ignore
|
|
return <HomePage isUserLoggedIn={isUserLoggedIn} packages={packages} />;
|
|
}}
|
|
</AppContextConsumer>
|
|
);
|
|
};
|
|
|
|
public renderVersionPage = (routerProps): ReactElement<HTMLDivElement> => {
|
|
return (
|
|
<AppContextConsumer>
|
|
{function renderConsumerVersionPage({ isUserLoggedIn }: Partial<AppStateInterface>) {
|
|
return <VersionPackage {...routerProps} isUserLoggedIn={isUserLoggedIn} />;
|
|
}}
|
|
</AppContextConsumer>
|
|
);
|
|
};
|
|
}
|
|
|
|
export default RouterApp;
|