From 59c04c10db788be517fb22ea6f14c0ab8c0ba294 Mon Sep 17 00:00:00 2001 From: Arthur Brophy Date: Thu, 6 Jul 2017 02:01:14 -0400 Subject: [PATCH 01/27] adds port to mysql createConnection call --- api/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/api/index.js b/api/index.js index e329a7d..7c7411e 100644 --- a/api/index.js +++ b/api/index.js @@ -76,6 +76,7 @@ server.use(jwt({ secret: config.jwt.secret }).unless({ * Initialize MySQL Connection */ global.db = mysql.createConnection({ + port : config.db.port, host : config.db.host, user : config.db.username, password : config.db.password, From ed9ec042b18967a754d58061162748f0a3745f96 Mon Sep 17 00:00:00 2001 From: Dwight Gunning Date: Thu, 17 Aug 2017 10:59:31 +0200 Subject: [PATCH 02/27] Added robots.txt to the website --- www/public/robots.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 www/public/robots.txt diff --git a/www/public/robots.txt b/www/public/robots.txt new file mode 100644 index 0000000..afc8de1 --- /dev/null +++ b/www/public/robots.txt @@ -0,0 +1,4 @@ +user-agent: * +Allow: /$ +Allow: /demo$ +Disallow: / From 843f6dd2cc7629acb430cd6a4ca9c667c4418810 Mon Sep 17 00:00:00 2001 From: Dwight Gunning Date: Thu, 17 Aug 2017 11:08:04 +0200 Subject: [PATCH 03/27] Set strict routing and redirect /demo/ to /demo --- www/routes/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/www/routes/index.js b/www/routes/index.js index 52260d2..dde52b1 100644 --- a/www/routes/index.js +++ b/www/routes/index.js @@ -1,6 +1,6 @@ var express = require('express'), cors = require('cors'), - router = express.Router(), + router = express.Router({'strict': true}), config = require('../config'), MailChimpAPI = require('mailchimp').MailChimpAPI; @@ -14,6 +14,10 @@ router.get('/demo', function(req, res, next) { res.render('demo', { title: 'Cabin: React Example App by Stream' }); }); +router.get('/demo/', function(req, res, next) { + res.redirect(302, '/demo') +}); + /* POST mailchimp */ router.post('/subscribe', cors({ origin: 'https://getstream.io/blog' }), function(req, res, next) { From 77f09d9964e220f0fb98db71d20167300c8fefa1 Mon Sep 17 00:00:00 2001 From: Dwight Gunning Date: Thu, 17 Aug 2017 11:08:41 +0200 Subject: [PATCH 04/27] Switch relative src and href urls to absolute --- www/views/demo.ejs | 32 ++++++++++++++++---------------- www/views/index.ejs | 32 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/www/views/demo.ejs b/www/views/demo.ejs index f38d2ae..5fa8b5b 100644 --- a/www/views/demo.ejs +++ b/www/views/demo.ejs @@ -17,10 +17,10 @@ - - - - + + + + @@ -68,7 +68,7 @@
  • - Cabin Logo + Cabin Logo
  • @@ -76,28 +76,28 @@ Get Stream
  • - React Step One → + React Step One →
  • - ReduxStep Two → + ReduxStep Two →
  • - GetStream.ioStep Three → + GetStream.ioStep Three →
  • - ImgixStep Four → + ImgixStep Four →
  • - Keen.ioStep Five → + Keen.ioStep Five →
  • - AlgoliaStep Six → + AlgoliaStep Six →
  • - MapboxStep Seven → + MapboxStep Seven →
  • - DigitalOceanStep Eight → + DigitalOceanStep Eight →
  • Bonus → @@ -133,13 +133,13 @@ diff --git a/www/views/index.ejs b/www/views/index.ejs index d2bae20..1c33fee 100644 --- a/www/views/index.ejs +++ b/www/views/index.ejs @@ -45,7 +45,7 @@ @@ -61,7 +61,7 @@ - React and Redux + React and Redux
    BROUGHT TO YOU BY GETSTREAM.IO
    @@ -98,7 +98,7 @@ Maximizing Efficiency

    Built With These Great Services

    Cabin is built using React and Redux. Stream powers the feed technology, Algolia search, Mapbox the custom maps, Keen analytics and ImgIX the image resizing. These APIs are powerful and scalable and allow you to build a fully featured app.

    - API Partners + API Partners
    @@ -131,7 +131,7 @@ - React logo + React logo

    React

      Step 2 → @@ -142,7 +142,7 @@ - Redux logo + Redux logo

      Redux

        Step 3 → @@ -164,7 +164,7 @@ - Stream logo + Stream logo

        Feeds

          Step 4 → @@ -178,7 +178,7 @@ - Imgix logo + Imgix logo

          Image Processing

            Step 5 → @@ -193,7 +193,7 @@ - Keen logo + Keen logo

            Analytics

              Step 6 → @@ -205,7 +205,7 @@ - Algolia logo + Algolia logo

              Search

                Step 7 → @@ -220,7 +220,7 @@ - Mapbox logo + Mapbox logo

                Maps

                - DigitalOcean logo + DigitalOcean logo

                Cloud Server

                  Step 9 → @@ -245,7 +245,7 @@ - Stream Bonus logo + Stream Bonus logo @@ -272,7 +272,7 @@
                  - Background image + Background image GITHUB @@ -306,13 +306,13 @@ From 6c048303399cb04598367580dfa53b4250a8f495 Mon Sep 17 00:00:00 2001 From: Dwight Gunning Date: Thu, 17 Aug 2017 15:42:37 +0200 Subject: [PATCH 05/27] Update demo page meta tags --- www/views/demo.ejs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/views/demo.ejs b/www/views/demo.ejs index 5fa8b5b..221ceb6 100644 --- a/www/views/demo.ejs +++ b/www/views/demo.ejs @@ -1,18 +1,18 @@ - Cabin: Thoroughly Learn React and Redux with this example app + Cabin Demo - Example app built with React and Redux - + - + From e0d63f245607b8d0232feedcd271ab76dda8e283 Mon Sep 17 00:00:00 2001 From: Dwight Gunning Date: Thu, 17 Aug 2017 15:59:28 +0200 Subject: [PATCH 06/27] Added canonical urls --- www/views/demo.ejs | 1 + www/views/index.ejs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/www/views/demo.ejs b/www/views/demo.ejs index 221ceb6..f79e922 100644 --- a/www/views/demo.ejs +++ b/www/views/demo.ejs @@ -5,6 +5,7 @@ + diff --git a/www/views/index.ejs b/www/views/index.ejs index 1c33fee..8d2a258 100644 --- a/www/views/index.ejs +++ b/www/views/index.ejs @@ -5,7 +5,7 @@ - + From fdf24c40f175b6424819ce9b4377aa84133255e4 Mon Sep 17 00:00:00 2001 From: Nick Parsons Date: Mon, 28 Aug 2017 11:26:51 -0600 Subject: [PATCH 07/27] Styled with Prettier --- app/config.js | 50 +- app/modules/App.js | 345 +- app/modules/actions/App.js | 36 +- app/modules/actions/Comments.js | 83 +- app/modules/actions/Contributions.js | 43 +- app/modules/actions/Explore.js | 35 +- app/modules/actions/FollowingActivity.js | 46 +- app/modules/actions/Header.js | 31 +- app/modules/actions/IncomingActivity.js | 47 +- app/modules/actions/Like.js | 133 +- app/modules/actions/Location.js | 37 +- app/modules/actions/Photo.js | 48 +- app/modules/actions/Photos.js | 240 +- app/modules/actions/Profile.js | 137 +- app/modules/actions/Search.js | 199 +- app/modules/actions/Stats.js | 279 +- app/modules/actions/Stream.js | 64 +- app/modules/actions/Trending.js | 35 +- app/modules/actions/User.js | 69 +- app/modules/actions/index.js | 34 +- app/modules/components/Activity/Actor.js | 49 +- app/modules/components/Activity/Commented.js | 66 +- app/modules/components/Activity/Following.js | 125 +- app/modules/components/Activity/Liked.js | 89 +- app/modules/components/Activity/index.js | 49 +- app/modules/components/Avatar/index.js | 58 +- app/modules/components/BackButton/index.js | 58 +- app/modules/components/Comment/index.js | 47 +- app/modules/components/Header/index.js | 186 +- app/modules/components/LikeButton/index.js | 56 +- app/modules/components/Nav/index.js | 185 +- .../components/PhotoList/PhotoFooter.js | 78 +- app/modules/components/PhotoList/PhotoItem.js | 118 +- app/modules/components/PhotoList/index.js | 41 +- app/modules/components/Tabs/index.js | 112 +- app/modules/components/Tabs/styles.css | 42 +- app/modules/components/TimeAgo/index.js | 56 +- app/modules/components/index.js | 12 +- app/modules/main.js | 109 +- app/modules/reducers/App.js | 20 +- app/modules/reducers/Comments.js | 74 +- app/modules/reducers/Contributions.js | 25 +- app/modules/reducers/Explore.js | 25 +- app/modules/reducers/FollowingActivity.js | 77 +- app/modules/reducers/Header.js | 52 +- app/modules/reducers/IncomingActivity.js | 78 +- app/modules/reducers/Likes.js | 72 +- app/modules/reducers/Location.js | 25 +- app/modules/reducers/Navigation.js | 10 +- app/modules/reducers/Onboarding.js | 20 +- app/modules/reducers/Pagination.js | 46 +- app/modules/reducers/Photo.js | 95 +- app/modules/reducers/Photos.js | 128 +- app/modules/reducers/Profile.js | 104 +- app/modules/reducers/Search.js | 201 +- app/modules/reducers/Stats.js | 120 +- app/modules/reducers/Stream.js | 20 +- app/modules/reducers/Tokens.js | 41 +- app/modules/reducers/Trending.js | 25 +- app/modules/reducers/User.js | 62 +- app/modules/reducers/index.js | 42 +- .../routes/Contributions/Contributions.js | 99 +- app/modules/routes/Contributions/index.js | 49 +- app/modules/routes/Explore/Explore.js | 107 +- app/modules/routes/Explore/index.js | 24 +- .../FollowingActivity/FollowingActivity.js | 193 +- app/modules/routes/FollowingActivity/index.js | 48 +- app/modules/routes/Home/Home.js | 295 +- app/modules/routes/Home/index.js | 23 +- app/modules/routes/Home/routes/Photo/Photo.js | 150 +- .../routes/Photo/components/PhotoComments.js | 83 +- .../routes/Photo/components/PhotoMetadata.js | 50 +- app/modules/routes/Home/routes/Photo/index.js | 108 +- app/modules/routes/Landing/Landing.js | 73 +- app/modules/routes/Landing/index.js | 12 +- app/modules/routes/Location/Location.js | 212 +- app/modules/routes/Location/index.js | 32 +- .../routes/Notifications/Notifications.js | 202 +- app/modules/routes/Notifications/index.js | 26 +- app/modules/routes/Profile/Profile.js | 283 +- .../routes/Profile/contributions/index.js | 49 +- app/modules/routes/Profile/index.js | 40 +- .../routes/Profile/navigation/index.js | 96 +- app/modules/routes/Search/Search.js | 269 +- .../routes/Search/components/Filters/index.js | 258 +- app/modules/routes/Search/components/index.js | 2 +- app/modules/routes/Search/index.js | 24 +- .../routes/SearchResults/SearchResults.js | 86 +- app/modules/routes/SearchResults/index.js | 45 +- app/modules/routes/Stats/Stats.js | 217 +- app/modules/routes/Stats/index.js | 48 +- app/modules/routes/Trending/Trending.js | 67 +- app/modules/routes/Trending/index.js | 40 +- app/modules/routes/Upload/Upload.js | 287 +- app/modules/routes/Upload/index.js | 12 +- app/modules/utils/analytics.js | 119 +- app/package-lock.json | 9166 +++++++++++++++++ app/package.json | 166 +- app/routes/index.js | 11 +- app/webpack.config.js | 182 +- 100 files changed, 13817 insertions(+), 4325 deletions(-) create mode 100644 app/package-lock.json diff --git a/app/config.js b/app/config.js index 5b5c4a1..17c4863 100644 --- a/app/config.js +++ b/app/config.js @@ -4,29 +4,29 @@ * Config */ module.exports = { - name: 'GetStream.io - React Example App', - version: '1.0.0', - env: process.env.NODE_ENV || 'DEVELOPMENT', - mapbox: { - accessToken: process.env.MAPBOX_ACCESS_TOKEN, - }, - stream: { - appId: process.env.STREAM_APP_ID, - key: process.env.STREAM_KEY, - }, - api: { - baseUrl: process.env.API_URL, - }, - imgix: { - baseUrl: process.env.IMGIX_BASE_URL, - }, - algolia: { - appId: process.env.ALGOLIA_APP_ID, - searchOnlyKey: process.env.ALGOLIA_SEARCH_ONLY_KEY, - }, - keen: { - projectId: process.env.KEEN_PROJECT_ID, - writeKey: process.env.KEEN_WRITE_KEY, - readKey: process.env.KEEN_READ_KEY, - } + name: 'GetStream.io - React Example App', + version: '1.0.0', + env: process.env.NODE_ENV || 'DEVELOPMENT', + mapbox: { + accessToken: process.env.MAPBOX_ACCESS_TOKEN, + }, + stream: { + appId: process.env.STREAM_APP_ID, + key: process.env.STREAM_KEY, + }, + api: { + baseUrl: process.env.API_URL, + }, + imgix: { + baseUrl: process.env.IMGIX_BASE_URL, + }, + algolia: { + appId: process.env.ALGOLIA_APP_ID, + searchOnlyKey: process.env.ALGOLIA_SEARCH_ONLY_KEY, + }, + keen: { + projectId: process.env.KEEN_PROJECT_ID, + writeKey: process.env.KEEN_WRITE_KEY, + readKey: process.env.KEEN_READ_KEY, + }, }; diff --git a/app/modules/App.js b/app/modules/App.js index b308e43..27e739c 100644 --- a/app/modules/App.js +++ b/app/modules/App.js @@ -1,51 +1,47 @@ -import React, { Component, cloneElement } from 'react' -import { connect } from 'react-redux' -import { browserHistory } from 'react-router' +import React, { Component, cloneElement } from 'react'; +import { connect } from 'react-redux'; +import { browserHistory } from 'react-router'; -import stream from 'getstream' -import config from 'config' +import stream from 'getstream'; +import config from 'config'; -const Home = require('./routes/Home/Home').default +const Home = require('./routes/Home/Home').default; import { - App as AppActions, - User as UserActions, - Photos as PhotoActions, - Header as HeaderActions, - Stream as StreamActions, -} from 'actions' + App as AppActions, + User as UserActions, + Photos as PhotoActions, + Header as HeaderActions, + Stream as StreamActions, +} from 'actions'; -import { - Header, -} from 'components' - -@connect(state => ({ - header: state.Header, - user: state.User, -})) +import { Header } from 'components'; /** * AppHeader component */ +@connect(state => ({ + header: state.Header, + user: state.User, +})) class AppHeader extends Component { - - /** + /** * render * @returns markup */ - render() { - - const { header, user, router, } = this.props - - return ( -
                  - ) - } + render() { + const { header, user, router } = this.props; + + return ( +
                  + ); + } } /** @@ -55,33 +51,31 @@ class AppHeader extends Component { * @param location */ function handleRouteChange(dispatch, route, location) { - if (route) { - - if (route.getHeaderLeft) { - route.getHeaderLeft(location, (err, component) => { - dispatch(HeaderActions.left(component)) - }) - } else { - dispatch(HeaderActions.left(null)) - } - - if (route.getHeaderMiddle) { - route.getHeaderMiddle(location, (err, component) => { - dispatch(HeaderActions.middle(component)) - }) - } else { - dispatch(HeaderActions.middle(null)) - } - - if (route.getHeaderRight) { - route.getHeaderRight(location, (err, component) => { - dispatch(HeaderActions.right(component)) - }) - } else { - dispatch(HeaderActions.right(null)) - } - - } + if (route) { + if (route.getHeaderLeft) { + route.getHeaderLeft(location, (err, component) => { + dispatch(HeaderActions.left(component)); + }); + } else { + dispatch(HeaderActions.left(null)); + } + + if (route.getHeaderMiddle) { + route.getHeaderMiddle(location, (err, component) => { + dispatch(HeaderActions.middle(component)); + }); + } else { + dispatch(HeaderActions.middle(null)); + } + + if (route.getHeaderRight) { + route.getHeaderRight(location, (err, component) => { + dispatch(HeaderActions.right(component)); + }); + } else { + dispatch(HeaderActions.right(null)); + } + } } /** @@ -89,121 +83,136 @@ function handleRouteChange(dispatch, route, location) { * Bootstraps application */ class App extends Component { - - static contextTypes = { - router: React.PropTypes.object.isRequired, - } - - componentWillMount() { - // instantiate a new client (client side) - this.client = stream.connect(config.stream.key, null, config.stream.appId) - } - - /** + static contextTypes = { + router: React.PropTypes.object.isRequired, + }; + + componentWillMount() { + // instantiate a new client (client side) + this.client = stream.connect( + config.stream.key, + null, + config.stream.appId, + ); + } + + /** * componentDidUpdate * @param oldProps * @returns {*} */ - componentDidUpdate(oldProps) { - - handleRouteChange( - this.props.dispatch, - this.props.routes[this.props.routes.length - 1], - this.props.location - ) - - if (oldProps.user.id != this.props.user.id && !this.props.user.id) { - return browserHistory.push('/landing') - } - - if (oldProps.user.id != this.props.user.id && this.props.user.id) { - this.connectToStream() - this.props.dispatch(AppActions.init()) - } - - } - - /** + componentDidUpdate(oldProps) { + handleRouteChange( + this.props.dispatch, + this.props.routes[this.props.routes.length - 1], + this.props.location, + ); + + if (oldProps.user.id != this.props.user.id && !this.props.user.id) { + return browserHistory.push('/landing'); + } + + if (oldProps.user.id != this.props.user.id && this.props.user.id) { + this.connectToStream(); + this.props.dispatch(AppActions.init()); + } + } + + /** * componentDidMount */ - componentDidMount() { - - const { dispatch } = this.props - - FB.getLoginStatus(res => { - if (res.status !== 'connected') { - if (this.props.location.pathname != '/landing') { - browserHistory.replace('/landing') - } - this.props.dispatch(AppActions.initDone()) - return - } - - dispatch(UserActions.fbLogin(res)) - - if (this.props.location.pathname == '/landing') { - browserHistory.replace('/') - } - - }) - - } - - connectToStream = () => { - // follow 'timeline_flat' feed - this.timeline = this.client.feed('timeline_flat', this.props.user.id, this.props.tokens.timelineFlat) - this.timeline - .subscribe(data => { - this.props.dispatch(StreamActions.timeline(data)) - }) - .then(() => { - //console.log('Full (Timeline Flat): Connected to faye channel, waiting for realtime updates'); - }, (err) => { - console.error('Full (Timeline Flat): Could not estabilsh faye connection', err); - }); - - // follow 'notifications' feed - this.notification = this.client.feed('notification', this.props.user.id, this.props.tokens.notification) - this.notification - .subscribe(data => { - this.props.dispatch(StreamActions.event(data)) - }) - .then(() => { - //console.log('Full (Notifications): Connected to faye channel, waiting for realtime updates'); - }, (err) => { - console.error('Full (Notifications): Could not estabilsh faye connection', err); - }); - } - - /** + componentDidMount() { + const { dispatch } = this.props; + + FB.getLoginStatus(res => { + if (res.status !== 'connected') { + if (this.props.location.pathname != '/landing') { + browserHistory.replace('/landing'); + } + this.props.dispatch(AppActions.initDone()); + return; + } + + dispatch(UserActions.fbLogin(res)); + + if (this.props.location.pathname == '/landing') { + browserHistory.replace('/'); + } + }); + } + + connectToStream = () => { + // follow 'timeline_flat' feed + this.timeline = this.client.feed( + 'timeline_flat', + this.props.user.id, + this.props.tokens.timelineFlat, + ); + this.timeline + .subscribe(data => { + this.props.dispatch(StreamActions.timeline(data)); + }) + .then( + () => { + //console.log('Full (Timeline Flat): Connected to faye channel, waiting for realtime updates'); + }, + err => { + console.error( + 'Full (Timeline Flat): Could not estabilsh faye connection', + err, + ); + }, + ); + + // follow 'notifications' feed + this.notification = this.client.feed( + 'notification', + this.props.user.id, + this.props.tokens.notification, + ); + this.notification + .subscribe(data => { + this.props.dispatch(StreamActions.event(data)); + }) + .then( + () => { + //console.log('Full (Notifications): Connected to faye channel, waiting for realtime updates'); + }, + err => { + console.error( + 'Full (Notifications): Could not estabilsh faye connection', + err, + ); + }, + ); + }; + + /** * render * @returns markup */ - render() { - - if (this.props.loading) return
                  Loading...
                  - - if (this.props.location.pathname == '/landing') { - return ( -
                  - {this.props.children || } -
                  - ) - } - - return ( -
                  - - {this.props.children || } -
                  - ) - - } - + render() { + if (this.props.loading) return
                  Loading...
                  ; + + if (this.props.location.pathname == '/landing') { + return ( +
                  + {this.props.children || } +
                  + ); + } + + return ( +
                  + + {this.props.children || } +
                  + ); + } } export default connect(state => ({ - user: state.User, - loading: state.App.loading, - tokens: state.Tokens, -}))(App) + user: state.User, + loading: state.App.loading, + tokens: state.Tokens, +}))(App); diff --git a/app/modules/actions/App.js b/app/modules/actions/App.js index 038379f..2a3e8e5 100644 --- a/app/modules/actions/App.js +++ b/app/modules/actions/App.js @@ -1,14 +1,14 @@ import { - Photos as PhotoActions, - IncomingActivity as IncomingActivityActions, - FollowingActivity as FollowingActivityActions, -} from './' + Photos as PhotoActions, + IncomingActivity as IncomingActivityActions, + FollowingActivity as FollowingActivityActions, +} from './'; /** * INIT * @type {string} */ -export const INIT = 'APP_INIT' +export const INIT = 'APP_INIT'; /** * init @@ -18,29 +18,29 @@ export const INIT = 'APP_INIT' * @returns {Function} */ export function init() { - return dispatch => { - Promise.all([ - dispatch(PhotoActions.load()), - dispatch(IncomingActivityActions.load()), - dispatch(FollowingActivityActions.load()), - ]).then(() => { - dispatch(initDone()) - }) - } + return dispatch => { + Promise.all([ + dispatch(PhotoActions.load()), + dispatch(IncomingActivityActions.load()), + dispatch(FollowingActivityActions.load()), + ]).then(() => { + dispatch(initDone()); + }); + }; } /** * INIT_DONE * @type {string} */ -export const INIT_DONE = 'APP_INIT_DONE' +export const INIT_DONE = 'APP_INIT_DONE'; /** * initDone * @returns {{type: string}} */ export function initDone() { - return { - type: INIT_DONE - } + return { + type: INIT_DONE, + }; } diff --git a/app/modules/actions/Comments.js b/app/modules/actions/Comments.js index 02901ea..a3a8fce 100644 --- a/app/modules/actions/Comments.js +++ b/app/modules/actions/Comments.js @@ -1,18 +1,18 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * ADD_COMMENT * @type {string} */ -export const ADD_COMMENT = 'PHOTOS_ADD_COMMENT' +export const ADD_COMMENT = 'PHOTOS_ADD_COMMENT'; /** * _addCommentRequest * @param id * @private */ -export const _addCommentRequest = (id) => ({ type: ADD_COMMENT, id, }) +export const _addCommentRequest = id => ({ type: ADD_COMMENT, id }); /** * _addCommentResponse @@ -21,7 +21,12 @@ export const _addCommentRequest = (id) => ({ type: ADD_COMMENT, id, }) * @param user * @private */ -export const _addCommentResponse = (id, comment, user) => ({ type: ADD_COMMENT, id, comment, user, }) +export const _addCommentResponse = (id, comment, user) => ({ + type: ADD_COMMENT, + id, + comment, + user, +}); /** * addComment @@ -33,37 +38,38 @@ export const _addCommentResponse = (id, comment, user) => ({ type: ADD_COMMENT, * @returns {Function} */ export function addComment(id, text) { - return (dispatch, getState) => { - const user = getState().User - dispatch(_addCommentRequest(id)) - const data = { - user_id: user.id, - upload_id: id, - comment: text, - } - axios.post(`${config.api.baseUrl}/comments`, data, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_addCommentResponse(id, res.data, user)) - }) - } + return (dispatch, getState) => { + const user = getState().User; + dispatch(_addCommentRequest(id)); + const data = { + user_id: user.id, + upload_id: id, + comment: text, + }; + axios + .post(`${config.api.baseUrl}/comments`, data, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_addCommentResponse(id, res.data, user)); + }); + }; } /** * LOAD_COMMENTS * @type {string} */ -export const LOAD_COMMENTS = 'PHOTOS_LOAD_COMMENT' +export const LOAD_COMMENTS = 'PHOTOS_LOAD_COMMENT'; /** * _loadCommentsRequest * @param postID * @private */ -export const _loadCommentsRequest = (postID) => ({ type: LOAD_COMMENTS, postID, }) +export const _loadCommentsRequest = postID => ({ type: LOAD_COMMENTS, postID }); /** * _loadCommentsResponse @@ -71,7 +77,11 @@ export const _loadCommentsRequest = (postID) => ({ type: LOAD_COMMENTS, postID, * @param comments * @private */ -export const _loadCommentsResponse = (postID, comments) => ({ type: LOAD_COMMENTS, postID, comments, }) +export const _loadCommentsResponse = (postID, comments) => ({ + type: LOAD_COMMENTS, + postID, + comments, +}); /** * load @@ -82,15 +92,16 @@ export const _loadCommentsResponse = (postID, comments) => ({ type: LOAD_COMMENT * @returns {Function} */ export function load(postID) { - return dispatch => { - dispatch(_loadCommentsRequest(postID)) - axios.get(`${config.api.baseUrl}/comments?upload_id=${postID}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadCommentsResponse(postID, res.data)) - }) - } + return dispatch => { + dispatch(_loadCommentsRequest(postID)); + axios + .get(`${config.api.baseUrl}/comments?upload_id=${postID}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadCommentsResponse(postID, res.data)); + }); + }; } diff --git a/app/modules/actions/Contributions.js b/app/modules/actions/Contributions.js index 1f1116e..aceb2f5 100644 --- a/app/modules/actions/Contributions.js +++ b/app/modules/actions/Contributions.js @@ -1,18 +1,18 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'CONTRIBUTIONS_LOAD' +export const LOAD = 'CONTRIBUTIONS_LOAD'; /** * _loadRequest * @param userID * @private */ -export const _loadRequest = (userID) => ({ type: LOAD, userID, }) +export const _loadRequest = userID => ({ type: LOAD, userID }); /** * _loadResponse @@ -20,7 +20,11 @@ export const _loadRequest = (userID) => ({ type: LOAD, userID, }) * @param response * @private */ -export const _loadResponse = (userID, response) => ({ type: LOAD, userID, response, }) +export const _loadResponse = (userID, response) => ({ + type: LOAD, + userID, + response, +}); /** * load @@ -31,16 +35,21 @@ export const _loadResponse = (userID, response) => ({ type: LOAD, userID, respon * @returns {Function} */ export function load(userID) { - return (dispatch, getState) => { - dispatch(_loadRequest(userID)) - const user = getState().User - axios.get(`${config.api.baseUrl}/contributions?user_id=${userID || user.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(userID, res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_loadRequest(userID)); + const user = getState().User; + axios + .get( + `${config.api.baseUrl}/contributions?user_id=${userID || + user.id}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }, + ) + .then(res => { + dispatch(_loadResponse(userID, res.data)); + }); + }; } diff --git a/app/modules/actions/Explore.js b/app/modules/actions/Explore.js index 1bf990f..ef070a6 100644 --- a/app/modules/actions/Explore.js +++ b/app/modules/actions/Explore.js @@ -1,24 +1,24 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'EXPLORE_LOAD' +export const LOAD = 'EXPLORE_LOAD'; /** * _loadRequest * @private */ -const _loadRequest = () => ({ type: LOAD, }) +const _loadRequest = () => ({ type: LOAD }); /** * _loadResponse * @param response * @private */ -const _loadResponse = (response) => ({ type: LOAD, response}) +const _loadResponse = response => ({ type: LOAD, response }); /** * load @@ -28,16 +28,17 @@ const _loadResponse = (response) => ({ type: LOAD, response}) * @returns {Function} */ export function load() { - return (dispatch, getState) => { - dispatch(_loadRequest()) - const user = getState().User - axios.get(`${config.api.baseUrl}/explore?user_id=${user.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_loadRequest()); + const user = getState().User; + axios + .get(`${config.api.baseUrl}/explore?user_id=${user.id}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadResponse(res.data)); + }); + }; } diff --git a/app/modules/actions/FollowingActivity.js b/app/modules/actions/FollowingActivity.js index 83c3df6..1394b56 100644 --- a/app/modules/actions/FollowingActivity.js +++ b/app/modules/actions/FollowingActivity.js @@ -1,24 +1,24 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'FOLLOWING_ACTIVITY_LOAD' +export const LOAD = 'FOLLOWING_ACTIVITY_LOAD'; /** * _loadRequest * @private */ -export const _loadRequest = () => ({ type: LOAD, }) +export const _loadRequest = () => ({ type: LOAD }); /** * _loadResponse * @param response * @private */ -export const _loadResponse = (response) => ({ type: LOAD, response, }) +export const _loadResponse = response => ({ type: LOAD, response }); /** * load @@ -28,18 +28,26 @@ export const _loadResponse = (response) => ({ type: LOAD, response, }) * @returns {Function} */ export function load() { - return (dispatch, getState) => { - return new Promise((resolve => { - dispatch(_loadRequest()) - axios.get(`${config.api.baseUrl}/following-activity?user_id=${getState().User.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(res.data)) - resolve() - }) - })) - } + return (dispatch, getState) => { + return new Promise(resolve => { + dispatch(_loadRequest()); + axios + .get( + `${config.api + .baseUrl}/following-activity?user_id=${getState().User + .id}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem( + 'jwt', + )}`, + }, + }, + ) + .then(res => { + dispatch(_loadResponse(res.data)); + resolve(); + }); + }); + }; } diff --git a/app/modules/actions/Header.js b/app/modules/actions/Header.js index eda35e0..7ac5751 100644 --- a/app/modules/actions/Header.js +++ b/app/modules/actions/Header.js @@ -2,7 +2,7 @@ * LEFT * @type {string} */ -export const LEFT = 'HEADER_LEFT' +export const LEFT = 'HEADER_LEFT'; /** * left @@ -10,18 +10,17 @@ export const LEFT = 'HEADER_LEFT' * @returns {{type: string, component: *}} */ export function left(component) { - return { - type: LEFT, - component, - } + return { + type: LEFT, + component, + }; } /** * MIDDLE * @type {string} */ -export const MIDDLE = 'HEADER_MIDDLE' - +export const MIDDLE = 'HEADER_MIDDLE'; /** * middle @@ -29,17 +28,17 @@ export const MIDDLE = 'HEADER_MIDDLE' * @returns {{type: string, component: *}} */ export function middle(component) { - return { - type: MIDDLE, - component, - } + return { + type: MIDDLE, + component, + }; } /** * RIGHT * @type {string} */ -export const RIGHT = 'HEADER_RIGHT' +export const RIGHT = 'HEADER_RIGHT'; /** * right @@ -47,8 +46,8 @@ export const RIGHT = 'HEADER_RIGHT' * @returns {{type: string, component: *}} */ export function right(component) { - return { - type: RIGHT, - component, - } + return { + type: RIGHT, + component, + }; } diff --git a/app/modules/actions/IncomingActivity.js b/app/modules/actions/IncomingActivity.js index bf62fe4..8f513eb 100644 --- a/app/modules/actions/IncomingActivity.js +++ b/app/modules/actions/IncomingActivity.js @@ -1,25 +1,24 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'INCOMING_ACTIVITY_LOAD' +export const LOAD = 'INCOMING_ACTIVITY_LOAD'; /** * _loadRequest * @private */ -export const _loadRequest = () => ({ type: LOAD, }) +export const _loadRequest = () => ({ type: LOAD }); /** * _loadResponse * @param response * @private */ -export const _loadResponse = (response) => ({ type: LOAD, response, }) - +export const _loadResponse = response => ({ type: LOAD, response }); /** * load @@ -29,18 +28,26 @@ export const _loadResponse = (response) => ({ type: LOAD, response, }) * @returns {Function} */ export function load() { - return (dispatch, getState) => { - return new Promise((resolve => { - dispatch(_loadRequest()) - axios.get(`${config.api.baseUrl}/incoming-activity?user_id=${getState().User.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(res.data)) - resolve() - }) - })) - } + return (dispatch, getState) => { + return new Promise(resolve => { + dispatch(_loadRequest()); + axios + .get( + `${config.api + .baseUrl}/incoming-activity?user_id=${getState().User + .id}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem( + 'jwt', + )}`, + }, + }, + ) + .then(res => { + dispatch(_loadResponse(res.data)); + resolve(); + }); + }); + }; } diff --git a/app/modules/actions/Like.js b/app/modules/actions/Like.js index e05933b..9196a67 100644 --- a/app/modules/actions/Like.js +++ b/app/modules/actions/Like.js @@ -1,19 +1,19 @@ -import * as axios from 'axios' -import config from 'config' -import * as querystring from 'querystring' +import * as axios from 'axios'; +import config from 'config'; +import * as querystring from 'querystring'; /** * LOAD * @type {string} */ -export const LOAD = 'LIKE_LOAD' +export const LOAD = 'LIKE_LOAD'; /** * _loadRequest * @param postID * @private */ -export const _loadRequest = (postID) => ({ type: LOAD, postID, }) +export const _loadRequest = postID => ({ type: LOAD, postID }); /** * _loadResponse @@ -21,7 +21,11 @@ export const _loadRequest = (postID) => ({ type: LOAD, postID, }) * @param response * @private */ -export const _loadResponse = (postID, response) => ({ type: LOAD, postID, response, }) +export const _loadResponse = (postID, response) => ({ + type: LOAD, + postID, + response, +}); /** * load @@ -33,32 +37,37 @@ export const _loadResponse = (postID, response) => ({ type: LOAD, postID, respon * @returns {Function} */ export function load(postID, userID) { - return (dispatch, getState) => { - dispatch(_loadRequest(postID)) - const user = getState().User - axios.get(`${config.api.baseUrl}/likes?upload_id=${postID}&user_id=${user.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(postID, res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_loadRequest(postID)); + const user = getState().User; + axios + .get( + `${config.api + .baseUrl}/likes?upload_id=${postID}&user_id=${user.id}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }, + ) + .then(res => { + dispatch(_loadResponse(postID, res.data)); + }); + }; } /** * ADD_LIKE * @type {string} */ -export const ADD_LIKE = 'ADD_LIKE' +export const ADD_LIKE = 'ADD_LIKE'; /** * _hnadleAddLikeRequest * @param postID * @private */ -export const _handleAddLikeRequest = (postID) => ({ type: ADD_LIKE, postID,}) +export const _handleAddLikeRequest = postID => ({ type: ADD_LIKE, postID }); /** * _handleAddLikeResponse @@ -66,7 +75,11 @@ export const _handleAddLikeRequest = (postID) => ({ type: ADD_LIKE, postID,}) * @param response * @private */ -export const _handleAddLikeResponse = (postID, response) => ({ type: ADD_LIKE, postID, response, }) +export const _handleAddLikeResponse = (postID, response) => ({ + type: ADD_LIKE, + postID, + response, +}); /** * like @@ -75,35 +88,39 @@ export const _handleAddLikeResponse = (postID, response) => ({ type: ADD_LIKE, p * @returns {Function} */ export function like(postID) { - return (dispatch, getState) => { - dispatch(_handleAddLikeRequest(postID)) - const data = { - user_id: getState().User.id, - upload_id: postID, - } - axios.post(`${config.api.baseUrl}/likes`, data, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_handleAddLikeResponse(postID, res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_handleAddLikeRequest(postID)); + const data = { + user_id: getState().User.id, + upload_id: postID, + }; + axios + .post(`${config.api.baseUrl}/likes`, data, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_handleAddLikeResponse(postID, res.data)); + }); + }; } /** * DELETE_LIKE * @type {string} */ -export const DELETE_LIKE = 'DELETE_LIKE' +export const DELETE_LIKE = 'DELETE_LIKE'; /** * _handleDeleteLikeRequest * @param postID * @private */ -export const _handleDeleteLikeRequest = (postID) => ({ type: DELETE_LIKE, postID,}) +export const _handleDeleteLikeRequest = postID => ({ + type: DELETE_LIKE, + postID, +}); /** * _handleDeleteLikeResponse @@ -111,7 +128,11 @@ export const _handleDeleteLikeRequest = (postID) => ({ type: DELETE_LIKE, postID * @param response * @private */ -export const _handleDeleteLikeResponse = (postID, response) => ({ type: DELETE_LIKE, postID, response, }) +export const _handleDeleteLikeResponse = (postID, response) => ({ + type: DELETE_LIKE, + postID, + response, +}); /** * deleteLike @@ -120,19 +141,23 @@ export const _handleDeleteLikeResponse = (postID, response) => ({ type: DELETE_L * @returns {Function} */ export function deleteLike(postID) { - return (dispatch, getState) => { - dispatch(_handleDeleteLikeRequest(postID)) - const data = { - user_id: getState().User.id, - upload_id: postID, - } - axios.delete(`${config.api.baseUrl}/likes?` + querystring.stringify(data), { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - } - }) - .then(res => { - dispatch(_handleDeleteLikeResponse(postID, res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_handleDeleteLikeRequest(postID)); + const data = { + user_id: getState().User.id, + upload_id: postID, + }; + axios + .delete( + `${config.api.baseUrl}/likes?` + querystring.stringify(data), + { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }, + ) + .then(res => { + dispatch(_handleDeleteLikeResponse(postID, res.data)); + }); + }; } diff --git a/app/modules/actions/Location.js b/app/modules/actions/Location.js index 291cb2d..c8b9e7e 100644 --- a/app/modules/actions/Location.js +++ b/app/modules/actions/Location.js @@ -1,18 +1,18 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'LOCATION_LOAD' +export const LOAD = 'LOCATION_LOAD'; /** * _loadRequest * @param location * @private */ -export const _loadRequest = (location) => ({ type: LOAD, location, }) +export const _loadRequest = location => ({ type: LOAD, location }); /** * _loadResponse @@ -20,7 +20,11 @@ export const _loadRequest = (location) => ({ type: LOAD, location, }) * @param response * @private */ -export const _loadResponse = (location, response) => ({ type: LOAD, location, response, }) +export const _loadResponse = (location, response) => ({ + type: LOAD, + location, + response, +}); /** * load @@ -31,15 +35,16 @@ export const _loadResponse = (location, response) => ({ type: LOAD, location, re * @returns {Function} */ export function load(location) { - return (dispatch) => { - dispatch(_loadRequest(location)) - axios.get(`${config.api.baseUrl}/locations?q=${location}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(location, res.data)) - }) - } + return dispatch => { + dispatch(_loadRequest(location)); + axios + .get(`${config.api.baseUrl}/locations?q=${location}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadResponse(location, res.data)); + }); + }; } diff --git a/app/modules/actions/Photo.js b/app/modules/actions/Photo.js index 24ff0c3..5544bb7 100644 --- a/app/modules/actions/Photo.js +++ b/app/modules/actions/Photo.js @@ -1,29 +1,26 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; -import { - Like as LikeActions, - Comments as CommentActions, -} from 'actions' +import { Like as LikeActions, Comments as CommentActions } from 'actions'; /** * LOAD * @type {string} */ -export const LOAD = 'PHOTO_LOAD' +export const LOAD = 'PHOTO_LOAD'; /** * _loadRequest * @private */ -const _loadRequest = () => ({ type: LOAD, }) +const _loadRequest = () => ({ type: LOAD }); /** * _loadResponse * @param response * @private */ -const _loadResponse = (response) => ({ type: LOAD, response, }) +const _loadResponse = response => ({ type: LOAD, response }); /** * load @@ -34,20 +31,21 @@ const _loadResponse = (response) => ({ type: LOAD, response, }) * @returns {Function} */ export function load(id) { - return dispatch => { - return new Promise((resolve) => { - dispatch(_loadRequest()) - axios.get(`${config.api.baseUrl}/upload?id=${id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(res.data)) - dispatch(CommentActions.load(id)) - dispatch(LikeActions.load(id)) - return resolve() - }) - }) - } + return dispatch => { + return new Promise(resolve => { + dispatch(_loadRequest()); + axios + .get(`${config.api.baseUrl}/upload?id=${id}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadResponse(res.data)); + dispatch(CommentActions.load(id)); + dispatch(LikeActions.load(id)); + return resolve(); + }); + }); + }; } diff --git a/app/modules/actions/Photos.js b/app/modules/actions/Photos.js index 628cd9e..15ddaf7 100644 --- a/app/modules/actions/Photos.js +++ b/app/modules/actions/Photos.js @@ -1,19 +1,19 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; -export const INJECT = 'PHOTOS_INJECT' +export const INJECT = 'PHOTOS_INJECT'; export function inject(posts) { - return { - type: INJECT, - posts, - } + return { + type: INJECT, + posts, + }; } /** * ADD * @type {string} */ -export const ADD = 'PHOTO_ADD' +export const ADD = 'PHOTO_ADD'; /** * add @@ -21,33 +21,33 @@ export const ADD = 'PHOTO_ADD' * @returns {{type: string, response: *}} */ export function add(response) { - return { - type: ADD, - response, - } + return { + type: ADD, + response, + }; } /** * LOAD * @type {string} */ -export const LOAD = 'PHOTOS_LOAD' +export const LOAD = 'PHOTOS_LOAD'; /** * _loadRequest * @private */ -const _loadRequest = () => ({ type: LOAD, }) +const _loadRequest = () => ({ type: LOAD }); /** * _loadResponse * @param response * @private */ -const _loadResponse = (response) => ({ type: LOAD, response, }) +const _loadResponse = response => ({ type: LOAD, response }); -export const ONBOARDING = 'PHOTOS_ONBOARDING' -const _loadOnboarding = (response) => ({ type: ONBOARDING, response, }) +export const ONBOARDING = 'PHOTOS_ONBOARDING'; +const _loadOnboarding = response => ({ type: ONBOARDING, response }); /** * load @@ -58,59 +58,59 @@ const _loadOnboarding = (response) => ({ type: ONBOARDING, response, }) * @returns {Function} */ export function load(id) { - return (dispatch, getState) => { - const userID = id || getState().User.id - dispatch(_loadRequest()) - - Promise.all([ - axios.get(`${config.api.baseUrl}/uploads?user_id=${userID}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}`, - }, - }), - axios.get(`${config.api.baseUrl}/active?user_id=${userID}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}`, - }, - }) - ]) - .then(res => { - dispatch(_loadResponse(res[0].data)) - dispatch(_loadOnboarding(res[1].data)) - }) - } + return (dispatch, getState) => { + const userID = id || getState().User.id; + dispatch(_loadRequest()); + + Promise.all([ + axios.get(`${config.api.baseUrl}/uploads?user_id=${userID}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }), + axios.get(`${config.api.baseUrl}/active?user_id=${userID}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }), + ]).then(res => { + dispatch(_loadResponse(res[0].data)); + dispatch(_loadOnboarding(res[1].data)); + }); + }; } -export const RELOAD = 'PHOTOS_RELOAD' -const _reloadResponse = response => ({ type: RELOAD, response, }) +export const RELOAD = 'PHOTOS_RELOAD'; +const _reloadResponse = response => ({ type: RELOAD, response }); export function reload() { - return (dispatch, getState) => { - const userID = getState().User.id - - axios.get(`${config.api.baseUrl}/uploads?user_id=${userID}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}`, - }, - }) - .then(res => { - dispatch(_reloadResponse(res.data)) - Promise.resolve() - }) - } + return (dispatch, getState) => { + const userID = getState().User.id; + + axios + .get(`${config.api.baseUrl}/uploads?user_id=${userID}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_reloadResponse(res.data)); + Promise.resolve(); + }); + }; } /** * LIKE * @type {string} */ -export const LIKE = 'PHOTOS_LIKE' +export const LIKE = 'PHOTOS_LIKE'; /** * _likeRequest * @private */ -const _likeRequest = () => ({ type: LIKE, }) +const _likeRequest = () => ({ type: LIKE }); /** * _likeResponse @@ -118,7 +118,7 @@ const _likeRequest = () => ({ type: LIKE, }) * @param response * @private */ -const _likeResponse = (postID, response) => ({ type: LIKE, postID, response, }) +const _likeResponse = (postID, response) => ({ type: LIKE, postID, response }); /** * like @@ -129,34 +129,35 @@ const _likeResponse = (postID, response) => ({ type: LIKE, postID, response, }) * @returns {Function} */ export function like(postID) { - return (dispatch, getState) => { - dispatch(_likeRequest()) - const data = { - user_id: getState().User.id, - upload_id: postID, - } - axios.post(`${config.api.baseUrl}/likes`, data, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}`, - }, - }) - .then(res => { - dispatch(_likeResponse(postID, res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_likeRequest()); + const data = { + user_id: getState().User.id, + upload_id: postID, + }; + axios + .post(`${config.api.baseUrl}/likes`, data, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_likeResponse(postID, res.data)); + }); + }; } /** * UNLIKE * @type {string} */ -export const UNLIKE = 'PHOTOS_UNLIKE' +export const UNLIKE = 'PHOTOS_UNLIKE'; /** * _unlikeRequest * @private */ -const _unlikeRequest = () => ({ type: UNLIKE, }) +const _unlikeRequest = () => ({ type: UNLIKE }); /** * _unlikeRequestResponse @@ -164,7 +165,11 @@ const _unlikeRequest = () => ({ type: UNLIKE, }) * @param response * @private */ -const _unlikeRequestResponse = (postID, response) => ({ type: UNLIKE, postID, response, }) +const _unlikeRequestResponse = (postID, response) => ({ + type: UNLIKE, + postID, + response, +}); /** * unlike @@ -175,45 +180,52 @@ const _unlikeRequestResponse = (postID, response) => ({ type: UNLIKE, postID, re * @returns {Function} */ export function unlike(postID) { - return (dispatch, getState) => { - return new Promise(resolve => { - dispatch(_unlikeRequest()) - const data = { - user_id: getState().User.id, - upload_id: postID, - } - axios.delete(`${config.api.baseUrl}/likes?user_id=${data.user_id}&upload_id=${data.upload_id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_unlikeRequestResponse(postID, res.data)) - resolve() - }) - }) - } + return (dispatch, getState) => { + return new Promise(resolve => { + dispatch(_unlikeRequest()); + const data = { + user_id: getState().User.id, + upload_id: postID, + }; + axios + .delete( + `${config.api + .baseUrl}/likes?user_id=${data.user_id}&upload_id=${data.upload_id}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem( + 'jwt', + )}`, + }, + }, + ) + .then(res => { + dispatch(_unlikeRequestResponse(postID, res.data)); + resolve(); + }); + }); + }; } /** * PAGINATE * @type {string} */ -export const PAGINATE = 'PHOTOS_PAGINATE' +export const PAGINATE = 'PHOTOS_PAGINATE'; /** * _paginateRequest * @param lastId * @private */ -const _paginateRequest = lastId => ({ type: PAGINATE, lastId, }) +const _paginateRequest = lastId => ({ type: PAGINATE, lastId }); /** * _paginateResponse * @param response * @private */ -const _paginateResponse = response => ({ type: PAGINATE, response, }) +const _paginateResponse = response => ({ type: PAGINATE, response }); /** * paginate @@ -223,23 +235,25 @@ const _paginateResponse = response => ({ type: PAGINATE, response, }) * @returns {Function} */ export function paginate() { - return (dispatch, getState) => { - const { - Pagination, - User, - } = getState() - if (Pagination.fetching) return; - dispatch(_paginateRequest(Pagination.lastId)) - axios.get(`${config.api.baseUrl}/uploads?user_id=${User.id}&last_id=${Pagination.lastId}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_paginateResponse(res.data)) - }) - } + return (dispatch, getState) => { + const { Pagination, User } = getState(); + if (Pagination.fetching) return; + dispatch(_paginateRequest(Pagination.lastId)); + axios + .get( + `${config.api + .baseUrl}/uploads?user_id=${User.id}&last_id=${Pagination.lastId}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }, + ) + .then(res => { + dispatch(_paginateResponse(res.data)); + }); + }; } -export const LOAD_HIDDEN = 'PHOTOS_LOAD_HIDDEN' -export const loadHidden = () => ({ type: LOAD_HIDDEN, }) +export const LOAD_HIDDEN = 'PHOTOS_LOAD_HIDDEN'; +export const loadHidden = () => ({ type: LOAD_HIDDEN }); diff --git a/app/modules/actions/Profile.js b/app/modules/actions/Profile.js index 3b61c9c..79ac389 100644 --- a/app/modules/actions/Profile.js +++ b/app/modules/actions/Profile.js @@ -1,18 +1,18 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'PROFILE_LOAD' +export const LOAD = 'PROFILE_LOAD'; /** * _loadRequest * @param userID * @private */ -export const _loadRequest = (userID) => ({ type: LOAD, userID, }) +export const _loadRequest = userID => ({ type: LOAD, userID }); /** * _loadResponse @@ -20,7 +20,11 @@ export const _loadRequest = (userID) => ({ type: LOAD, userID, }) * @param response * @private */ -export const _loadResponse = (userID, response) => ({ type: LOAD, userID, response, }) +export const _loadResponse = (userID, response) => ({ + type: LOAD, + userID, + response, +}); /** * load @@ -29,32 +33,33 @@ export const _loadResponse = (userID, response) => ({ type: LOAD, userID, respon * @returns {Function} */ export function load(userID) { - return (dispatch, getState) => { - dispatch(_loadRequest(userID)) - const user = getState().User - axios.get(`${config.api.baseUrl}/users/${userID}?user_id=${user.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(userID, res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_loadRequest(userID)); + const user = getState().User; + axios + .get(`${config.api.baseUrl}/users/${userID}?user_id=${user.id}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadResponse(userID, res.data)); + }); + }; } /** * FOLLOW * @type {string} */ -export const FOLLOW = 'PROFILE_FOLLOW' +export const FOLLOW = 'PROFILE_FOLLOW'; /** * _followRequest * @param userID * @private */ -export const _followRequest = (userID) => ({ type: FOLLOW, userID, }) +export const _followRequest = userID => ({ type: FOLLOW, userID }); /** * _followResponse @@ -62,7 +67,11 @@ export const _followRequest = (userID) => ({ type: FOLLOW, userID, }) * @param response * @private */ -export const _followResponse = (userID, response) => ({ type: FOLLOW, userID, response, }) +export const _followResponse = (userID, response) => ({ + type: FOLLOW, + userID, + response, +}); /** * follow @@ -71,42 +80,41 @@ export const _followResponse = (userID, response) => ({ type: FOLLOW, userID, re * @returns {Function} */ export function follow(userID) { - return (dispatch, getState) => { - return new Promise(resolve => { + return (dispatch, getState) => { + return new Promise(resolve => { + dispatch(_followRequest(userID)); + const user = getState().User; + const data = { + user_id: user.id, + follower_id: userID, + }; + axios + .post(`${config.api.baseUrl}/followers`, data, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_followResponse(userID, res.data)); - dispatch(_followRequest(userID)) - const user = getState().User - const data = { - user_id: user.id, - follower_id: userID, - } - axios.post(`${config.api.baseUrl}/followers`, data, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_followResponse(userID, res.data)) - - resolve() - }) - - }) - } + resolve(); + }); + }); + }; } /** * UNFOLLOW * @type {string} */ -export const UNFOLLOW = 'PROFILE_UNFOLLOW' +export const UNFOLLOW = 'PROFILE_UNFOLLOW'; /** * _unfollowRequest * @param userID * @private */ -export const _unfollowRequest = (userID) => ({ type: UNFOLLOW, userID, }) +export const _unfollowRequest = userID => ({ type: UNFOLLOW, userID }); /** * _unfollowResponse @@ -114,7 +122,11 @@ export const _unfollowRequest = (userID) => ({ type: UNFOLLOW, userID, }) * @param response * @private */ -export const _unfollowResponse = (userID, response) => ({ type: UNFOLLOW, userID, response, }) +export const _unfollowResponse = (userID, response) => ({ + type: UNFOLLOW, + userID, + response, +}); /** * unfollow @@ -125,19 +137,26 @@ export const _unfollowResponse = (userID, response) => ({ type: UNFOLLOW, userID * @returns {Function} */ export function unfollow(userID) { - return (dispatch, getState) => { - return new Promise(resolve => { - dispatch(_unfollowRequest(userID)) - const user = getState().User - axios.delete(`${config.api.baseUrl}/followers?user_id=${user.id}&follower_id=${userID}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - } - }) - .then(res => { - dispatch(_unfollowResponse(userID, res.data)) - resolve() - }) - }) - } + return (dispatch, getState) => { + return new Promise(resolve => { + dispatch(_unfollowRequest(userID)); + const user = getState().User; + axios + .delete( + `${config.api + .baseUrl}/followers?user_id=${user.id}&follower_id=${userID}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem( + 'jwt', + )}`, + }, + }, + ) + .then(res => { + dispatch(_unfollowResponse(userID, res.data)); + resolve(); + }); + }); + }; } diff --git a/app/modules/actions/Search.js b/app/modules/actions/Search.js index 051d56d..b5b146b 100644 --- a/app/modules/actions/Search.js +++ b/app/modules/actions/Search.js @@ -1,22 +1,24 @@ -import * as axios from 'axios' -import algoliasearch from 'algoliasearch' -import config from 'config' - -const algolia = algoliasearch(config.algolia.appId, config.algolia.searchOnlyKey) +import * as axios from 'axios'; +import algoliasearch from 'algoliasearch'; +import config from 'config'; +const algolia = algoliasearch( + config.algolia.appId, + config.algolia.searchOnlyKey, +); /** * SEARCH * @type {string} */ -export const SEARCH = 'SEARCH_SEARCH' +export const SEARCH = 'SEARCH_SEARCH'; /** * _searchRequest * @param term * @private */ -const _searchRequest = (term) => ({ type: SEARCH, term, }) +const _searchRequest = term => ({ type: SEARCH, term }); /** * _searchResponse @@ -24,7 +26,7 @@ const _searchRequest = (term) => ({ type: SEARCH, term, }) * @param response * @private */ -const _searchResponse = (term, response) => ({ type: SEARCH, term, response, }) +const _searchResponse = (term, response) => ({ type: SEARCH, term, response }); /** * search @@ -36,59 +38,52 @@ const _searchResponse = (term, response) => ({ type: SEARCH, term, response, }) * @returns {Function} */ export function search(term, type = 'all') { - - return dispatch => { - - // Initialize the 'cabin' index: - let index = algolia.initIndex('cabin'), - attrs = [] - - switch(type) { - case 'all': - attrs.push( - 'first_name', - 'last_name', - 'location', - 'hashtags', - ) - break; - case 'hashtags': - attrs.push('hashtags') - break - case 'user': - attrs.push( - 'first_name', - 'last_name', - ) - break - case 'location': - attrs.push('location') - break - } - - // Perform Algolia search: - index.search(term, { - attributesToHighlight: attrs, - hitsPerPage: 100 - }, (err, content) => { - dispatch(_searchResponse(term, content)) - }) - } - + return dispatch => { + // Initialize the 'cabin' index: + let index = algolia.initIndex('cabin'), + attrs = []; + + switch (type) { + case 'all': + attrs.push('first_name', 'last_name', 'location', 'hashtags'); + break; + case 'hashtags': + attrs.push('hashtags'); + break; + case 'user': + attrs.push('first_name', 'last_name'); + break; + case 'location': + attrs.push('location'); + break; + } + + // Perform Algolia search: + index.search( + term, + { + attributesToHighlight: attrs, + hitsPerPage: 100, + }, + (err, content) => { + dispatch(_searchResponse(term, content)); + }, + ); + }; } /** * TRIGGER * @type {string} */ -export const TRIGGER = 'SEARCH_TRIGGER' +export const TRIGGER = 'SEARCH_TRIGGER'; /** * _triggerRequest * @param search * @private */ -const _triggerRequest = (search) => ({ type: TRIGGER, search, }) +const _triggerRequest = search => ({ type: TRIGGER, search }); /** * _triggerResponse @@ -96,7 +91,11 @@ const _triggerRequest = (search) => ({ type: TRIGGER, search, }) * @param response * @private */ -const _triggerResponse = (search, response) => ({ type: TRIGGER, search, response, }) +const _triggerResponse = (search, response) => ({ + type: TRIGGER, + search, + response, +}); /** * trigger @@ -107,45 +106,46 @@ const _triggerResponse = (search, response) => ({ type: TRIGGER, search, respons * @returns {Function} */ export function trigger(search) { - return (dispatch, getState) => { - dispatch(_triggerRequest(search)) - /** + return (dispatch, getState) => { + dispatch(_triggerRequest(search)); + /** * data * @type {{user_id: *, search: *}} */ - const data = { - user_id: getState().User.id, - search: search.word, - } - axios.post(`${config.api.baseUrl}/searches`, data, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_triggerResponse(search, res.data)) - }) - } + const data = { + user_id: getState().User.id, + search: search.word, + }; + axios + .post(`${config.api.baseUrl}/searches`, data, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_triggerResponse(search, res.data)); + }); + }; } /** * RECENT * @type {string} */ -export const RECENT = 'SEARCH_RECENT' +export const RECENT = 'SEARCH_RECENT'; /** * _recentRequest * @private */ -const _recentRequest = () => ({ type: RECENT, }) +const _recentRequest = () => ({ type: RECENT }); /** * _recentResponse * @param response * @private */ -const _recentResponse = (response) => ({ type: RECENT, response, }) +const _recentResponse = response => ({ type: RECENT, response }); /** * recent @@ -155,37 +155,41 @@ const _recentResponse = (response) => ({ type: RECENT, response, }) * @returns {Function} */ export function recent() { - return (dispatch, getState) => { - dispatch(_recentRequest()) - axios.get(`${config.api.baseUrl}/searches?user_id=${getState().User.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_recentResponse(res.data)) - }) - } + return (dispatch, getState) => { + dispatch(_recentRequest()); + axios + .get( + `${config.api.baseUrl}/searches?user_id=${getState().User.id}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }, + ) + .then(res => { + dispatch(_recentResponse(res.data)); + }); + }; } /** * RESULTS * @type {string} */ -export const RESULTS = 'SEARCH_RESULTS' +export const RESULTS = 'SEARCH_RESULTS'; /** * _searchResultsRequest * @private */ -const _searchResultsRequest = () => ({ type: RESULTS, }) +const _searchResultsRequest = () => ({ type: RESULTS }); /** * _searchResultsResponse * @param response * @private */ -const _searchResultsResponse = (response) => ({ type: RESULTS, response, }) +const _searchResultsResponse = response => ({ type: RESULTS, response }); /** * results @@ -197,15 +201,22 @@ const _searchResultsResponse = (response) => ({ type: RESULTS, response, }) * @returns {Function} */ export function results(type, query) { - return dispatch => { - dispatch(_searchResultsRequest()) - axios.get(`${config.api.baseUrl}/uploads?type=${type}&query=${encodeURIComponent(query)}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_searchResultsResponse(res.data)) - }) - } + return dispatch => { + dispatch(_searchResultsRequest()); + axios + .get( + `${config.api + .baseUrl}/uploads?type=${type}&query=${encodeURIComponent( + query, + )}`, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }, + ) + .then(res => { + dispatch(_searchResultsResponse(res.data)); + }); + }; } diff --git a/app/modules/actions/Stats.js b/app/modules/actions/Stats.js index cf01fa3..2b99dbf 100644 --- a/app/modules/actions/Stats.js +++ b/app/modules/actions/Stats.js @@ -1,18 +1,18 @@ -import config from 'config' -import * as axios from 'axios' +import config from 'config'; +import * as axios from 'axios'; /** * LOAD * @type {string} */ -export const LOAD = 'STATS_LOAD' +export const LOAD = 'STATS_LOAD'; /** * _loadRequest * @param userId * @private */ -export const _loadRequest = (userId) => ({ type: LOAD, userId, }) +export const _loadRequest = userId => ({ type: LOAD, userId }); /** * _loadResponse @@ -20,7 +20,11 @@ export const _loadRequest = (userId) => ({ type: LOAD, userId, }) * @param response * @private */ -export const _loadResponse = (userId, response) => ({ type: LOAD, userId, response, }) +export const _loadResponse = (userId, response) => ({ + type: LOAD, + userId, + response, +}); /** * load @@ -31,129 +35,144 @@ export const _loadResponse = (userId, response) => ({ type: LOAD, userId, respon * @returns {Function} */ export function load(userId) { - return (dispatch, getState) => { - - dispatch(_loadRequest(userId)) - - axios.get(`${config.api.baseUrl}/stats/${userId}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(userId, res.data)) - }) - - Keen.ready(function() { - - let itemViewsQuery = new Keen.Query("count", { - event_collection: 'views', - timeframe: 'this_30_days', - filters: [{ - "property_name": 'postAuthorId', - "operator": 'eq', - "property_value": userId - }, { - "property_name": 'type', - "operator": 'eq', - "property_value": 'item' - }] - }) - - keenClient.run(itemViewsQuery, function(err, res) { - - if (err) { - //console.log(err) - return - } - - dispatch(_loadResponse(userId, { - 'itemViews': res.result - })) - - }) - - let profileViewsQuery = new Keen.Query("count", { - event_collection: 'views', - timeframe: 'this_30_days', - filters: [{ - property_name: 'profileUser', - operator: 'eq', - property_value: userId - }, { - property_name: 'type', - operator: 'eq', - property_value: 'user' - }] - }) - - keenClient.run(profileViewsQuery, function(err, res) { - - if (err) { - //console.log(err) - return - } - - dispatch(_loadResponse(userId, { - profileViews: res.result - })) - - }) - - let geoViewsQuery = new Keen.Query("count", { - event_collection: 'views', - timeframe: 'this_30_days', - filters: [{ - property_name: 'postAuthorId', - operator: 'eq', - property_value: userId - }, { - property_name: 'type', - operator: 'eq', - property_value: 'item' - }, { - property_name: 'ip_geo_info.city', - operator: 'ne', - property_value: null - }], - group_by: ['ip_geo_info.city', 'ip_geo_info.province', 'ip_geo_info.country'], - }) - - keenClient.run(geoViewsQuery, function(err, res) { - if (err) { - //console.log(err) - return - } - dispatch(_loadResponse(userId, { - 'geoViews': res.result.slice(0, 5) - })) - }) - - let newFollowersQuery = new Keen.Query('sum', { - event_collection: "follow", - timeframe: "this_30_days", - filters: [{ - property_name: 'targetId', - operator: 'eq', - property_value: userId - }], - target_property: 'directionInt' - }) - - keenClient.run(newFollowersQuery, function(err, res) { - - if (err) { - //console.log(err) - return - } - - dispatch(_loadResponse(userId, { - - 'newFollowers': res - })) - - }) - - }) - } + return (dispatch, getState) => { + dispatch(_loadRequest(userId)); + + axios + .get(`${config.api.baseUrl}/stats/${userId}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadResponse(userId, res.data)); + }); + + Keen.ready(function() { + let itemViewsQuery = new Keen.Query('count', { + event_collection: 'views', + timeframe: 'this_30_days', + filters: [ + { + property_name: 'postAuthorId', + operator: 'eq', + property_value: userId, + }, + { + property_name: 'type', + operator: 'eq', + property_value: 'item', + }, + ], + }); + + keenClient.run(itemViewsQuery, function(err, res) { + if (err) { + //console.log(err) + return; + } + + dispatch( + _loadResponse(userId, { + itemViews: res.result, + }), + ); + }); + + let profileViewsQuery = new Keen.Query('count', { + event_collection: 'views', + timeframe: 'this_30_days', + filters: [ + { + property_name: 'profileUser', + operator: 'eq', + property_value: userId, + }, + { + property_name: 'type', + operator: 'eq', + property_value: 'user', + }, + ], + }); + + keenClient.run(profileViewsQuery, function(err, res) { + if (err) { + //console.log(err) + return; + } + + dispatch( + _loadResponse(userId, { + profileViews: res.result, + }), + ); + }); + + let geoViewsQuery = new Keen.Query('count', { + event_collection: 'views', + timeframe: 'this_30_days', + filters: [ + { + property_name: 'postAuthorId', + operator: 'eq', + property_value: userId, + }, + { + property_name: 'type', + operator: 'eq', + property_value: 'item', + }, + { + property_name: 'ip_geo_info.city', + operator: 'ne', + property_value: null, + }, + ], + group_by: [ + 'ip_geo_info.city', + 'ip_geo_info.province', + 'ip_geo_info.country', + ], + }); + + keenClient.run(geoViewsQuery, function(err, res) { + if (err) { + //console.log(err) + return; + } + dispatch( + _loadResponse(userId, { + geoViews: res.result.slice(0, 5), + }), + ); + }); + + let newFollowersQuery = new Keen.Query('sum', { + event_collection: 'follow', + timeframe: 'this_30_days', + filters: [ + { + property_name: 'targetId', + operator: 'eq', + property_value: userId, + }, + ], + target_property: 'directionInt', + }); + + keenClient.run(newFollowersQuery, function(err, res) { + if (err) { + //console.log(err) + return; + } + + dispatch( + _loadResponse(userId, { + newFollowers: res, + }), + ); + }); + }); + }; } diff --git a/app/modules/actions/Stream.js b/app/modules/actions/Stream.js index 29a0851..0073a50 100644 --- a/app/modules/actions/Stream.js +++ b/app/modules/actions/Stream.js @@ -1,46 +1,42 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; import { - Photos as PhotosActions, - IncomingActivity as IncomingActivityActions, -} from 'actions' + Photos as PhotosActions, + IncomingActivity as IncomingActivityActions, +} from 'actions'; -export const CLEAR = 'STREAM_CLEAR' +export const CLEAR = 'STREAM_CLEAR'; export function clear() { - return { - type: CLEAR, - } + return { + type: CLEAR, + }; } export function timeline(data) { - return dispatch => { - - Promise.all(data.new.map(p => { - - const id = p.object.split(':')[1] - - return ( - axios.get(`${config.api.baseUrl}/upload?id=${id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - ) - - })).then(results => { - dispatch(PhotosActions.inject(results.map(r => r.data))) - }) - } + return dispatch => { + Promise.all( + data.new.map(p => { + const id = p.object.split(':')[1]; + + return axios.get(`${config.api.baseUrl}/upload?id=${id}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }); + }), + ).then(results => { + dispatch(PhotosActions.inject(results.map(r => r.data))); + }); + }; } +export const EVENT = 'STREAM_EVENT'; -export const EVENT = 'STREAM_EVENT' - -const _newEvent = data => ({ type: EVENT, count: data.new.length,}) +const _newEvent = data => ({ type: EVENT, count: data.new.length }); export function event(data) { - return dispatch => { - dispatch(_newEvent(data)) - dispatch(IncomingActivityActions.load()) - } + return dispatch => { + dispatch(_newEvent(data)); + dispatch(IncomingActivityActions.load()); + }; } diff --git a/app/modules/actions/Trending.js b/app/modules/actions/Trending.js index f03f6b0..d397d49 100644 --- a/app/modules/actions/Trending.js +++ b/app/modules/actions/Trending.js @@ -1,24 +1,24 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * LOAD * @type {string} */ -export const LOAD = 'TRENDING_LOAD' +export const LOAD = 'TRENDING_LOAD'; /** * _loadRequest * @private */ -const _loadRequest = () => ({ type: LOAD, }) +const _loadRequest = () => ({ type: LOAD }); /** * _loadResponse * @param response * @private */ -const _loadResponse = (response) => ({ type: LOAD, response, }) +const _loadResponse = response => ({ type: LOAD, response }); /** * trending @@ -28,16 +28,17 @@ const _loadResponse = (response) => ({ type: LOAD, response, }) * @returns {Function} */ export function load() { - return (dispatch, getState) => { - _loadRequest() - const user = getState().User - axios.get(`${config.api.baseUrl}/trending?user_id=${user.id}`, { - headers: { - Authorization: `Bearer ${localStorage.getItem('jwt')}` - }, - }) - .then(res => { - dispatch(_loadResponse(res.data)) - }) - } + return (dispatch, getState) => { + _loadRequest(); + const user = getState().User; + axios + .get(`${config.api.baseUrl}/trending?user_id=${user.id}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('jwt')}`, + }, + }) + .then(res => { + dispatch(_loadResponse(res.data)); + }); + }; } diff --git a/app/modules/actions/User.js b/app/modules/actions/User.js index 47a6cac..e90dc76 100644 --- a/app/modules/actions/User.js +++ b/app/modules/actions/User.js @@ -1,18 +1,18 @@ -import * as axios from 'axios' -import config from 'config' +import * as axios from 'axios'; +import config from 'config'; /** * FB_LOGIN * @type {string} */ -export const FB_LOGIN = 'USER_FB_LOGIN' +export const FB_LOGIN = 'USER_FB_LOGIN'; /** * _fbLoginInitial * @param initial * @private */ -const _fbLoginInitial = (initial) => ({ type: FB_LOGIN, initial, }) +const _fbLoginInitial = initial => ({ type: FB_LOGIN, initial }); /** * fbLogin @@ -23,42 +23,43 @@ const _fbLoginInitial = (initial) => ({ type: FB_LOGIN, initial, }) * @returns {Function} */ export function fbLogin(response) { - var token = response.authResponse.accessToken; - var userID = response.authResponse.userID; - return dispatch => { - axios.post(`${config.api.baseUrl}/users`, { - token : token, - fb_user_id : userID - }) - .then(function(res) { - localStorage.setItem('jwt', res.data.jwt); - dispatch(_fbLoginInitial(res.data)) - }) - .catch(function(res) { - window.location.reload() - dispatch(_fbLoginInitial(res.data)) - }); - } + var token = response.authResponse.accessToken; + var userID = response.authResponse.userID; + return dispatch => { + axios + .post(`${config.api.baseUrl}/users`, { + token: token, + fb_user_id: userID, + }) + .then(function(res) { + localStorage.setItem('jwt', res.data.jwt); + dispatch(_fbLoginInitial(res.data)); + }) + .catch(function(res) { + window.location.reload(); + dispatch(_fbLoginInitial(res.data)); + }); + }; } /** * LOGOUT * @type {string} */ -export const LOGOUT = 'USER_LOGOUT' +export const LOGOUT = 'USER_LOGOUT'; /** * _logoutRequest * @private */ -export const _logoutRequest = () => ({ type: LOGOUT, }) +export const _logoutRequest = () => ({ type: LOGOUT }); /** * _logoutResponse * @param response * @private */ -export const _logoutResponse = (response) => ({ type: LOGOUT, response, }) +export const _logoutResponse = response => ({ type: LOGOUT, response }); /** * logout @@ -68,19 +69,19 @@ export const _logoutResponse = (response) => ({ type: LOGOUT, response, }) * @returns {Function} */ export function logout() { - return dispatch => { - dispatch(_logoutRequest()) - FB.logout(response => { - dispatch(_logoutResponse(response)) - }) - } + return dispatch => { + dispatch(_logoutRequest()); + FB.logout(response => { + dispatch(_logoutResponse(response)); + }); + }; } /** * FOLLOW * @type {string} */ -export const FOLLOW = 'USER_FOLLOW' +export const FOLLOW = 'USER_FOLLOW'; /** * follow @@ -88,8 +89,8 @@ export const FOLLOW = 'USER_FOLLOW' * @returns {{type: string, user: *}} */ export function follow(user) { - return { - type: FOLLOW, - user, - } + return { + type: FOLLOW, + user, + }; } diff --git a/app/modules/actions/index.js b/app/modules/actions/index.js index 8dc2b19..69f7a6b 100644 --- a/app/modules/actions/index.js +++ b/app/modules/actions/index.js @@ -1,17 +1,17 @@ -export * as App from './App' -export * as User from './User' -export * as Photos from './Photos' -export * as Comments from './Comments' -export * as Like from './Like' -export * as Photo from './Photo' -export * as Stats from './Stats' -export * as Explore from './Explore' -export * as Trending from './Trending' -export * as Search from './Search' -export * as Location from './Location' -export * as Profile from './Profile' -export * as Header from './Header' -export * as Contributions from './Contributions' -export * as IncomingActivity from './IncomingActivity' -export * as FollowingActivity from './FollowingActivity' -export * as Stream from './Stream' +export * as App from './App'; +export * as User from './User'; +export * as Photos from './Photos'; +export * as Comments from './Comments'; +export * as Like from './Like'; +export * as Photo from './Photo'; +export * as Stats from './Stats'; +export * as Explore from './Explore'; +export * as Trending from './Trending'; +export * as Search from './Search'; +export * as Location from './Location'; +export * as Profile from './Profile'; +export * as Header from './Header'; +export * as Contributions from './Contributions'; +export * as IncomingActivity from './IncomingActivity'; +export * as FollowingActivity from './FollowingActivity'; +export * as Stream from './Stream'; diff --git a/app/modules/components/Activity/Actor.js b/app/modules/components/Activity/Actor.js index a344045..37f2042 100644 --- a/app/modules/components/Activity/Actor.js +++ b/app/modules/components/Activity/Actor.js @@ -1,36 +1,39 @@ -import React, { Component } from 'react' -import { Avatar } from 'components' -import { Link } from 'react-router' +import React, { Component } from 'react'; +import { Avatar } from 'components'; +import { Link } from 'react-router'; /** * Actor component */ export default class Actor extends Component { - - /** + /** * defaultProps * @type {{avatar: string, email: string, firstName: string, lastName: string}} */ - static defaultProps = { - avatar: '', - first_name: '', - last_name: '', - } + static defaultProps = { + avatar: '', + first_name: '', + last_name: '', + }; - /** + /** * render * @returns markup */ - render() { - return ( - -
                  -
                  - -
                  -
                  {this.props.first_name}
                  {this.props.last_name && this.props.last_name.charAt(0) + '.'}
                  -
                  - - ) - } + render() { + return ( + +
                  +
                  + +
                  +
                  + {this.props.first_name}
                  + {this.props.last_name && + this.props.last_name.charAt(0) + '.'} +
                  +
                  + + ); + } } diff --git a/app/modules/components/Activity/Commented.js b/app/modules/components/Activity/Commented.js index f322e12..f336b27 100644 --- a/app/modules/components/Activity/Commented.js +++ b/app/modules/components/Activity/Commented.js @@ -1,44 +1,50 @@ -import React, { Component } from 'react' +import React, { Component } from 'react'; -import Actor from './Actor' -import { Link } from 'react-router' -import config from 'config' +import Actor from './Actor'; +import { Link } from 'react-router'; +import config from 'config'; /** * Commented component */ export default class Commented extends Component { - - /** + /** * defaultProps * @type {{actor: {}, user: {}, timestamp: null, timeSince: string}} */ - static defaultProps = { - actor: {}, - user: {}, - time: null, - timeSince: '', - } + static defaultProps = { + actor: {}, + user: {}, + time: null, + timeSince: '', + }; - /** + /** * render * @returns markup */ - render() { - return ( -
                  -
                  - - - - -
                  -
                  -
                  - " -

                  {this.props.comment}

                  -
                  -
                  - ) - } + render() { + return ( +
                  +
                  + + + + +
                  +
                  +
                  + + " + +

                  + {this.props.comment} +

                  +
                  +
                  + ); + } } diff --git a/app/modules/components/Activity/Following.js b/app/modules/components/Activity/Following.js index bf4921a..32e3c4c 100644 --- a/app/modules/components/Activity/Following.js +++ b/app/modules/components/Activity/Following.js @@ -1,93 +1,92 @@ -import React, { Component } from 'react' +import React, { Component } from 'react'; -import Actor from './Actor' +import Actor from './Actor'; /** * Following component */ export default class Following extends Component { - - /** + /** * * @type {{actor: {}, user: {}, timestamp: null, timeSince: string, following: boolean, onFollowBack: Following.defaultProps.onFollowBack, onUnfollow: Following.defaultProps.onUnfollow}} */ - static defaultProps = { - actor: {}, - user: {}, - time: null, - timeSince: '', - following: false, + static defaultProps = { + actor: {}, + user: {}, + time: null, + timeSince: '', + following: false, - onFollowBack: () => { - }, - onUnfollow: () => { - }, - } + onFollowBack: () => {}, + onUnfollow: () => {}, + }; - /** + /** * handleFollowBack * @param e */ - handleFollowBack = (e) => { - e.preventDefault() + handleFollowBack = e => { + e.preventDefault(); - this.props.onFollowBack(e, this.props.actor) - } + this.props.onFollowBack(e, this.props.actor); + }; - /** + /** * handleUnfollow * @param e */ - handleUnfollow = (e) => { - e.preventDefault() + handleUnfollow = e => { + e.preventDefault(); - this.props.onUnfollow(e, this.props.actor) - } + this.props.onUnfollow(e, this.props.actor); + }; - /** + /** * renderFollowButton * @returns markup */ - renderFollowButton = () => { - - if (this.props.following) { - return ( -
                  - -
                  - ) - } - - return ( -
                  - -
                  - ) + renderFollowButton = () => { + if (this.props.following) { + return ( +
                  + +
                  + ); + } - } + return ( +
                  + +
                  + ); + }; - /** + /** * render * @returns markup */ - render() { - return ( -
                  - - {this.renderFollowButton()} -
                  - -
                  -
                  -

                  Followed, {this.props.timeSince}

                  -
                  -
                  - -
                  - -
                  -
                  -
                  - ) - } + render() { + return ( +
                  + + {this.renderFollowButton()} +
                  + +
                  +
                  +

                  + Followed, {this.props.timeSince} +

                  +
                  +
                  + +
                  + +
                  +
                  +
                  + ); + } } diff --git a/app/modules/components/Activity/Liked.js b/app/modules/components/Activity/Liked.js index f7e6d01..4a7a97a 100644 --- a/app/modules/components/Activity/Liked.js +++ b/app/modules/components/Activity/Liked.js @@ -1,60 +1,67 @@ -import React, { Component } from 'react' -import { Link } from 'react-router' -import config from 'config' +import React, { Component } from 'react'; +import { Link } from 'react-router'; +import config from 'config'; -import Actor from './Actor' +import Actor from './Actor'; -const Picture = props => ( -
                  - - - -
                  -) +const Picture = props => +
                  + + + +
                  ; /** * Liked component */ export default class Liked extends Component { - - /** + /** * defaultProps * @type {{pictures: Array}} */ - static defaultProps = { - activities: [], - } + static defaultProps = { + activities: [], + }; - /** + /** * renderMessage * @returns {*} */ - renderMessage = () => { - if (this.props.activity_count === 1) return 'Liked your picture' - return `Liked ${this.props.activity_count} pictures` - } + renderMessage = () => { + if (this.props.activity_count === 1) return 'Liked your picture'; + return `Liked ${this.props.activity_count} pictures`; + }; - /** + /** * render * @returns markup */ - render() { - return ( -
                  - -
                  - -
                  -
                  -

                  {this.renderMessage()}, {this.props.timeSince}

                  -
                  -
                  -
                  -
                  - {this.props.activities.slice(0,6).map((p, i) => )} -
                  -
                  -
                  - ) - } + render() { + return ( +
                  + +
                  + +
                  +
                  +

                  + {this.renderMessage()}, {this.props.timeSince} +

                  +
                  +
                  +
                  +
                  + {this.props.activities + .slice(0, 6) + .map((p, i) => + , + )} +
                  +
                  +
                  + ); + } } diff --git a/app/modules/components/Activity/index.js b/app/modules/components/Activity/index.js index df63135..c7af199 100644 --- a/app/modules/components/Activity/index.js +++ b/app/modules/components/Activity/index.js @@ -1,40 +1,39 @@ -import React, { Component, cloneElement } from 'react' +import React, { Component, cloneElement } from 'react'; -export Actor from './Actor' -export Following from './Following' -export Liked from './Liked' -export Commented from './Commented' +export Actor from './Actor'; +export Following from './Following'; +export Liked from './Liked'; +export Commented from './Commented'; -import moment from 'moment' +import moment from 'moment'; /** * Activity index component */ export class Item extends Component { - - /** + /** * defaultProps * @type {{type: null, timestamp: null, actor: {}}} */ - static defaultProps = { - verb: null, - time: null, - actor: {}, - } + static defaultProps = { + verb: null, + time: null, + actor: {}, + }; - /** + /** * render * @returns markup */ - render() { - return ( -
                • - {cloneElement(this.props.children, { - timestamp: this.props.time, - actor: this.props.actor, - timeSince: moment.utc(this.props.time).fromNow(), - })} -
                • - ) - } + render() { + return ( +
                • + {cloneElement(this.props.children, { + timestamp: this.props.time, + actor: this.props.actor, + timeSince: moment.utc(this.props.time).fromNow(), + })} +
                • + ); + } } diff --git a/app/modules/components/Avatar/index.js b/app/modules/components/Avatar/index.js index 0f0aa7c..1fab4c5 100644 --- a/app/modules/components/Avatar/index.js +++ b/app/modules/components/Avatar/index.js @@ -1,44 +1,46 @@ -import React, { Component } from 'react' +import React, { Component } from 'react'; const styles = { - root: { - backgroundColor: '#fafafa', - display: 'inline-block', - } -} + root: { + backgroundColor: '#fafafa', + display: 'inline-block', + }, +}; /** * Avatar index component */ class Avatar extends Component { - - /** + /** * defaultProps * @type {{email: null, height: number, imgHeight: number}} */ - static defaultProps = { - email_md5: null, - height: 155, - imgHeight: 400, - } + static defaultProps = { + email_md5: null, + height: 155, + imgHeight: 400, + }; - /** + /** * render * @returns markup */ - render() { - - const placeHolder = Object.assign({}, styles.root, { - height: this.props.height, - width: this.props.height, - }) - - if (!this.props.emailHash) return
                  - - return - - } + render() { + const placeHolder = Object.assign({}, styles.root, { + height: this.props.height, + width: this.props.height, + }); + + if (!this.props.emailHash) return
                  ; + + return ( + + ); + } } -export default Avatar +export default Avatar; diff --git a/app/modules/components/BackButton/index.js b/app/modules/components/BackButton/index.js index b45e65a..0f7f6d1 100644 --- a/app/modules/components/BackButton/index.js +++ b/app/modules/components/BackButton/index.js @@ -1,40 +1,46 @@ -import React, { Component } from 'react' -import { Link } from 'react-router' - +import React, { Component } from 'react'; +import { Link } from 'react-router'; /** * BackButton index component */ class BackButton extends Component { - - /** + /** * defaultProps * @type {{to: string, icon: XML, label: string}} */ - static defaultProps = { - to: '/', - icon: , - label: 'Back', - } + static defaultProps = { + to: '/', + icon: , + label: 'Back', + }; - /** + /** * render * @returns markup */ - render() { - - const content = {this.props.icon}{this.props.label} - - if (typeof this.props.to == 'string') { - return ( - {content} - ) - } - - return {content} - - } - + render() { + const content = ( + + {this.props.icon} + {this.props.label} + + ); + + if (typeof this.props.to == 'string') { + return ( + + {content} + + ); + } + + return ( + + {content} + + ); + } } -export default BackButton +export default BackButton; diff --git a/app/modules/components/Comment/index.js b/app/modules/components/Comment/index.js index 2720aec..79370a4 100644 --- a/app/modules/components/Comment/index.js +++ b/app/modules/components/Comment/index.js @@ -1,34 +1,33 @@ -import React, { Component } from 'react' -import { Link } from 'react-router' -import TimeAgo from '../TimeAgo' +import React, { Component } from 'react'; +import { Link } from 'react-router'; +import TimeAgo from '../TimeAgo'; /** * Comment index component */ class Comment extends Component { - - /** + /** * * @returns markup */ - render() { - return ( -
                  - -
                  - {this.props.firstName} {this.props.lastName.charAt(0) + '.'} -
                  - -
                  - -
                  -
                  - {this.props.comment} -
                  -
                  - ) - } - + render() { + return ( +
                  + +
                  + {this.props.firstName}{' '} + {this.props.lastName.charAt(0) + '.'} +
                  + +
                  + +
                  +
                  + {this.props.comment} +
                  +
                  + ); + } } -export default Comment +export default Comment; diff --git a/app/modules/components/Header/index.js b/app/modules/components/Header/index.js index ef7981e..f96aefa 100644 --- a/app/modules/components/Header/index.js +++ b/app/modules/components/Header/index.js @@ -1,133 +1,123 @@ -import React, {Component} from 'react' -import { connect } from 'react-redux' -import { Link, IndexLink, withRouter } from 'react-router' +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { Link, IndexLink, withRouter } from 'react-router'; -import Nav from '../../components/Nav' +import Nav from '../../components/Nav'; /** * Left component */ class Left extends Component { - - state = { - step: 0, - } - - shouldComponentUpdate(nextProps, nextState) { - return nextProps.step !== this.state.step - } - - componentDidMount() { - if (this.props.active) { - setTimeout(() => - this.setState({ step: this.state.step + 1}), 1) - } - } - - componentDidUpdate(oldProps, oldState) { - if (this.props.active != oldProps.active) { - - if (this.props.active) { - setTimeout(() => - this.setState({ step: this.state.step + 1}), 1) - } else { - this.setState({ step: 0, }) - } - } - - } - - getClasses = () => { - const classes = ['item', 'left'] - - if (this.props.active) { - classes.push( - this.state.step === 0 ? 'active-initial' : 'active' - ) - - } - - return classes - } - - /** + state = { + step: 0, + }; + + shouldComponentUpdate(nextProps, nextState) { + return nextProps.step !== this.state.step; + } + + componentDidMount() { + if (this.props.active) { + setTimeout(() => this.setState({ step: this.state.step + 1 }), 1); + } + } + + componentDidUpdate(oldProps, oldState) { + if (this.props.active != oldProps.active) { + if (this.props.active) { + setTimeout( + () => this.setState({ step: this.state.step + 1 }), + 1, + ); + } else { + this.setState({ step: 0 }); + } + } + } + + getClasses = () => { + const classes = ['item', 'left']; + + if (this.props.active) { + classes.push(this.state.step === 0 ? 'active-initial' : 'active'); + } + + return classes; + }; + + /** * render * @returns markup */ - render() { - return ( -
                  - - - -
                  - ) - } - + render() { + return ( +
                  + + + +
                  + ); + } } /** * Right component */ class Right extends Component { - - /** + /** * render * @returns markup */ - render() { - return ( -
                  - - - -
                  - ) - } - + render() { + return ( +
                  + + + +
                  + ); + } } /** * Header index component */ class Header extends Component { - - /** + /** * defaultProps * @type {{userID: null, left: markup, middle: markup}} */ - static defaultProps = { - userID: null, + static defaultProps = { + userID: null, - left: , - middle: