Skip to content

Commit d2650e2

Browse files
author
Saketh Pericherla
committed
tie up client with backend
1 parent 956acd2 commit d2650e2

29 files changed

+29560
-0
lines changed

client/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br>
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br>
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br>
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br>
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br>
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
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.
35+
36+
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.
37+
38+
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.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).

client/package-lock.json

+17,206
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "typescript-app",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"axios": "^0.18.1",
7+
"dateformat": "^3.0.3",
8+
"immutability-helper": "^3.0.1",
9+
"react": "^16.8.6",
10+
"react-dom": "^16.8.6",
11+
"react-router-dom": "^5.0.1",
12+
"react-scripts": "2.1.8",
13+
"semantic-ui-css": "^2.4.1",
14+
"semantic-ui-react": "^0.86.0",
15+
"styled-components": "^4.3.2"
16+
},
17+
"devDependencies": {
18+
"@types/axios": "^0.14.0",
19+
"@types/dateformat": "^3.0.0",
20+
"@types/jest": "24.0.11",
21+
"@types/node": "^14.0.5",
22+
"@types/react": "16.8.13",
23+
"@types/react-dom": "16.8.4",
24+
"@types/react-router-dom": "^4.3.4",
25+
"@types/styled-components": "^4.1.18",
26+
"@types/uuid": "^8.0.0",
27+
"auth0-js": "^9.11.1",
28+
"typescript": "3.9.3"
29+
},
30+
"scripts": {
31+
"start": "react-scripts start",
32+
"build": "react-scripts build",
33+
"test": "react-scripts test",
34+
"eject": "react-scripts eject"
35+
},
36+
"eslintConfig": {
37+
"extends": "react-app"
38+
},
39+
"browserslist": [
40+
">0.2%",
41+
"not dead",
42+
"not ie <= 11",
43+
"not op_mini all"
44+
]
45+
}

client/public/favicon.ico

3.78 KB
Binary file not shown.

client/public/index.html

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<!--
12+
manifest.json provides metadata used when your web app is installed on a
13+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
14+
-->
15+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>React App</title>
26+
</head>
27+
<body>
28+
<noscript>You need to enable JavaScript to run this app.</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>

client/public/manifest.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

client/src/App.css

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 40vmin;
8+
pointer-events: none;
9+
}
10+
11+
.App-header {
12+
background-color: #282c34;
13+
min-height: 100vh;
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
font-size: calc(10px + 2vmin);
19+
color: white;
20+
}
21+
22+
.App-link {
23+
color: #61dafb;
24+
}
25+
26+
@keyframes App-logo-spin {
27+
from {
28+
transform: rotate(0deg);
29+
}
30+
to {
31+
transform: rotate(360deg);
32+
}
33+
}

client/src/App.tsx

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import React, { Component } from "react";
2+
import { Link, Route, Router, Switch } from "react-router-dom";
3+
import { Grid, Menu, Segment } from "semantic-ui-react";
4+
5+
import Auth from "./auth/Auth";
6+
import EditIssue from "./components/EditIssue";
7+
import { LogIn } from "./components/LogIn";
8+
import { NotFound } from "./components/NotFound";
9+
import { Issues } from "./components/Issues";
10+
import { IssueItem } from "./types/Issue";
11+
import { createIssue, deleteIssue } from "./api/issues-api";
12+
13+
export interface AppProps {
14+
auth: Auth;
15+
history: any;
16+
}
17+
18+
export interface AppState {
19+
issues: IssueItem[];
20+
newIssueTitle: string;
21+
loadingAllIssues: boolean;
22+
}
23+
24+
export default class App extends Component<AppProps, AppState> {
25+
state = {
26+
issues: [],
27+
newIssueTitle: "",
28+
loadingAllIssues: true,
29+
};
30+
constructor(props: AppProps) {
31+
super(props);
32+
33+
this.handleLogin = this.handleLogin.bind(this);
34+
this.handleLogout = this.handleLogout.bind(this);
35+
this.onIssueCreate = this.onIssueCreate.bind(this);
36+
this.onIssueDelete = this.onIssueDelete.bind(this);
37+
this.handleTitleChange = this.handleTitleChange.bind(this);
38+
this.saveIssues = this.saveIssues.bind(this);
39+
this.onEditButtonClick = this.onEditButtonClick.bind(this);
40+
}
41+
42+
handleLogin() {
43+
this.props.auth.login();
44+
}
45+
46+
handleLogout() {
47+
this.props.auth.logout();
48+
}
49+
50+
private async onIssueCreate(event: React.ChangeEvent<HTMLButtonElement>) {
51+
try {
52+
const newIssue = await createIssue(this.props.auth.getIdToken(), {
53+
title: this.state.newIssueTitle,
54+
});
55+
56+
this.setState({
57+
issues: [...this.state.issues, newIssue],
58+
newIssueTitle: "",
59+
});
60+
} catch {
61+
alert("IssueItem creation failed");
62+
}
63+
}
64+
65+
private async onIssueDelete(issueId: string) {
66+
try {
67+
await deleteIssue(this.props.auth.getIdToken(), issueId);
68+
this.setState((state) => ({
69+
issues: state.issues.filter((issue) => issue.issueId != issueId),
70+
}));
71+
} catch (err) {
72+
alert(err.message);
73+
}
74+
}
75+
76+
private saveIssues(issues: IssueItem[]) {
77+
this.setState({ issues, loadingAllIssues: false });
78+
}
79+
80+
private handleTitleChange(event: React.ChangeEvent<HTMLInputElement>) {
81+
this.setState({ newIssueTitle: event.target.value });
82+
}
83+
84+
private onEditButtonClick(issueId: string) {
85+
this.props.history.push(`/issues/${issueId}/edit`);
86+
}
87+
88+
render() {
89+
return (
90+
<div>
91+
<Segment style={{ padding: "8em 0em" }} vertical>
92+
<Grid container stackable verticalAlign="middle">
93+
<Grid.Row>
94+
<Grid.Column width={16}>
95+
<Router history={this.props.history}>
96+
{this.generateMenu()}
97+
98+
{this.generateCurrentPage()}
99+
</Router>
100+
</Grid.Column>
101+
</Grid.Row>
102+
</Grid>
103+
</Segment>
104+
</div>
105+
);
106+
}
107+
108+
generateMenu() {
109+
return (
110+
<Menu>
111+
<Menu.Item name="home">
112+
<Link to="/">Home</Link>
113+
</Menu.Item>
114+
115+
<Menu.Menu position="right">{this.logInLogOutButton()}</Menu.Menu>
116+
</Menu>
117+
);
118+
}
119+
120+
logInLogOutButton() {
121+
if (this.props.auth.isAuthenticated()) {
122+
return (
123+
<Menu.Item name="logout" onClick={this.handleLogout}>
124+
Log Out
125+
</Menu.Item>
126+
);
127+
} else {
128+
return (
129+
<Menu.Item name="login" onClick={this.handleLogin}>
130+
Log In
131+
</Menu.Item>
132+
);
133+
}
134+
}
135+
136+
generateCurrentPage() {
137+
if (!this.props.auth.isAuthenticated()) {
138+
return <LogIn auth={this.props.auth} />;
139+
}
140+
141+
return (
142+
<Switch>
143+
<Route
144+
path="/"
145+
exact
146+
render={(props) => {
147+
return (
148+
<Issues
149+
{...props}
150+
auth={this.props.auth}
151+
loadingAllIssues={this.state.loadingAllIssues}
152+
issues={this.state.issues}
153+
saveIssues={this.saveIssues}
154+
onIssueCreate={this.onIssueCreate}
155+
onIssueDelete={this.onIssueDelete}
156+
onEditButtonClick={this.onEditButtonClick}
157+
handleTitleChange={this.handleTitleChange}
158+
/>
159+
);
160+
}}
161+
/>
162+
163+
<Route
164+
path="/issues/:issueId/edit"
165+
exact
166+
render={(props) => {
167+
return (
168+
<EditIssue
169+
{...props}
170+
auth={this.props.auth}
171+
issues={this.state.issues}
172+
/>
173+
);
174+
}}
175+
/>
176+
177+
<Route component={NotFound} />
178+
</Switch>
179+
);
180+
}
181+
}

0 commit comments

Comments
 (0)