16 | )
17 |
18 | export default Listing;
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 |
2 | # gwg-women-techmakers
3 | This is a Grow with Google project for an offline first app that provides information based on location and search.
4 |
5 | ## Getting Started
6 | Read the the [Set Up Instructions](https://github.com/gwg-women/gwg-women-techmakers/wiki/Set-Up-Instructions) on our wiki.
7 |
8 | ## Contributing to the Project
9 | Please read the [contribution guidelines](https://github.com/gwg-women/gwg-women-techmakers/wiki/Contribution-Guidelines) on the wiki to see how to get started with solving issues and creating pull requests.
10 |
11 | ## Pending
12 | - Whether we use geolocation or use the search box instead
13 |
14 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Mappa
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mappa",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "cra-append-sw": "^2.1.1",
7 | "google-maps-react": "^1.1.2",
8 | "install": "^0.10.4",
9 | "npm": "^5.7.1",
10 | "react": "^16.2.0",
11 | "react-dom": "^16.2.0",
12 | "react-scripts": "1.1.1",
13 | "serve": "^6.5.0"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start && cra-append-sw --mode dev ./public/sw.js",
17 | "build": "react-scripts build && cra-append-sw --mode build --skip-compile ./public/sw.js",
18 | "test": "react-scripts test --env=jsdom",
19 | "eject": "react-scripts eject",
20 | "now-start": "serve --single ./build"
21 | },
22 | "devDependencies": {
23 | "react-axe": "^3.0.1"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/services/weather.js:
--------------------------------------------------------------------------------
1 | const http = require('http');
2 |
3 | export function getWeather(lat, lng){
4 | let weather;
5 | const weather_api = process.env.REACT_APP_WEATHERKEY;
6 |
7 | return new Promise(function(resolve, reject){
8 | if(typeof weather_api === 'undefined'){
9 | console.log('Please set up your weather key to return weather details.');
10 | reject();
11 | } else {
12 | const url = `https://api.openweathermap.org/data/2.5/weather?units=Imperial&lat=${lat}&lon=${lng}&APPID=${weather_api}`;
13 |
14 | http.get(url, (res) => {
15 | res.setEncoding('utf8');
16 | res.on('data', (data) => {
17 | data = JSON.parse(data);
18 | weather = data.main.temp;
19 | resolve(weather);
20 | })
21 | });
22 | }
23 | })
24 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 tanyagupta
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/components/PlacesListItem.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const PlacesListItem = (props) => (
4 |
60 | )
61 | }
62 | }
63 |
64 | export default GoogleApiWrapper({
65 | apiKey: (process.env.REACT_APP_GKEY),
66 | libraries: ['places']
67 | })(Search)
--------------------------------------------------------------------------------
/src/services/googlePlaces.js:
--------------------------------------------------------------------------------
1 | const http = require('https');
2 |
3 | export default function getPlaces(lat, lng, query){
4 | let Listings =[];
5 | let location = {latitude:0,
6 | longitide:0}
7 | location.latitude=lat;
8 | location.longitide=lng;
9 | console.log('in get places');
10 |
11 | const google_api = process.env.REACT_APP_GKEY;
12 |
13 | const url = `https://maps.googleapis.com/maps/api/place/textsearch/json?query=${query}&key=${google_api}&location=${lat},${lng}&radius=5000`;
14 |
15 |
16 | const GOOGLE_PLACES_OPTIONS = {
17 | method: 'GET',
18 | hostname: 'www.googleapis.com',
19 | port: null,
20 | path: `/geolocation/v1/geolocate?key=${google_api}`,
21 | headers: {
22 | 'content-type': 'application/json',
23 | 'cache-control': 'no-cache',
24 | }
25 | };
26 |
27 |
28 | return new Promise(function(resolve, reject){
29 | console.log('in place promise');
30 | http.get(url, (res) => {
31 | if(res.statusCode == 'OK'){
32 | console.log(" OK ");
33 | res.setEncoding('utf8');
34 | res.on('data', (data) => {
35 | data = JSON.parse(data);
36 | if(data.results.length >= 0){
37 | Listings = data.results;
38 | console.log(Listings);
39 | resolve(Listings);
40 | }
41 | })
42 | } else if(res.statusCode != 'ZERO_RESULTS'){
43 | console.log("error" + res.statusCode);
44 | reject();
45 | }
46 | });
47 | });
48 |
49 | }
50 |
51 |
52 | /* NOTES : Getting CORS error
53 |
54 | localhost/:1 Failed to load https://maps.googleapis.com/maps/api/place/textsearch/json?query=food&key=AIzaSyAR9_HMLChf4WdyDIX3ZuDF6pZYqi9aZDI&location=40.854885,-88.081807&radius=5000: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
55 | localhost/:1 Uncaught (in promise) TypeError: Failed to fetch
56 |
57 | Also, couldn't find a wasy to use the env variables
58 | api = process.env.API_KEY; is not working
59 | */
--------------------------------------------------------------------------------
/public/sw.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | const CACHE_NAME = 'maapa-cache-v15';
4 |
5 | const urlsToCache =[
6 | '/',
7 | '/static/js/main.bd8fcf5f.js',
8 | '/static/css/main.181bbb8b.css',
9 | '/index.html',
10 | ];
11 |
12 | function createDB() {
13 | idb.open('mappa', 1, function(upgradeDB){
14 | var store = upgradeDB.createObjectStore('weather')
15 | })
16 | };
17 |
18 | // The first time the user starts up the app, 'install' is triggered.
19 | self.addEventListener('install', function(event) {
20 | // if (doCache) {
21 | event.waitUntil(
22 | caches.open(CACHE_NAME)
23 | .then(function(cache) {
24 | return cache.addAll(urlsToCache)
25 | })
26 | );
27 | // }
28 | });
29 |
30 | self.addEventListener("activate", function(event) {
31 | const cacheWhitelist = [CACHE_NAME];
32 | event.waitUntil(
33 | caches.keys()
34 | .then(keyList =>
35 | Promise.all(keyList.map(key => {
36 | if (!cacheWhitelist.includes(key)) {
37 | return caches.delete(key);
38 | }
39 | }))
40 | )
41 | );
42 | });
43 |
44 |
45 | // When the webpage goes to fetch files, we intercept that request and serve up the matching files
46 | // if we have them
47 | self.addEventListener('fetch', function (event) {
48 | const requestUrl = new URL(event.request.url)
49 |
50 | if (requestUrl.pathname.startsWith('/maps/api/staticmap')) {
51 | event.respondWith(
52 | caches.open(CACHE_NAME).then(function (cache) {
53 | return cache.match(event.request).then(function (response) {
54 | console.log("caching All request: ", requestUrl, " Response: ", response)
55 | return response || fetch(event.request).then(function (response) {
56 | cache.put(event.request, response.clone())
57 | return response;
58 | })
59 | .catch(function () {
60 | // console.log('in catch fetch for request: ', requestUrl.pathname);
61 | if (requestUrl.pathname.startsWith('/maps/api/js')) {
62 | return caches.match('maps/api/staticmap')
63 | }
64 | })
65 | })
66 | })
67 | )
68 | }
69 | });
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/docs/contributionguidelines.md:
--------------------------------------------------------------------------------
1 | Thanks for joining the GWG Women Techmakers team!
2 |
3 | ## Issues
4 | Assign yourself an issue you're interested in helping with.
5 |
6 | ## Branches
7 |
8 | We're all working off of the "dev" branch.
9 |
10 | Click the "Fork" button. Once you've done that, you can use your favorite git client to clone your repository or just head straight to the command line:
11 |
12 | Clone your fork to your local machine
13 | `git clone https://github.com//gwg-women-techmakers.git`
14 |
15 | To keep your fork up to date by tracking the original "upstream" repository that you forked. To do this, you'll need to add a remote:
16 | `git remote add upstream https://github.com/gwg-women/gwg-women-techmakers.git`
17 |
18 | After you've set up your local environment and assigned yourself an issue, follow these steps for contributing to the project:
19 | 1. Always pull in new updates from "dev" branch before getting started and pull and push to sync your local repository:
20 | `git checkout dev`
21 | `git pull upstream dev`
22 | `git push origin dev`.
23 |
24 | 2. Create a new branch for our particular issue: `git checkout -b `
25 | 3. Make your changes to solve that issue.
26 | 4. Commit early, commit often! If you have a large issue that takes time, it's best to save your work on your machine and on Github often. For Github:
27 | - `git add -A'
28 | - 'git commit -m "I did these things during this save"`
29 | - `git push`
30 | - The first push will ask you to create that branch to your fork on Github. Just follow it's instructions.
31 | 5. When you're ready to submit your changes, create a pull request in the branch containing your changes from your forked repository. For more details refer :[GitHub : Creating the Pull Request](https://help.github.com/articles/creating-a-pull-request/)
32 | 6. Fill out the pull request with these questions in mind:
33 | - What issue does it solve? Identify it with a `#` and the number, which will connect your issue and pull request automatically.
34 | - What did you do to solve the issue? Just a brief list of updates is good.
35 | - How can we test this to be sure it works?
36 | 7. Assign a couple teammates to review your pull request and submit.
37 | 8. Once it has been approved and merged, please delete your branch.
38 |
--------------------------------------------------------------------------------
/README_do_not_edit_on_dev.md:
--------------------------------------------------------------------------------
1 | # gwg-women-techmakers
2 | This is a Grow with Google project for an offline first app that provides information based on location and search.
3 |
4 | ## Getting Started
5 | Read the the [Set Up Instructions](https://github.com/gwg-women/gwg-women-techmakers/wiki/Set-Up-Instructions) on our wiki.
6 |
7 | ## Contributing to the Project
8 | Please read the [contribution guidelines](https://github.com/gwg-women/gwg-women-techmakers/wiki/Contribution-Guidelines) on the wiki to see how to get started with solving issues and creating pull requests.
9 |
10 |
11 | ## The repository uses the following files :
12 |
13 | * **public/index.html** : The main HTML page. Contains links to all of the CSS resources needed to render the map and results. It also loads results of Google Maps API asyncronously.
14 |
15 | * **src/index.js**: is the JavaScript entry point.
16 |
17 | * **src/components**: Contains all the controls.
18 | ***Description.js**
19 | Contains the Wiki component that displays the wikipedia information about the current city.
20 |
21 | ***Header.js***
22 | Get's the current location and weather conditions and displays the information on the header.
23 |
24 | ***InitialMap.js***
25 | Get's and displays the map with markers to the search results.
26 |
27 | ***Places.js***
28 | Displays the searchResults in the form of a list on the leftside of the app.
29 |
30 | ***PlacesListItem.js***
31 | Contains the ListItems control that displays all the list items. It displays the name address and opening hours of a place.
32 |
33 | ***Search.js***
34 | Get's the user Input for search query.
35 |
36 | * **src/css/index.css**
37 | Contains the styles of the App
38 |
39 | * **src/services** folder has the code that makes calls to the location, map and weather API's and fetches their results.
40 |
41 | ***geolocation.js***
42 |
43 | ***weather.js***
44 |
45 | * **registerServiceWorker.js** checks for and registers the service worker for the application.
46 |
47 | ## Some Packages Used ##
48 | npm
49 |
50 | react
51 |
52 | react-dom
53 |
54 | react-scripts
55 |
56 | cra-append-sw
57 |
58 | google-maps-react
59 |
60 |
61 | ## Motivation
62 |
63 | This project is made as part of the GROW With GOOGLE Challenge for practicing
64 | * Creating Progressive web apllications
65 | * Registering and create a service worker
66 | * Creatinf a REACT web application
67 | * Colaborationg using GIT
68 | * Interacting with API servers
69 | * Use of third-party libraries and APIs
70 | * Use Google Maps
71 |
--------------------------------------------------------------------------------
/src/components/Header.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import {getCity} from '../services/geolocation.js';
3 | import {getWeather} from '../services/weather.js';
4 | import {GoogleApiWrapper} from 'google-maps-react';
5 | import Image from '../img/24.png';
6 |
7 | class HeaderContainer extends Component {
8 | state = {};
9 |
10 | componentDidMount() {
11 | this.getMyLocation();
12 | }
13 |
14 | componentWillUpdate(prevProps, prevState) {
15 | if (prevState.currentCity !== this.state.currentCity) {
16 | this.props.setCurrentCity(this.state.currentCity);
17 | }
18 | }
19 |
20 | getCityWeather(latitude, longitude) {
21 | const {setCurrentCity} = this.props;
22 |
23 | getCity(latitude, longitude).then((city) => {
24 | this.setState({currentCity: city});
25 | setCurrentCity(city);
26 |
27 | }).catch(function(err) {
28 | console.log('Error retrieving the current city: ', err);
29 | });
30 |
31 | getWeather(latitude, longitude).then((weather) => {
32 | weather = Math.round(weather);
33 | this.setState({currentWeather: weather})
34 | }).catch(function(err){
35 | console.log('Error retrieving the current weather: ', err);
36 | })
37 | }
38 |
39 | getMyLocation = () => {
40 | const {
41 | handleLocationChange,
42 | setUserPosition
43 | } = this.props;
44 | const pos = {
45 | lat: parseFloat(localStorage.getItem('lat')),
46 | lng: parseFloat(localStorage.getItem('lng'))
47 | }
48 |
49 | handleLocationChange(pos);
50 | setUserPosition(pos);
51 | // ***Get Location from Cache
52 | if (pos.lat && pos.lng) {
53 | this.getCityWeather(pos.lat, pos.lng);
54 | }
55 |
56 |
57 | const errorLocation = (err) => {
58 | console.log("error retrieving current position, " + err);
59 | }
60 |
61 | // ***Get Location from getCurrentPosition
62 | const currentLocation = (position) => {
63 | const {
64 | handleLocationChange,
65 | setUserPosition
66 | } = this.props
67 |
68 | const pos = {
69 | lat: position.coords.latitude,
70 | lng: position.coords.longitude
71 | }
72 | setUserPosition(pos)
73 | handleLocationChange(pos)
74 |
75 | localStorage.setItem('lat', pos.lat);
76 | localStorage.setItem('lng', pos.lng);
77 | this.getCityWeather(pos.lat, pos.lng);
78 | }
79 |
80 | // Ask user for permission to use location services
81 | if (navigator.geolocation) {
82 | navigator.geolocation.getCurrentPosition(currentLocation, errorLocation);
83 | } else {
84 | alert('Sorry your browser doesn\'t support the Geolocation API');
85 | }
86 | }
87 |
88 | render () {
89 | const {currentCity, currentWeather} = this.state;
90 | const message = (this.state.currentCity && this.state.currentWeather)
91 | ? ` You're in ${currentCity}. It is currently ${currentWeather}°F`
92 | : ``;
93 |
94 | return(
95 |
96 | Welcome to Mappa. {message}
97 |
98 | );
99 | }
100 | }
101 |
102 | export default GoogleApiWrapper({
103 | apiKey: (process.env.REACT_APP_GKEY),
104 | libraries: ['places'],
105 | version: '3'
106 |
107 | })(HeaderContainer)
108 |
109 |
--------------------------------------------------------------------------------
/docs/Setupinstructions.md:
--------------------------------------------------------------------------------
1 | ### Following these instructions will enable you to run the app locally with your own Google Maps API key.
2 | This is an essential first step to contributing to this project.
3 |
4 | #
5 |
6 | [Special instructions for beginners](http://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html) - Follow these steps up to "Give GitHub your public keys".
7 |
8 |
9 |
10 | General Set Up Instructions
11 |
12 | 1. Fork the repository to your github.
13 |
14 | * To **fork** the project, head over to [gwg-women-techmakers](https://github.com/gwg-women/gwg-women-techmakers) and fork the project into your own github.
15 |
16 | * Head into your forked project and click the green button that says **Clone or download** to see the URL to use to fork into your own computer. It should look a little something like this:
17 |
18 | ```https://github.com//gwg-women-techmakers.git```
19 |
20 | * Open your command shell of choice and navigate to the folder where you want your project to be in. Type in:
21 |
22 | ```git clone https://github.com//gwg-women-techmakers.git```
23 |
24 |
25 |
26 | 2. How to get your own API key
27 |
28 | * Get Google Maps API
29 |
30 | - Go to the [Google API Console](https://console.developers.google.com/apis)
31 | - [Create or select a project for Google Maps Android Backend API](https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&reusekey=true) or search for it in **Library** panel
32 | - [Create or select a project for Google Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/get-api-key) or find it in **Library** panel
33 | - In Google API Console check to see if the APIs are enabled in **Enabled APIs and services** panel
34 | - In Google API Console retrieve your **API key** inside the **Credentials** panel.
35 |
36 |
37 | * Get a OpenWeatherMap API key:
38 | - Go to the [OpenWeatherMap how to start](https://openweathermap.org/appid) page and click sign up
39 | - Create a free account
40 | - Go to the API Keys tab
41 |
42 |
43 | 2. Getting it running
44 |
45 | * **Installing Dependencies**:
46 | - Navigate inside **gwg-women-techmakers** folder with your command shell and install all dependencies with your package manager of choice.
47 | * NPM:
48 | `npm install`
49 | * Yarn:
50 | `yarn install`
51 | * **Inserting your API key**:
52 | - Inside the directory, find **.env.example** and create a copy and name it **.env**.
53 |
54 | NOTE: .env is in .gitignore and will not be uploaded to your github.
55 |
56 | - Your API key inside your environment variable (.env) should start with **REACT_APP**.
57 | - Google's API should look this:
58 |
59 | ```REACT_APP_GKEY: api_key```
60 | - Weather's API should look like this:
61 |
62 | ```REACT_APP_WEATHERKEY: api_key```
63 |
64 | * **Starting the APP**:
65 |
66 | * Build everything together with your package manager of choice:
67 | * NPM:
68 | `npm run build` or `npm build`
69 |
70 | * Yarn:
71 | `yarn build`
72 |
73 | * Start it!:
74 | * Run the app by typing in:
75 | * NPM:
76 | ```npm start```
77 |
78 | * Yarn:
79 | ```yarn start```
80 |
81 | You should be able to see it run on localhost:3000. That's it!
82 |
83 |
84 |