diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/App.css b/src/App.css index 2134e4d..9dd2624 100644 --- a/src/App.css +++ b/src/App.css @@ -2,7 +2,11 @@ body { margin: 0; } -.google-map-container > div { +.report-google-map-container > div { height: 92% !important; width: 50% !important; +} + +.sighting-google-map-container > div { + height: 92% !important; } \ No newline at end of file diff --git a/src/components/Main.js b/src/components/Main.js index 34951bd..2259d17 100644 --- a/src/components/Main.js +++ b/src/components/Main.js @@ -6,9 +6,9 @@ import Tabs from '@material-ui/core/Tabs'; import Tab from '@material-ui/core/Tab'; import Typography from '@material-ui/core/Typography'; import Home from '../pages/Home'; -import Map from '../pages/Map'; +import ViewMap from '../pages/ViewMap'; import Quiz from '../pages/Quiz'; -import Sighting from '../pages/Sighting'; +import SightingList from '../pages/SightingList'; import Report from '../pages/Report'; import Info from '../pages/Info'; @@ -58,9 +58,9 @@ class SimpleTabs extends React.Component { {value === 0 && } {value === 1 && } - {value === 2 && } + {value === 2 && } {value === 3 && } - {value === 4 && } + {value === 4 && } {value === 5 && } ); diff --git a/src/components/ReportForm.js b/src/components/ReportForm.js index 95c87ff..ac72000 100644 --- a/src/components/ReportForm.js +++ b/src/components/ReportForm.js @@ -6,7 +6,7 @@ import MenuItem from '@material-ui/core/MenuItem'; import TextField from '@material-ui/core/TextField'; import Button from '@material-ui/core/Button'; import firebase from '../firebase.js'; -import MapContainer from '../pages/Map'; +import GoogleMap from '../components/ReportMap'; /** * Styles that the different @@ -326,7 +326,7 @@ class ReportForm extends React.Component { - + diff --git a/src/pages/Map.js b/src/components/ReportMap.js similarity index 98% rename from src/pages/Map.js rename to src/components/ReportMap.js index d738508..5d697bf 100644 --- a/src/pages/Map.js +++ b/src/components/ReportMap.js @@ -101,7 +101,7 @@ export class MapContainer extends Component { return ( // Render the Google Map, Marker, and InfoWindow components -
+
{ + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition((position) => { + this.setState({ + myLatLng: { + lat: position.coords.latitude, + lng: position.coords.longitude + } + } + ); + }) + } else { + // If browser doesn't support geolocation or if user does not allow it, + // center map on Grand Rapids, Michigan + this.setState({ + myLatLng: { + lat: 42.9634, + lng: 85.6681 + } + } + ); + } + } + + //DOPE: this converts a firebase snapshot (js object) to an array + snapshotToArray = (snapshot) => { + var returnArr = []; + + snapshot.forEach(function(childSnapshot) { + var item = childSnapshot.val(); + item.key = childSnapshot.key; + + returnArr.push(item); + }); + + return returnArr; + } + + // When the component has mounted to the DOM, get the user's location + componentDidMount() { + this.getLocation(); + + //DOPE: So initially I was using this to print the array of sightings to the console + const sightingsRef = firebase.database().ref('sightings'); + + sightingsRef.on('value', (snapshot) => { + console.log(this.snapshotToArray(snapshot)); + }); + + //DOPE: Instead, make the snapshot into an object and store it in the component state + sightingsRef.on('value', (snapshot) => { + let sightings = snapshot.val(); + let newState = []; + for (let sighting in sightings) { + newState.push({ + id: sighting, + lat: sightings[sighting].lat, + lng: sightings[sighting].lng, + desc: sightings[sighting].desc, + type: sightings[sighting].type, + confidence: sightings[sighting].confidence, + date: sightings[sighting].date, + time: sightings[sighting].time + }); + } + this.setState({ + sightings: newState + }); + }); + } + + // When the user clicks on a marker, pass the props related to that marker + // and show the related info window + onMarkerClick = (props, marker) => { + this.setState({ + selectedPlace: props, + activeMarker: marker, + showingInfoWindow: true + }); + } + + onMapClick = (props, map, e) => { + if (this.state.showingInfoWindow) { + this.setState({ + showingInfoWindow: false, + activeMarker: null + }); + } + } + + // Set the state of the component to contain user coordinates and initial + // marker and info window information + state = { + myLatLng: { + lat: 42.9634, + lng: 85.6681 + }, + showingInfoWindow: false, + activeMarker: {}, + selectedPlace: {}, + sightings: [] + } + + render() { + + // TODO: This line is used by the custom marker icon + //const { google } = this.props; + + return ( + // Render the Google Map, Marker, and InfoWindow components +
+ + + + + {/*DOPE: Then map the data from each sighting in sightings onto Marker props */} + { this.state.sightings.map((sighting) => { + return ( + + ) + })} + + + + + + { this.state.selectedPlace.type } + + + { this.state.selectedPlace.confidence } + + + { this.state.selectedPlace.date } + + + { this.state.selectedPlace.time } + + + { this.state.selectedPlace.description } + + + + +
+ ); + } +} + +// Send the Google Map API Key with the MapContainer component +export default GoogleApiWrapper({ + apiKey: (API_KEY) +})(MapContainer) \ No newline at end of file diff --git a/src/pages/Sighting.js b/src/pages/SightingList.js similarity index 100% rename from src/pages/Sighting.js rename to src/pages/SightingList.js diff --git a/src/pages/ViewMap.js b/src/pages/ViewMap.js new file mode 100644 index 0000000..6187d45 --- /dev/null +++ b/src/pages/ViewMap.js @@ -0,0 +1,14 @@ +import React, { Component } from 'react'; +import GoogleMap from '../components/SightingMap'; + +class Sighting extends Component { + render() { + return ( +
+ +
+ ); + } +} + +export default Sighting; \ No newline at end of file