Add a landing page

Summary:
This adds a dummy landing page. We’ll want to actually put nice content
on it. For development convenience, I’m totally fine with having the
`yarn start` launch `/explorer` instead of just `/`.

Test Plan:
Run `yarn start` and note that the navigation works.

wchargin-branch: landing-page
This commit is contained in:
William Chargin 2018-07-20 19:03:38 -07:00
parent 6be05e91c8
commit 256582d8b3
5 changed files with 72 additions and 11 deletions

View File

@ -1,19 +1,12 @@
// @flow
import React from "react";
import {IndexRoute, Route, Router, browserHistory} from "react-router";
import {Router, browserHistory} from "react-router";
import Page from "./Page";
import CredExplorer from "./credExplorer/App";
import {createRoutes} from "./routes";
export default class App extends React.Component<{}> {
render() {
return (
<Router history={browserHistory}>
<Route path="/" component={Page}>
<IndexRoute component={CredExplorer} />
</Route>
</Router>
);
return <Router history={browserHistory} routes={createRoutes()} />;
}
}

9
src/app/HomePage.js Normal file
View File

@ -0,0 +1,9 @@
// @flow
import React from "react";
export default class HomePage extends React.Component<{||}> {
render() {
return <h1>Home</h1>;
}
}

View File

@ -1,11 +1,28 @@
// @flow
import React, {type Node} from "react";
import {Link} from "react-router";
import {routeData} from "./routes";
import * as NullUtil from "../util/null";
export default class Page extends React.Component<{|+children: Node|}> {
render() {
return (
<div>
<header>
<nav>
<ul style={{listStyle: "none", paddingLeft: 0, margin: 0}}>
{routeData.map(({navTitle, path}) =>
NullUtil.map(navTitle, (navTitle) => (
<li key={path} style={{display: "inline", marginRight: 10}}>
<Link to={path}>{navTitle}</Link>
</li>
))
)}
</ul>
</nav>
</header>
<main>{this.props.children}</main>
</div>
);

View File

@ -16,7 +16,7 @@ import type {PagerankNodeDecomposition} from "../../core/attribution/pagerankNod
import * as NullUtil from "../../util/null";
type Props = {};
type Props = {||};
type State = {
repoOwner: string,
repoName: string,

42
src/app/routes.js Normal file
View File

@ -0,0 +1,42 @@
// @flow
import React from "react";
import {IndexRoute, Route} from "react-router";
import Page from "./Page";
type RouteDatum = {|
+path: string,
+component: React$ComponentType<{||}>,
+title: string,
+navTitle: ?string,
|};
export const routeData: $ReadOnlyArray<RouteDatum> = [
{
path: "/",
component: require("./HomePage").default,
title: "SourceCred",
navTitle: "Home",
},
{
path: "/explorer",
component: require("./credExplorer/App").default,
title: "SourceCred explorer",
navTitle: "Explorer",
},
];
export function createRoutes() {
return (
<Route path="/" component={Page}>
{routeData.map(({path, component}) => {
if (path === "/") {
return <IndexRoute key={path} component={component} />;
} else {
return <Route key={path} path={path} component={component} />;
}
})}
</Route>
);
}