Skip to content

Commit

Permalink
Init git
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Nov 13, 2018
1 parent 7a67332 commit d725052
Show file tree
Hide file tree
Showing 15 changed files with 908 additions and 281 deletions.
44 changes: 0 additions & 44 deletions README.md
@@ -1,44 +0,0 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
Empty file added now.json
Empty file.
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -3,9 +3,12 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^3.4.0",
"moment": "^2.22.2",
"react": "^16.6.1",
"react-dom": "^16.6.1",
"react-scripts": "2.1.1"
"react-scripts": "2.1.1",
"victory": "^30.6.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
19 changes: 10 additions & 9 deletions public/index.html
@@ -1,15 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand All @@ -19,12 +22,10 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Stocks App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root"></div>
<!--
This HTML file is a template.
Expand Down
32 changes: 0 additions & 32 deletions src/App.css

This file was deleted.

53 changes: 33 additions & 20 deletions src/App.js
@@ -1,28 +1,41 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import React, { Component } from "react";
import StockTable from "./StockTable";

// import StockChart from './StockChart';

const StockChart = React.lazy(() =>
import(/* webpackChunkName: 'Chart' */ "./StockChart")
);

// const ChartPromise = import(/* webpackChunkName: 'StockChart' */ "./StockChart");
// const StockChart = React.lazy(() => ChartPromise);

class App extends Component {
state = {
selectedStock: null
};
render() {
const { stocks } = this.props;
const { selectedStock } = this.state;
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<React.Suspense fallback={<div>Loading...</div>}>
<StockTable
stocks={stocks}
onSelect={selectedStock => this.setState({ selectedStock })}
/>
{/* <div hidden={true}>
<React.Suspense fallback={<div>Loading...</div>}>
<Chart data={[]} />
</React.Suspense>
</div> */}
{selectedStock && (
<StockChart
stock={selectedStock}
onClose={() => this.setState({ selectedStock: false })}
/>
)}
</React.Suspense>
);
}
}

export default App;
9 changes: 0 additions & 9 deletions src/App.test.js

This file was deleted.

68 changes: 68 additions & 0 deletions src/Modal.js
@@ -0,0 +1,68 @@
import React from "react";

const Modal = ({ children, onClose }) => (
<Overlay onClose={onClose}>
<Content onClose={onClose}>{children}</Content>
</Overlay>
);

const Overlay = ({ children, onClose }) => (
<div
children={children}
style={{
background: "hsla(0, 0%,0%,0.33)",
position: "fixed",
top: 0,
right: 0,
bottom: 0,
left: 0,
overflow: "auto",
display: "flex",
alignItems: "center",
justifyContent: "center"
}}
onClick={event => {
event.stopPropagation();
onClose();
}}
/>
);

const Content = ({ children, onClose }) => (
<div
onClick={event => {
event.stopPropagation();
}}
style={{
background: "white",
outline: "none",
position: "relative",
borderRadius: "10px"
}}
aria-modal="true"
tabIndex="-1"
>
<CloseButton onClick={onClose} />
{children}
</div>
);

const CloseButton = ({ onClick }) => (
<button
style={{
position: "absolute",
top: 18,
right: 18,
backgroundColor: "transparent",
border: "none",
cursor: "pointer",
zIndex: 10,
color: "#777"
}}
onClick={onClick}
>
close
</button>
);

export default Modal;
73 changes: 73 additions & 0 deletions src/StockChart.js
@@ -0,0 +1,73 @@
import React from "react";
import {
VictoryLine,
VictoryChart,
VictoryContainer,
VictoryLabel,
VictoryAxis
} from "victory";
import Modal from "./Modal";
import moment from "moment";

export default function Chart({ stock, onClose }) {
const [first, ...rest] = Object.values(stock.data);
const [last] = rest.reverse();
const up = last.y >= first.y;
const { width, height } = getDimentions();
return (
<Modal onClose={onClose}>
<VictoryChart
domain={{ y: [80, 220] }}
height={height}
width={width}
containerComponent={<VictoryContainer responsive={false} />}
>
<VictoryLabel
text={stock.name}
x={width / 2}
y={30}
textAnchor="middle"
style={{ fontSize: "18px", fontWeight: "bold" }}
/>
<VictoryLine
data={stock.data}
labels={d => d.y}
x={d => moment(d.x).format("MMM D")}
style={{
labels: { opacity: 0.75 },
data: { stroke: up ? "darkgreen" : "darkred", strokeWidth: 3 }
}}
/>
<VictoryAxis
style={{
axis: { stroke: "" },
tickLabels: { opacity: 0.75, fontSize: "17px" }
}}
/>
</VictoryChart>
</Modal>
);
}

function getDimentions() {
const viewportWidth = Math.max(
document.documentElement.clientWidth,
window.innerWidth || 0
);
const viewportHeight = Math.max(
document.documentElement.clientHeight,
window.innerHeight || 0
);

const maxWidth = 600;
const mobileViewportWidth = 500;
let width = viewportWidth;
width *= viewportWidth > mobileViewportWidth ? 0.9 : 1;
width = Math.round(Math.min(width, maxWidth));

const maxHeight = viewportHeight * 0.95;
let height = width / 1.62;
height = Math.round(Math.min(height, maxHeight));

return { width, height };
}
26 changes: 26 additions & 0 deletions src/StockTable.js
@@ -0,0 +1,26 @@
import React from "react";

export default function StockTable({ stocks, onSelect }) {
return (
<table>
<caption>Stocks</caption>
<tbody>
{stocks.map(stock => (
<Row key={stock.name} stock={stock} onClick={() => onSelect(stock)} />
))}
</tbody>
</table>
);
}

function Row({ stock, onClick }) {
return (
<tr key={stock.name} onClick={onClick}>
<td>{stock.name}</td>
<td>{stock.today}</td>
<td style={{ color: stock.change < 0 ? "darkred" : "darkgreen" }}>
{stock.change < 0 ? stock.change : "+" + stock.change}%
</td>
</tr>
);
}

0 comments on commit d725052

Please sign in to comment.