Entony 6 年 前
コミット
a3f25a043d

ファイルの差分が大きいため隠しています
+ 904 - 155
package-lock.json


+ 1 - 0
package.json

@@ -5,6 +5,7 @@
   "dependencies": {
     "antd": "^3.10.9",
     "axios": "^0.18.0",
+    "firebase": "^5.7.0",
     "node-sass": "^4.10.0",
     "prop-types": "^15.6.2",
     "react": "^16.6.3",

+ 2 - 6
src/Reducers/auth.js

@@ -1,12 +1,8 @@
 import * as types from "../constants/actionTypes";
 
-const initState = {
-	user: null,
-	isFetching: false,
-	error: null
-};
+import initState from "../state/initialState";
 
-export default (state = initState, { type, payload }) => {
+export default (state = initState.auth, { type, payload }) => {
 	switch (type) {
 		case types.AUTH: {
 			return {

+ 25 - 0
src/actions/auth.js

@@ -14,3 +14,28 @@ export const authFail = payload => ({
 	type: types.AUTH_FAIL,
 	payload
 });
+
+// export const addUser = payload => ({
+//   type: ADD_USER,
+//   payload,
+// });
+
+// const usersRef = database.ref('users');
+// export const startListeningForUsers = () => dispatch => {
+//   // listen users in database, if new user start our app we set him in database and our local state
+//   usersRef.on('child_added', snapshot => {
+//     dispatch(addUser(snapshot.val()));
+//   });
+// };
+
+// export const startListeningToAuthChange = () => dispatch => {
+// 	// start listen auth in database
+// 	auth.onAuthStateChanged(user => {
+// 		if (!user) {
+// 			return dispatch(signedOut());
+// 		}
+// 		// if user exist we set him to database
+// 		usersRef.child(user.uid).set(pick(user, ['displayName', 'photoURL', 'email', 'uid']));
+// 		return dispatch(signedIn(user));
+// 	});
+// };

+ 9 - 0
src/actions/index.js

@@ -0,0 +1,9 @@
+import * as auth from "./auth";
+import * as todo from "./auth";
+import * as weather from "./auth";
+
+export default {
+	...auth,
+	...todo,
+	...weather
+};

+ 15 - 2
src/container/App.js

@@ -7,18 +7,27 @@ import List from "../components/list";
 import LoadForm from "../components/loadForm";
 import EditModal from "../components/modal";
 
+import { auth, googleAuthProvider } from "../firebaseConfig";
+
 class App extends Component {
 	state = {
 		openAddForm: false,
-		toggleModal: false
+		toggleModal: false,
+		user: null
 	};
 
 	componentDidMount() {
 		const { getLoads } = this.props;
 
 		getLoads();
+
+		auth.onAuthStateChanged(user => this.setState({ user }));
 	}
 
+	authRequest = () => {
+		auth.signInWithPopup(googleAuthProvider).then(res => this.setState({ user: res.user }));
+	};
+
 	openEditModal = id => {
 		const { getInitVal } = this.props;
 		getInitVal(id);
@@ -30,9 +39,13 @@ class App extends Component {
 
 	render() {
 		const { list, inputData, editLoadsRequest, initialValues, postLoads } = this.props;
-		const { openAddForm, toggleModal } = this.state;
+		const { openAddForm, toggleModal, user } = this.state;
 		return (
 			<Fragment>
+				<button onClick={this.authRequest}>Auth</button>
+
+				<h1>{user && user.displayName}</h1>
+
 				<h1 className="h1-tag">
 					Доставка грузов "to-do list" -{" "}
 					<span onClick={this.openFormHandler} className="h1-tag h1-tag--add">

+ 4 - 2
src/container/fetchPage.js

@@ -1,6 +1,7 @@
 import React, { Component } from "react";
 import { connect } from "react-redux";
 import { bindActionCreators } from "redux";
+import actions from "../actions";
 
 import { takeInputValue, getWeather } from "../actions/weather";
 
@@ -46,7 +47,7 @@ class FetchPage extends Component {
 
 	render() {
 		const { weather, error } = this.props;
-
+		console.log("this.", this.props);
 		const { photo } = this.state;
 		return (
 			<div className="page">
@@ -76,7 +77,8 @@ const mapStateToProps = state => ({
 	error: state.w.error
 });
 
-const mapDispatchToProps = dispatch => bindActionCreators({ takeInputValue, getWeather }, dispatch);
+const mapDispatchToProps = dispatch =>
+	bindActionCreators({ takeInputValue, getWeather, ...actions }, dispatch);
 
 export default connect(
 	mapStateToProps,

+ 19 - 0
src/firebaseConfig.js

@@ -0,0 +1,19 @@
+import firebase from "firebase";
+
+const config = {
+	apiKey: "AIzaSyAAdN5kpOg5rx6q2ocluadzmmV_vcQM0Lw",
+	authDomain: "first-fly.firebaseapp.com",
+	databaseURL: "https://first-fly.firebaseio.com",
+	projectId: "first-fly",
+	storageBucket: "first-fly.appspot.com",
+	messagingSenderId: "221333478401"
+};
+
+firebase.initializeApp(config);
+
+export default firebase;
+
+export const database = firebase.database();
+export const storage = firebase.storage();
+export const auth = firebase.auth();
+export const googleAuthProvider = new firebase.auth.GoogleAuthProvider();

+ 7 - 0
src/state/initialState.js

@@ -0,0 +1,7 @@
+export default {
+	auth: {
+		user: null,
+		isFetching: false,
+		error: null
+	}
+};

+ 5 - 1
src/state/state.js

@@ -5,6 +5,7 @@ import createSagaMiddleware from "redux-saga";
 
 import saga from "../saga";
 import reducers from "../Reducers";
+import initialState from "./initialState";
 
 const sagaMiddleware = createSagaMiddleware();
 
@@ -15,10 +16,13 @@ const log = state => next => action => {
 	console.log("nextState", state.getState());
 };
 
-export default createStore(
+const store = createStore(
 	reducers,
+	initialState,
 	// applyMiddleware(thunk, logger)
 	applyMiddleware(thunk, sagaMiddleware, log)
 );
 
 sagaMiddleware.run(saga);
+
+export default store;