Commit dd0cd20e by Shahanas khan

initial commit

parents
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "accubits_test",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.56",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.20.0",
"classnames": "^2.2.6",
"connected-react-router": "^6.8.0",
"history": "^4.10.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-google-charts": "^3.0.15",
"react-redux": "^7.2.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Karla"
/>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<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.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
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>
</head>
<body bgcolor="#f5f5fb">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
/** @format */
export const BASE_URL = "https://u50g7n0cbj.execute-api.us-east-1.amazonaws.com/v2/";
import React from "react";
import { Switch, Route } from "react-router-dom";
import State from "../screens/state";
import Map from "../screens/maps";
const Router = () => {
return (
<Switch><Route exact path="/" component={State} />
<Route exact path="/maps/" component={Map} />
</Switch>
);
};
export default Router;
import React from "react";
import { Provider } from "react-redux";
import store, { history } from "../store/configureStore";
import { HashRouter } from "react-router-dom";
import Routing from "./app";
const AppContaner = () => {
return (
<Provider store={store}>
<HashRouter history={history}>
<Routing />
</HashRouter>
</Provider>
);
};
export default AppContaner;
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./app";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
import { connect } from "react-redux";
import { withRouter } from "react-router";
import { push } from "connected-react-router";
import Map from "./maps";
function mapStateToProps(state) {
return {
countryDetails: state.pollutionData.data,
pollutionDetails: state.pollutionData.data2,
};
}
function mapDispatchToProps(dispatch) {
return {
navigateTo: (url) => dispatch(push(url)),
};
}
export default withRouter(
connect(mapStateToProps, mapDispatchToProps)(Map)
);
import React, { Component } from "react";
import Chart from "react-google-charts";
import AppBar from "@material-ui/core/AppBar";
import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos';
import {
Grid,Paper,Toolbar,Typography,TableHead,TableRow,TableCell,Table,TableBody,TextField,IconButton,
} from "@material-ui/core";
import Autocomplete from "@material-ui/lab/Autocomplete";
class mapDetails extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
states: "",
show: false,
};
}
componentDidMount() {
if (this.props.pollutionDetails !== "") {
let dataas = this.props.pollutionDetails;
// console.log(dataas)
let cities = dataas.results;
this.setState({ data2s: cities });
// console.log(this.state.data2s);
}
else {
this.props.navigateTo("/");
}
}
handleState = (e, value) => {
e.preventDefault();
if (value === null) {
this.setState({ mapData: "" });
} else {
this.setState({ mapData: value.city,
pollutionArray:value.parameters
,
show: true,}
)
}
};
render() {
console.log(this.state);
let a= this.state.pollutionArray;
let poldata= a?.length?a[0]:[];
// console.log(poldata);
let entries1 = a?.length
? a.map((item, i) => {
return [item.displayName, parseInt(item.count)];
})
: [];
console.log(entries1)
entries1.unshift(["parameters", "count"]);
console.log(entries1);
return (
<div>
<Grid >
<Paper >
<AppBar position="static" color="secondary">
<IconButton
edge="start"
color="inherit"
aria-label="menu"
>
<Typography
style={{ fontSize:"30px" }}
variant="h6" >
World Pollution Details
</Typography>
</IconButton>
</AppBar>
<Toolbar >
<IconButton
style={{ paddingTop:"15px",}}
onClick={(e) => {
this.props.navigateTo("/");
}}
>
<ArrowBackIosIcon style={{ color:"#FF007F"}} />
</IconButton>
<Typography
variant="h6"
id="tableTitle"
style={{ fontSize:"25px" , paddingTop:"5px"}}
>
select a city
</Typography>
&nbsp;
&nbsp;
&nbsp;
<div style={{paddingTop:"60px"}} />
<Autocomplete
options={this.state.data2s ? this.state.data2s : null}
getOptionLabel={(option) =>
option.city ? option.city : ""
}
onChange={this.handleState}
value={this.state.mapData}
renderInput={(params) => (
<TextField
fullWidth
style={{ height: "40px",
width: "250px",}}
label="Select city"
id="outlined-margin-dense"
margin="dense"
variant="outlined"
required
name="mapData"
{...params}
></TextField>
)}
/>
</Toolbar>
</Paper>
{
this.state.show == true? (
<div style={{paddingLeft:"150px",paddingRight:"150px"}}>
<div >
<h2>Pollution Map of {this.state.mapData}</h2>
</div>
<br></br>
<Chart
width={"100%"}
height={"250px"}
chartType="Bar"
// loader={<div>Loading Chart</div>}
data={entries1}
options={{
chart: {
title: 'Parameter and Counts',
subtitle: 'This graph shows the various environmental pollution parameters v/s its counts',
},
}}
rootProps={{ "data-testid": "2" }}
/>
</div>
) :(null)
}
</Grid>
</div>
);
}
}
export default mapDetails;
import {
GET_COUNTRY_DETAILS,
GET_COUNTRY_DETAILS_ERROR,
GET_POLLUTION_DETAILS,
GET_POLLUTION_DETAILS_ERROR,
} from "./constants";
import stateService from "../../../services/stateService";
export const getcountryDetails= () => {
return (dispatch) => {
new stateService().getStateDetails().then((response) => {
if (response.data) {
dispatch(success(response.data));
} else {
dispatch(failure(response));
}
});
};
function success(data) {
return { type: GET_COUNTRY_DETAILS, data };
}
function failure(error) {
return { type: GET_COUNTRY_DETAILS_ERROR, error };
}
};
export const getPollutionDetails= (id) => {
return (dispatch) => {
new stateService().getMapDetails(id).then((response) => {
if (response.data) {
dispatch(success(response.data));
} else {
dispatch(failure(response));
}
});
};
function success(data) {
return { type: GET_POLLUTION_DETAILS, data };
}
function failure(error) {
return { type: GET_POLLUTION_DETAILS_ERROR, error };
}
};
export const GET_COUNTRY_DETAILS = "GET_COUNTRY_DETAILS";
export const GET_COUNTRY_DETAILS_ERROR = "GET_COUNTRY_DETAILS_ERROR";
export const GET_POLLUTION_DETAILS = "GET_POLLUTION_DETAILS"
export const GET_POLLUTION_DETAILS_ERROR = "GET_POLLUTION_DETAILS_ERROR"
import {
GET_COUNTRY_DETAILS,
GET_COUNTRY_DETAILS_ERROR,
GET_DISTRICT_DATA,
GET_POLLUTION_DETAILS,
GET_POLLUTION_DETAILS_ERROR
} from "./constants";
const initialState = {
data: [],
data2: [],
districtData: "",
};
export default function (state = initialState, action) {
switch (action.type) {
case GET_COUNTRY_DETAILS:
return {
...state,
data: action.data,
};
case GET_COUNTRY_DETAILS_ERROR:
return {
...state,
};
case GET_POLLUTION_DETAILS:
return {
...state,
data2: action.data,
};
case GET_POLLUTION_DETAILS_ERROR:
return {
...state,
};
default:
return state;
}
}
import { connect } from "react-redux";
import { withRouter } from "react-router";
import { push } from "connected-react-router";
import States from "./states";
import { getcountryDetails, getPollutionDetails } from "./data/action";
function mapDispatchToProps(dispatch) {
return {
getcountryDetails: () => dispatch(getcountryDetails()),
getPollutionDetails: (id) => dispatch(getPollutionDetails(id)),
navigateTo: (url) => dispatch(push(url)),
};
}
function mapStateToProps(state) {
return {
countryDetails: state.pollutionData.data,
pollutionDetails: state.pollutionData.data2,
};
}
export default withRouter(
connect(mapStateToProps, mapDispatchToProps)(States)
);
import React, { Component } from "react";
import {
Grid,Paper,Toolbar,Typography,TableHead,TableRow,TableCell,Table,TableBody,TextField,IconButton,
} from "@material-ui/core";
import Autocomplete from "@material-ui/lab/Autocomplete";
import AppBar from "@material-ui/core/AppBar";
import ArrowForwardIosIcon from '@material-ui/icons/ArrowForwardIos';
class stateDetails extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
state_filter: "",
};
}
componentDidMount() {
this.props.getcountryDetails();
}
componentDidUpdate(prevProps, prevState) {
if (prevProps.countryDetails !== this.props.countryDetails) {
let dataas = this.props.countryDetails;
let countries = dataas.results;
this.setState({ data: countries });
console.log(this.state.data);
}
}
handleState = (e, value) => {
e.preventDefault();
if (value === null) {
this.setState({ state_filter: "" });
} else {
this.setState({ state_filter: value.name,
code:value.code}
,
() => {
this.props.getPollutionDetails(this.state.code)
this.setState({
...this.state,
mapdata: this.props.pollutionDetails
});
console.log(this.state);
}
)
}
};
// callMapDetails(prevProps, prevState){
// if (prevProps.pollutionDetails !== this.props.pollutionDetails) {
// let data2 = this.props.pollutionDetails;
// console.log(data2);
// }
// }
viewMap = (data) => {
this.setState({
...this.state,
mapdata: this.props.pollutionDetails
});
console.log(this.state)
this.props.navigateTo("/maps/");
};
render() {
const { mapdata } = this.state;
console.log(mapdata
);
return (
<div>
<Grid >
<Paper >
<AppBar position="static" color="secondary">
{/* <Toolbar> */}
<IconButton
edge="start"
color="inherit"
aria-label="menu"
>
<Typography
style={{ fontSize:"30px" }}
variant="h6" >
World Pollution Details
</Typography>
</IconButton>
{/* </Toolbar> */}
</AppBar>
<Toolbar >
<Typography
variant="h6"
id="tableTitle"
style={{ fontSize:"25px" , paddingTop:"10px"}}
>
Choose Country
</Typography>
&nbsp;
&nbsp;
&nbsp;
<div style={{paddingTop:"60px"}} />
<Autocomplete
options={this.state.data ? this.state.data : null}
getOptionLabel={(option) =>
option.name ? option.name : ""
}
onChange={this.handleState}
value={this.state.state_filter}
renderInput={(params) => (
<TextField
fullWidth
style={{ height: "40px",
width: "250px",}}
label="Select State"
id="outlined-margin-dense"
margin="dense"
variant="outlined"
required
name="state_filter"
{...params}
></TextField>
)}
/>
</Toolbar>
</Paper>
{
this.state.state_filter != "" ? (
<div style={{paddingLeft:"150px"}}>
<div>
<h2>You have choosen {this.state.state_filter}</h2>
</div>
<br></br>
<h3>
Please click <button style={{color:"blue", backgroundColor:"yellow"}} onClick={this.viewMap}><h3>here</h3></button> to view the pollution details of various citites of {this.state.state_filter}
</h3>
<br></br>
<h3>
If you want to change the country you can also select from the dropdown
</h3>
</div>
) :(null)
}
</Grid>
</div>
);
}
}
export default (stateDetails);
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' },
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
})
.catch(error => {
console.error(error.message);
});
}
}
/** @format */
import axios from "axios";
import { BASE_URL } from "../../apiConfig";
import { onRequest, onRequestError } from "./interceptors/requestInterceptor";
import {
onResponse,
onResponseError,
} from "./interceptors/responseInterceptor";
const API = () => {
const defaultOptions = {
baseURL: BASE_URL,
headers: {
"Content-Type": "application/json",
},
};
const instance = axios.create(defaultOptions);
instance.interceptors.request.use(
(config) => onRequest(config),
(error) => onRequestError(error)
);
instance.interceptors.response.use(
(response) => onResponse(response),
(error) => onResponseError(error)
);
return instance;
};
export default API();
import API from "./api";
export default async (options) => {
try {
return await API(options);
} catch (e) {
return e;
}
};
export const onRequest = (config) => {
return config;
};
export const onRequestError = (error) => {
return error;
};
export const onResponse = (response) => {
response.headers["Cache-Control"] = "no-store";
return response;
};
export const onResponseError = (error) => {
const responseError = { ...error };
if (error.response === undefined) {
responseError.error = {
message: "Network Error, Please check your internet connection",
};
return responseError;
} else if (error.response.status === 400) {
responseError.error = {
message: "Bad Request. Please try after some time.",
};
} else {
responseError.error = {
message: "Service unavailable. Please try after some time.",
};
}
return responseError;
};
import APIRequest from "./api/apiRequest";
class stateService {
getStateDetails = (params) => {
return APIRequest({
url: `countries`,
method: "GET",
params
});
};
getMapDetails = (params) => {
return APIRequest({
url: `locations?country=${params}`,
method: "GET",
});
};
}
export default stateService;
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import { createStore, applyMiddleware, compose } from "redux";
import { routerMiddleware } from "connected-react-router";
import { createHashHistory } from "history";
import thunk from "redux-thunk";
import createRootReducer from "./rootReducer";
export const history = createHashHistory();
const middleware = [thunk, routerMiddleware(history)];
const initialState = {};
const store = createStore(
createRootReducer(history),
initialState,
compose(applyMiddleware(...middleware))
);
export default store;
import { combineReducers } from "redux";
import { connectRouter } from "connected-react-router";
import pollutionData from "../screens/state/data/reducer";
export default (history) =>
combineReducers({
router: connectRouter(history),
pollutionData,
});
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment