From 8cebe809ebe8e43ddfda8ecb080a87e4a9ee11b1 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Sun, 13 May 2018 22:06:03 -0500 Subject: [PATCH] Posts update --- .babelrc | 6 +++++ .firebaserc | 5 ++++ .gitignore | 2 ++ app/auth/Login.js | 10 +------- app/auth/auth.actions.js | 4 ++++ app/auth/auth.reducer.js | 30 ++++++++++------------- app/posts/NewPost.js | 34 ++++++++++++++++---------- app/posts/posts.actions.js | 3 +++ app/posts/posts.reducer.js | 15 ++++++++++++ app/reducers.js | 4 +++- firebase-debug.log | 49 ++++++++++++++++++++++++++++++++++++++ package-lock.json | 16 +++++++++++++ package.json | 3 ++- 13 files changed, 141 insertions(+), 40 deletions(-) create mode 100644 .babelrc create mode 100644 .firebaserc create mode 100644 .gitignore create mode 100644 app/auth/auth.actions.js create mode 100644 app/posts/posts.actions.js create mode 100644 app/posts/posts.reducer.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..080f42b --- /dev/null +++ b/.babelrc @@ -0,0 +1,6 @@ +{ + "presets": ["latest", "react"], + "plugins": [ + "transform-object-rest-spread" + ] +} diff --git a/.firebaserc b/.firebaserc new file mode 100644 index 0000000..861b5f7 --- /dev/null +++ b/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "laboratoria-419ca" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1c1dbe --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +bundle.js diff --git a/app/auth/Login.js b/app/auth/Login.js index 0e924bb..99c2520 100644 --- a/app/auth/Login.js +++ b/app/auth/Login.js @@ -3,16 +3,9 @@ import { connect } from 'react-redux' import { push } from 'react-router-redux' import { Button } from 'material-ui' +import { authSuccess, authFail } from './auth.actions' import Base from '../components/Base' -const authSuccess = () => ({ - type: 'AUTH_SUCCESS' -}) - -const authFail = () => ({ - type: 'AUTH_FAIL' -}) - class LoginContainer extends React.Component { render() { const onClick = () => { @@ -32,6 +25,5 @@ class LoginContainer extends React.Component { export default connect(null, dispatch => ({ login: () => { dispatch(authSuccess()) - dispatch(push('/')) } }))(LoginContainer) diff --git a/app/auth/auth.actions.js b/app/auth/auth.actions.js new file mode 100644 index 0000000..ce4f585 --- /dev/null +++ b/app/auth/auth.actions.js @@ -0,0 +1,4 @@ +import { createAction } from 'redux-actions' + +export const authSuccess = createAction('AUTH_SUCCESS') +export const authFail = createAction('AUTH_FAIL') diff --git a/app/auth/auth.reducer.js b/app/auth/auth.reducer.js index 7af2e83..d068a5f 100644 --- a/app/auth/auth.reducer.js +++ b/app/auth/auth.reducer.js @@ -1,23 +1,19 @@ +import { handleActions } from 'redux-actions' + +import * as actions from './auth.actions' const initialState = { isAuthenticated: false } -const authReducer = (state = initialState , action) => { - switch (action.type) { - case 'AUTH_SUCCESS': - return { - ...state, - isAuthenticated: true - } - case 'AUTH_FAIL': - return { - ...state, - isAuthenticated: false - } - default: - return state - } -} +export default handleActions({ + [actions.authSuccess]: (state, action) => ({ + ...state, + isAuthenticated: true + }), + [actions.authFail]: (state, action) => ({ + ...state, + isAuthenticated: false + }) +}, initialState) -export default authReducer diff --git a/app/posts/NewPost.js b/app/posts/NewPost.js index 29c5f7c..733d299 100644 --- a/app/posts/NewPost.js +++ b/app/posts/NewPost.js @@ -8,26 +8,34 @@ import { CardContent, CardActions, } from 'material-ui' +import { connect } from 'react-redux' +import * as actions from './posts.actions' + +const postOptions = [{ + value: 'friends', + label: 'Friends' +}, { + value: 'public', + label: 'Public' +}] const PostOptions = props => ( ) const NewPost = props => { + + const onPublish = () => { + + } + return ( @@ -45,4 +53,6 @@ const NewPost = props => { ) } -export default NewPost +export default connect(null, dispatch => ({ + addPost: post => dispatch(actions.postAdd(post)) +}))(NewPost) diff --git a/app/posts/posts.actions.js b/app/posts/posts.actions.js new file mode 100644 index 0000000..1f0ce3b --- /dev/null +++ b/app/posts/posts.actions.js @@ -0,0 +1,3 @@ +import { createAction } from 'redux-actions' + +export const postAdd = createAction('POST_ADD') diff --git a/app/posts/posts.reducer.js b/app/posts/posts.reducer.js new file mode 100644 index 0000000..34649e0 --- /dev/null +++ b/app/posts/posts.reducer.js @@ -0,0 +1,15 @@ +import { handleActions } from 'redux-actions' + +import * as actions from './posts.actions' + +const initialState = { + list: [] +} + +export default handleActions({ + [actions.postAddSuccess]: (state, action) => ({ + ...state, + list: [ ...state.list, action.payload ] + }) +}, initialState) + diff --git a/app/reducers.js b/app/reducers.js index a7c0d4e..8dfce39 100644 --- a/app/reducers.js +++ b/app/reducers.js @@ -1,8 +1,10 @@ import { combineReducers } from 'redux' import auth from './auth/auth.reducer' +import posts from './posts/posts.reducer' export default combineReducers({ - auth, + auth, + posts, }) diff --git a/firebase-debug.log b/firebase-debug.log index 28ce59e..24d60bd 100644 --- a/firebase-debug.log +++ b/firebase-debug.log @@ -120,3 +120,52 @@ at TCP.done [as _onclose] (_tls_wrap.js:356:7) [error] [error] Error: An unexpected error has occurred. +[debug] [2018-05-14T02:24:46.413Z] ---------------------------------------------------------------------- +[debug] [2018-05-14T02:24:46.415Z] Command: /Users/ext.jbuitron/.nvm/versions/node/v8.11.1/bin/node /Users/ext.jbuitron/.nvm/versions/node/v8.11.1/bin/firebase serve +[debug] [2018-05-14T02:24:46.415Z] CLI Version: 3.18.4 +[debug] [2018-05-14T02:24:46.415Z] Platform: darwin +[debug] [2018-05-14T02:24:46.415Z] Node Version: v8.11.1 +[debug] [2018-05-14T02:24:46.415Z] Time: Sun May 13 2018 21:24:46 GMT-0500 (-05) +[debug] [2018-05-14T02:24:46.415Z] ---------------------------------------------------------------------- +[debug] +[debug] [2018-05-14T02:24:46.422Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"] +[debug] [2018-05-14T02:24:46.422Z] > authorizing via signed-in user +[debug] [2018-05-14T02:24:46.424Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"] +[debug] [2018-05-14T02:24:46.424Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token + { refresh_token: '1/tNI_Yrr4lRPNJcQO2TuocbX0hxnTzbpuQYWap7YV_sw', + client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com', + client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi', + grant_type: 'refresh_token', + scope: 'email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase openid' } + Sun May 13 2018 21:24:46 GMT-0500 (-05) +[debug] [2018-05-14T02:24:47.272Z] <<< HTTP RESPONSE 200 +[debug] [2018-05-14T02:24:47.288Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/laboratoria-419ca + + Sun May 13 2018 21:24:47 GMT-0500 (-05) +[debug] [2018-05-14T02:24:48.350Z] <<< HTTP RESPONSE 200 +[debug] [2018-05-14T02:24:48.351Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/laboratoria-419ca/tokens + + Sun May 13 2018 21:24:48 GMT-0500 (-05) +[debug] [2018-05-14T02:24:49.308Z] <<< HTTP RESPONSE 200 +[debug] [2018-05-14T02:24:49.309Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/laboratoria-419ca + + Sun May 13 2018 21:24:49 GMT-0500 (-05) +[debug] [2018-05-14T02:24:50.297Z] <<< HTTP RESPONSE 200 +[info] +[info] === Serving from '/Users/ext.jbuitron/personal/projects/inter/laboratoria'... +[info] +[info] i functions: Preparing to emulate functions. +[debug] [2018-05-14T02:24:50.698Z] Fetching environment +[debug] [2018-05-14T02:24:50.700Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/87445228632:getServerAppConfig + + Sun May 13 2018 21:24:50 GMT-0500 (-05) +[debug] [2018-05-14T02:24:50.701Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/87445228632/clients/_:getWebAppConfig + + Sun May 13 2018 21:24:50 GMT-0500 (-05) +[debug] [2018-05-14T02:24:52.766Z] <<< HTTP RESPONSE 200 +[debug] [2018-05-14T02:24:52.766Z] Starting @google-cloud/functions-emulator +[debug] [2018-05-14T02:24:52.848Z] <<< HTTP RESPONSE 200 +[info] i hosting: Serving hosting files from: public +[info] ✔ hosting: Local server: http://localhost:5000 + +[debug] [2018-05-14T02:24:53.819Z] Parsing function triggers diff --git a/package-lock.json b/package-lock.json index 0922257..39a645e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6617,6 +6617,11 @@ } } }, + "reduce-reducers": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/reduce-reducers/-/reduce-reducers-0.1.5.tgz", + "integrity": "sha512-uoVmQnZQ+BtKKDKpBdbBri5SLNyIK9ULZGOA504++VbHcwouWE+fJDIo8AuESPF9/EYSkI0v05LDEQK6stCbTA==" + }, "redux": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/redux/-/redux-4.0.0.tgz", @@ -6633,6 +6638,17 @@ } } }, + "redux-actions": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/redux-actions/-/redux-actions-2.3.2.tgz", + "integrity": "sha512-PPclrJFIbDzD48oNj46biisg34NTtb1VxP9MTTAxsgIFuV4mEe5UXLRNBwyqrlXrMQHUbmpnjJupxocS4mxpvA==", + "requires": { + "invariant": "^2.2.1", + "lodash": "^4.13.1", + "lodash-es": "^4.17.4", + "reduce-reducers": "^0.1.0" + } + }, "regenerate": { "version": "1.3.3", "resolved": "https://artifacts.riotgames.com:443/artifactory/api/npm/npm/regenerate/-/regenerate-1.3.3.tgz", diff --git a/package.json b/package.json index 344b8c9..38e7c51 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "react-router": "^4.2.0", "react-router-dom": "^4.2.2", "react-router-redux": "^5.0.0-alpha.9", - "redux": "^4.0.0" + "redux": "^4.0.0", + "redux-actions": "^2.3.2" } }