Skip to content

Commit ad0b27a

Browse files
author
Rajeev Kumar Singh
committed
initial commit
0 parents  commit ad0b27a

File tree

95 files changed

+15048
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+15048
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

polling-app-client/.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
12+
# misc
13+
.DS_Store
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*

polling-app-client/README.md

+2,433
Large diffs are not rendered by default.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { injectBabelPlugin } = require('react-app-rewired');
2+
const rewireLess = require('react-app-rewire-less');
3+
4+
module.exports = function override(config, env) {
5+
config = injectBabelPlugin(['import', { libraryName: 'antd', style: true }], config);
6+
config = rewireLess.withLoaderOptions({
7+
modifyVars: {
8+
"@layout-body-background": "#FFFFFF",
9+
"@layout-header-background": "#FFFFFF",
10+
"@layout-footer-background": "#FFFFFF"
11+
},
12+
})(config, env);
13+
return config;
14+
};

polling-app-client/package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "polling-app-client",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"antd": "^3.2.2",
7+
"react": "^16.2.0",
8+
"react-dom": "^16.2.0",
9+
"react-router-dom": "^4.2.2",
10+
"react-scripts": "1.1.1"
11+
},
12+
"scripts": {
13+
"start": "react-app-rewired start",
14+
"build": "react-app-rewired build",
15+
"test": "react-app-rewired test --env=jsdom",
16+
"eject": "react-scripts eject"
17+
},
18+
"devDependencies": {
19+
"babel-plugin-import": "^1.6.5",
20+
"react-app-rewire-less": "^2.1.0",
21+
"react-app-rewired": "^1.4.1"
22+
}
23+
}

polling-app-client/public/favicon.png

129 Bytes
Loading

polling-app-client/public/index.html

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

polling-app-client/src/app/App.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.app-content {
2+
margin-top: 64px;
3+
}

polling-app-client/src/app/App.js

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import React, { Component } from 'react';
2+
import './App.css';
3+
import {
4+
Route,
5+
withRouter,
6+
Switch
7+
} from 'react-router-dom';
8+
9+
import { getCurrentUser } from '../util/APIUtils';
10+
import { ACCESS_TOKEN } from '../constants';
11+
12+
import PollList from '../poll/PollList';
13+
import NewPoll from '../poll/NewPoll';
14+
import Login from '../user/login/Login';
15+
import Signup from '../user/signup/Signup';
16+
import Profile from '../user/profile/Profile';
17+
import AppHeader from '../common/AppHeader';
18+
import NotFound from '../common/NotFound';
19+
import LoadingIndicator from '../common/LoadingIndicator';
20+
import PrivateRoute from '../common/PrivateRoute';
21+
22+
import { Layout, notification } from 'antd';
23+
const { Content } = Layout;
24+
25+
class App extends Component {
26+
constructor(props) {
27+
super(props);
28+
this.state = {
29+
currentUser: null,
30+
isAuthenticated: false,
31+
isLoading: false
32+
}
33+
this.handleLogout = this.handleLogout.bind(this);
34+
this.loadCurrentUser = this.loadCurrentUser.bind(this);
35+
this.handleLogin = this.handleLogin.bind(this);
36+
37+
notification.config({
38+
placement: 'topRight',
39+
top: 70,
40+
duration: 3,
41+
});
42+
}
43+
44+
loadCurrentUser() {
45+
this.setState({
46+
isLoading: true
47+
});
48+
getCurrentUser()
49+
.then(response => {
50+
this.setState({
51+
currentUser: response,
52+
isAuthenticated: true,
53+
isLoading: false
54+
});
55+
}).catch(error => {
56+
this.setState({
57+
isLoading: false
58+
});
59+
});
60+
}
61+
62+
componentWillMount() {
63+
this.loadCurrentUser();
64+
}
65+
66+
handleLogout(redirectTo="/", notificationType="success", description="You're successfully logged out.") {
67+
localStorage.removeItem(ACCESS_TOKEN);
68+
69+
this.setState({
70+
currentUser: null,
71+
isAuthenticated: false
72+
});
73+
74+
this.props.history.push(redirectTo);
75+
76+
notification[notificationType]({
77+
message: 'Polling App',
78+
description: description,
79+
});
80+
}
81+
82+
handleLogin() {
83+
notification.success({
84+
message: 'Polling App',
85+
description: "You're successfully logged in.",
86+
});
87+
this.loadCurrentUser();
88+
this.props.history.push("/");
89+
}
90+
91+
render() {
92+
if(this.state.isLoading) {
93+
return <LoadingIndicator />
94+
}
95+
return (
96+
<Layout className="app-container">
97+
<AppHeader isAuthenticated={this.state.isAuthenticated}
98+
currentUser={this.state.currentUser}
99+
onLogout={this.handleLogout} />
100+
101+
<Content className="app-content">
102+
<div className="container">
103+
<Switch>
104+
<Route exact path="/"
105+
render={(props) => <PollList isAuthenticated={this.state.isAuthenticated}
106+
currentUser={this.state.currentUser} handleLogout={this.handleLogout} {...props} />}>
107+
</Route>
108+
<Route path="/login"
109+
render={(props) => <Login onLogin={this.handleLogin} {...props} />}></Route>
110+
<Route path="/signup" component={Signup}></Route>
111+
<Route path="/users/:username"
112+
render={(props) => <Profile isAuthenticated={this.state.isAuthenticated} currentUser={this.state.currentUser} {...props} />}>
113+
</Route>
114+
<PrivateRoute authenticated={this.state.isAuthenticated} path="/poll/new" component={NewPoll} handleLogout={this.handleLogout}></PrivateRoute>
115+
<Route component={NotFound}></Route>
116+
</Switch>
117+
</div>
118+
</Content>
119+
</Layout>
120+
);
121+
}
122+
}
123+
124+
export default withRouter(App);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
.app-title {
2+
float: left;
3+
}
4+
5+
.app-title a {
6+
text-decoration: none;
7+
line-height: 64px;
8+
font-size: 21px;
9+
display: inline-block;
10+
}
11+
12+
.app-title a:hover {
13+
text-decoration: none;
14+
}
15+
16+
.app-header {
17+
position: fixed;
18+
width: 100%;
19+
box-shadow: 0 2px 8px #f0f1f2;
20+
z-index: 10;
21+
padding: 0;
22+
}
23+
24+
.app-menu {
25+
float: right;
26+
}
27+
28+
.app-menu > li {
29+
padding: 0 20px;
30+
}
31+
32+
.app-menu > li > a {
33+
padding: 0 20px;
34+
margin: 0 -20px;
35+
}
36+
37+
.app-menu > li > a > i {
38+
margin-right: 0 !important;
39+
}
40+
41+
.profile-dropdown-menu {
42+
min-width: 180px;
43+
}
44+
45+
.profile-menu .user-full-name-info {
46+
font-size: 17px;
47+
font-weight: 600;
48+
color: rgba(0,0,0,0.85);
49+
}
50+
51+
.profile-menu .username-info {
52+
font-size: 14px;
53+
color: rgba(0,0,0,0.65);
54+
}
55+
56+
.dropdown-item {
57+
padding: 10px 12px;
58+
}
59+
60+
.dropdown-item a {
61+
padding: 10px 12px;
62+
margin: -10px -12px;
63+
}
64+
65+
.nav-icon {
66+
font-size: 20px;
67+
}
68+
69+
.poll-icon {
70+
margin-top: -4px;
71+
}
72+
73+
@media (max-width: 768px) {
74+
.app-title a {
75+
font-size: 20px;
76+
}
77+
78+
.app-menu > li {
79+
padding: 0 15px;
80+
}
81+
82+
.app-menu > li > a {
83+
padding: 0 15px;
84+
margin: 0 -15px;
85+
}
86+
}

0 commit comments

Comments
 (0)