feat: read from firestore

This commit is contained in:
Kyle Gill
2019-03-28 21:12:20 -06:00
parent cb9a52082e
commit 205f2b3e9b
8 changed files with 35 additions and 31 deletions

View File

@@ -1,6 +1,9 @@
import React, { Component } from "react";
import styled from "@emotion/styled";
import { compose } from "recompose";
import { withTheme } from "emotion-theming";
import { withFirebase } from "../../firebase";
import { withAuthentication } from "../../session";
import { addDays, subDays, format, isAfter, startOfYesterday } from "date-fns";
import { SIZES } from "../../../styles/constants";
@@ -43,11 +46,14 @@ class Day extends Component {
const {
match: {
params: { year, month, day }
}
},
firebase,
authUser,
} = this.props;
const currentDay = new Date(year, month - 1, day);
console.log(currentDay);
if (!currentDay) return;
firebase.db.collection("entries").doc(`${year}${month}${day}-${authUser.uid}`).get().then(doc => console.log(doc.data()))
return (
<>
@@ -64,4 +70,4 @@ class Day extends Component {
}
}
export default withTheme(Day);
export default compose(withFirebase,withTheme, withAuthentication)(Day);

View File

@@ -27,10 +27,11 @@ class RegisterForm extends Component {
onSubmit = event => {
const { username, email, passwordOne } = this.state;
const { firebase } = this.props
this.props.firebase
firebase
.doCreateUserWithEmailAndPassword(email, passwordOne)
.then(authUser => {
.then(result => {
this.setState({
username: "",
email: "",
@@ -38,6 +39,12 @@ class RegisterForm extends Component {
passwordTwo: "",
error: null
});
const { user } = result
console.log(user)
firebase.db.collection("users").doc(user.uid).set({
email: user.email,
theme: "LIGHT"
})
this.props.history.push("/home");
})
.catch(error => {
@@ -53,7 +60,6 @@ class RegisterForm extends Component {
render() {
const { username, email, passwordOne, passwordTwo, error } = this.state;
const isInvalid =
passwordOne !== passwordTwo ||
passwordOne === "" ||

View File

@@ -1,5 +1,5 @@
import React from "react";
import fire from "../../firebase/fire.js";
import { withFirebase } from "../../firebase";
import SignOut from "../../SignOut";
@@ -16,11 +16,9 @@ class User extends React.Component {
addUser = e => {
e.preventDefault();
const db = fire.firestore();
db.settings({
timestampsInSnapshots: true
});
const userRef = db.collection("users").add({
const { firebase } = this.props
const userRef = firebase.db.collection("users").doc().add({
name: this.state.name
});
this.setState({ name: "" });
@@ -45,4 +43,4 @@ class User extends React.Component {
}
}
export default User;
export default withFirebase(User);