diff --git a/package.json b/package.json index 7993437..869e3a5 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "@material-ui/core": "^3.1.0", "google-maps-react": "^2.0.2", + "firebase": "^5.5.1", "react": "^16.5.1", "react-dom": "^16.5.1", "react-router": "^4.3.1", diff --git a/src/components/Main.js b/src/components/Main.js index 1f3d080..34951bd 100644 --- a/src/components/Main.js +++ b/src/components/Main.js @@ -9,6 +9,7 @@ import Home from '../pages/Home'; import Map from '../pages/Map'; import Quiz from '../pages/Quiz'; import Sighting from '../pages/Sighting'; +import Report from '../pages/Report'; import Info from '../pages/Info'; function TabContainer(props) { @@ -43,24 +44,26 @@ class SimpleTabs extends React.Component { const { classes } = this.props; const { value } = this.state; - return ( -
- - - - - - - - - - {value === 0 && } - {value === 1 && } - {value === 2 && } - {value === 3 && } - {value === 4 && } -
- ); + return ( +
+ + + + + + + + + + + {value === 0 && } + {value === 1 && } + {value === 2 && } + {value === 3 && } + {value === 4 && } + {value === 5 && } +
+ ); } } diff --git a/src/components/ReportForm.js b/src/components/ReportForm.js new file mode 100644 index 0000000..4dd046e --- /dev/null +++ b/src/components/ReportForm.js @@ -0,0 +1,311 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import Grid from '@material-ui/core/Grid'; +import { withStyles } from '@material-ui/core/styles'; +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'; + +/** + * Styles that the different + * Material UI components pull + * in. Mostly used for spacing. + */ +const styles = theme => ({ + container: { + display: 'flex', + flexWrap: 'wrap', + }, + textField: { + marginLeft: theme.spacing.unit * 2, + marginRight: theme.spacing.unit, + marginTop: theme.spacing.unit * 2, + flexBasis: 280, + }, + button: { + marginLeft: theme.spacing.unit * 2, + marginRight: theme.spacing.unit, + marginTop: theme.spacing.unit * 2, + }, + dense: { + marginTop: 30, + }, + menu: { + width: 200, + }, +}); + +/** + * Function for formatting the + * date as a string that + * Material UI can use. We'll + * also store the date like + * this string in the database. + * @param {*} date, Date passed in. + */ +function formatDate(date) { + var d = new Date(date), + month = '' + (d.getMonth() + 1), + day = '' + d.getDate(), + year = d.getFullYear(); + + if (month.length < 2) month = '0' + month; + if (day.length < 2) day = '0' + day; + + return [year, month, day].join('-'); +} + +/** + * Types of sightings. Label is what is + * viewed in the application, value is + * what is stored in the database. +*/ +const sightingTypes = [ + { + value: 'visual', + label: 'Visual', + }, + { + value: 'roadkill', + label: 'Roadkill', + }, + { + value: 'trapped', + label: 'Trapped', + }, + { + value: 'viewed_tracks', + label: 'Viewed Tracks', + }, + { + value: 'photo', + label: 'Photo', + }, + { + value: 'other', + label: 'Other', + }, +]; + +/** + * Levels of confidence. Label is what is + * viewed in the application, value is + * what is stored in the database. +*/ +const confidenceLevels = [ + { + value: '1', + label: '1 - Strongly unconfident', + }, + { + value: '2', + label: '2 - Unconfident', + }, + { + value: '3', + label: '3 - Somewhat confident', + }, + { + value: '4', + label: '4 - Confident', + }, + { + value: '5', + label: '5 - Very confident', + }, + ]; + +/** + * The form component. + */ +class ReportForm extends React.Component { + /** + * Component contructor. Currently + * only used to bind event + * handlers. + */ + constructor() { + super(); + this.handleSubmit = this.handleSubmit.bind(this); + } + + /** + * State of form components. + */ + state = { + date: formatDate(new Date()), + time: '00:00', + type: 'visual', + confidence: '1', + desc: '' + }; + + /** + * Handles state change in form + * components. + */ + handleChange = name => event => { + this.setState({ + [name]: event.target.value, + }); + }; + + /** + * Event listener for form. + * When the form is submitted, + * this function passes the + * data along to Firebase. + */ + handleSubmit(e) { + e.preventDefault(); + const sightingsRef = firebase.database().ref('sightings'); + const sighting = { + type: this.state.type, + confidence: this.state.confidence, + date: this.state.date, + time: this.state.time, + desc: this.state.desc + } + sightingsRef.push(sighting); + this.setState({ + date: formatDate(new Date()), + time: '00:00', + type: 'visual', + confidence: '1', + desc: '' + }); + }; + + + /** + * The render method for this component. + */ + render() { + const { classes } = this.props; + + /** + * The actual form. + */ + return ( +
+ + + + {sightingTypes.map(option => ( + + {option.label} + + ))} + + + + + + {confidenceLevels.map(option => ( + + {option.label} + + ))} + + + + + + + + + + + + + + + + + + + +
+ ); + } +} + +ReportForm.propTypes = { + classes: PropTypes.object.isRequired, +}; + +export default withStyles(styles)(ReportForm); \ No newline at end of file diff --git a/src/firebase.js b/src/firebase.js new file mode 100644 index 0000000..f26bb7a --- /dev/null +++ b/src/firebase.js @@ -0,0 +1,14 @@ +import firebase from 'firebase/app'; +import 'firebase/database'; + +const config = { + apiKey: "AIzaSyAYf9AbeYwLY892NRiQfn0AMtG9xIFAJbo", + authDomain: "marten-application.firebaseapp.com", + databaseURL: "https://marten-application.firebaseio.com", + projectId: "marten-application", + storageBucket: "marten-application.appspot.com", + messagingSenderId: "659856510832" +}; + +firebase.initializeApp(config); +export default firebase; \ No newline at end of file diff --git a/src/pages/Report.js b/src/pages/Report.js new file mode 100644 index 0000000..8a7909d --- /dev/null +++ b/src/pages/Report.js @@ -0,0 +1,15 @@ +import React, { Component } from 'react'; +import ReportForm from '../components/ReportForm'; +import Typography from '@material-ui/core/Typography'; + +class Report extends Component { + render() { + return ( + + + + ); + } +} + +export default Report;