From 80311262a4b430b6272610f8bfa6427248ebfb87 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Mon, 7 Aug 2017 21:25:11 -0400 Subject: [PATCH 1/8] Adding Immutable - Reselect - Redux Actions --- package.json | 5 ++++- yarn.lock | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 30c638f8c..17ca56215 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "fuzzy-search": "^1.4.0", + "immutable": "^3.8.1", "lodash.uniqby": "^4.7.0", "lowlight": "^1.5.0", "md5": "^2.2.1", @@ -68,10 +69,12 @@ "react-redux": "^5.0.2", "react-syntax-highlighter": "^5.6.2", "redux": "^3.6.0", + "redux-actions": "^2.2.1", "redux-logger": "^2.7.4", "redux-persist": "^4.3.1", "redux-persist-transform-encrypt": "^1.0.2", - "redux-thunk": "^2.2.0" + "redux-thunk": "^2.2.0", + "reselect": "^3.0.1" }, "devDependencies": { "@commitlint/cli": "^3.1.0", diff --git a/yarn.lock b/yarn.lock index ee3438022..205e0b3d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3118,7 +3118,7 @@ interpret@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.3.tgz#cbc35c62eeee73f19ab7b10a801511401afc0f90" -invariant@^2.0.0, invariant@^2.2.0: +invariant@^2.0.0, invariant@^2.2.0, invariant@^2.2.1: version "2.2.2" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360" dependencies: @@ -3997,7 +3997,7 @@ lodash@^3.5.0: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" -lodash@^4.0.0, lodash@^4.11.2, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1: +lodash@^4.0.0, lodash@^4.11.2, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -5332,6 +5332,19 @@ reduce-component@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/reduce-component/-/reduce-component-1.0.1.tgz#e0c93542c574521bea13df0f9488ed82ab77c5da" +reduce-reducers@^0.1.0: + version "0.1.2" + resolved "https://registry.yarnpkg.com/reduce-reducers/-/reduce-reducers-0.1.2.tgz#fa1b4718bc5292a71ddd1e5d839c9bea9770f14b" + +redux-actions@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/redux-actions/-/redux-actions-2.2.1.tgz#d64186b25649a13c05478547d7cd7537b892410d" + dependencies: + invariant "^2.2.1" + lodash "^4.13.1" + lodash-es "^4.17.4" + reduce-reducers "^0.1.0" + redux-logger@^2.7.4: version "2.10.2" resolved "https://registry.yarnpkg.com/redux-logger/-/redux-logger-2.10.2.tgz#3c5a5f0a6f32577c1deadf6655f257f82c6c3937" @@ -5480,6 +5493,10 @@ require-uncached@^1.0.2: caller-path "^0.1.0" resolve-from "^1.0.0" +reselect@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/reselect/-/reselect-3.0.1.tgz#efdaa98ea7451324d092b2b2163a6a1d7a9a2147" + resolve-from@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" From da0d70358a2dbde1f35bc7ba1763bbea18c21705 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Mon, 14 Aug 2017 06:26:57 -0500 Subject: [PATCH 2/8] Initial refactor for reducer / actions / constants --- src/organization/organization.action.js | 124 ++++++++++--------- src/organization/organization.constants.js | 9 ++ src/organization/organization.record.js | 3 + src/organization/organization.reducer.js | 132 ++++++++++++--------- src/organization/organization.selectors.js | 3 + src/organization/organization.type.js | 5 - 6 files changed, 156 insertions(+), 120 deletions(-) create mode 100644 src/organization/organization.constants.js create mode 100644 src/organization/organization.record.js create mode 100644 src/organization/organization.selectors.js delete mode 100644 src/organization/organization.type.js diff --git a/src/organization/organization.action.js b/src/organization/organization.action.js index 6f305c40c..b0dc05157 100644 --- a/src/organization/organization.action.js +++ b/src/organization/organization.action.js @@ -1,68 +1,80 @@ -import { fetchOrg, fetchOrgMembers, fetchUrl } from 'api'; -import { GET_ORG, GET_ORG_REPOS, GET_ORG_MEMBERS } from './organization.type'; +import { createAction } from 'redux-actions'; -export const getOrg = orgName => { - return (dispatch, getState) => { - const accessToken = getState().auth.accessToken; +import { + fetchOrg, + fetchOrgMembers, + fetchUrl, +} from 'api'; +import { + GET_ORG, + GET_ORG_LOADING, + GET_ORG_ERROR, + GET_ORG_REPOS, + GET_ORG_REPOS_LOADING, + GET_ORG_REPOS_ERROR, + GET_ORG_MEMBERS, + GET_ORG_MEMBERS_LOADING, + GET_ORG_MEMBERS_ERROR, +} from './organization.constants'; - dispatch({ type: GET_ORG.PENDING }); +export const getOrg = createAction(GET_ORG); +export const getOrgLoading = createAction(GET_ORG_LOADING); +export const getOrgError = createAction(GET_ORG_ERROR); +export const getOrgRepos = createAction(GET_ORG_REPOS); +export const getOrgReposLoading = createAction(GET_ORG_REPOS_LOADING); +export const getOrgReposError = createAction(GET_ORG_REPOS_ERROR); +export const getOrgMembers = createAction(GET_ORG_MEMBERS); +export const getOrgMembersLoading = createAction(GET_ORG_MEMBERS_LOADING); +export const getOrgMembersError = createAction(GET_ORG_MEMBERS_ERROR); - return fetchOrg(orgName, accessToken) - .then(data => { - dispatch({ - type: GET_ORG.SUCCESS, - payload: data, - }); - }) - .catch(error => { - dispatch({ - type: GET_ORG.ERROR, - payload: error, - }); - }); - }; +export const fetchOrganizations = orgName => (dispatch, getState) => { + // use a selector here + const accessToken = getState().auth.accessToken; + + dispatch(getOrgLoading(true)); + dispatch(getOrgError('')); + + return fetchOrg(orgName, accessToken) + .then(data => { + dispatch(getOrgLoading(false)); + dispatch(getOrg(data)); + }) + .catch(error => { + dispatch(getOrgLoading(false)); + dispatch(getOrgError(error)); + }); }; -export const getOrgRepos = url => { - return (dispatch, getState) => { - const accessToken = getState().auth.accessToken; +export const fetchOrganizationRepos = url => (dispatch, getState) => { + const accessToken = getState().auth.accessToken; - dispatch({ type: GET_ORG_REPOS.PENDING }); + dispatch(getOrgReposLoading(true)); + dispatch(getOrgReposError('')); - fetchUrl(url, accessToken) - .then(data => { - dispatch({ - type: GET_ORG_REPOS.SUCCESS, - payload: data, - }); - }) - .catch(error => { - dispatch({ - type: GET_ORG_REPOS.ERROR, - payload: error, - }); - }); - }; + fetchUrl(url, accessToken) + .then(data => { + dispatch(getOrgReposLoading(false)); + dispatch(getOrgRepos(data)); + }) + .catch(error => { + dispatch(getOrgReposLoading(false)); + dispatch(getOrgReposError(error)); + }); }; -export const getOrgMembers = orgName => { - return (dispatch, getState) => { - const accessToken = getState().auth.accessToken; +export const fetchOrganizationMembers = orgName => (dispatch, getState) => { + const accessToken = getState().auth.accessToken; - dispatch({ type: GET_ORG_MEMBERS.PENDING }); + dispatch(getOrgMembersLoading(true)); + dispatch(getOrgMembersError('')); - return fetchOrgMembers(orgName, accessToken) - .then(data => { - dispatch({ - type: GET_ORG_MEMBERS.SUCCESS, - payload: data, - }); - }) - .catch(error => { - dispatch({ - type: GET_ORG_MEMBERS.ERROR, - payload: error, - }); - }); - }; + return fetchOrgMembers(orgName, accessToken) + .then(data => { + dispatch(getOrgMembersLoading(true)); + dispatch(getOrgMembers(data)); + }) + .catch(error => { + dispatch(getOrgMembersLoading(true)); + dispatch(getOrgMembersError(error)); + }); }; diff --git a/src/organization/organization.constants.js b/src/organization/organization.constants.js new file mode 100644 index 000000000..76e3d0e2c --- /dev/null +++ b/src/organization/organization.constants.js @@ -0,0 +1,9 @@ +export const GET_ORG = 'GET_ORG'; +export const GET_ORG_LOADING = 'GET_ORG_LOADING'; +export const GET_ORG_ERROR = 'GET_ORG_ERROR'; +export const GET_ORG_REPOS = 'GET_ORG_REPOS'; +export const GET_ORG_REPOS_LOADING = 'GET_ORG_REPOS_LOADING'; +export const GET_ORG_REPOS_ERROR = 'GET_ORG_REPOS_ERROR'; +export const GET_ORG_MEMBERS = 'GET_ORG_MEMBERS'; +export const GET_ORG_MEMBERS_LOADING = 'GET_ORG_MEMBERS_LOADING'; +export const GET_ORG_MEMBERS_ERROR = 'GET_ORG_MEMBERS_ERROR'; diff --git a/src/organization/organization.record.js b/src/organization/organization.record.js new file mode 100644 index 000000000..d25099e8e --- /dev/null +++ b/src/organization/organization.record.js @@ -0,0 +1,3 @@ +import { Record } from 'immutable'; + +// WIP diff --git a/src/organization/organization.reducer.js b/src/organization/organization.reducer.js index 37df01601..c0a5544a8 100644 --- a/src/organization/organization.reducer.js +++ b/src/organization/organization.reducer.js @@ -1,4 +1,16 @@ -import { GET_ORG, GET_ORG_REPOS, GET_ORG_MEMBERS } from './organization.type'; +import { handleActions } from 'redux-actions'; + +import { + GET_ORG, + GET_ORG_LOADING, + GET_ORG_ERROR, + GET_ORG_REPOS, + GET_ORG_REPOS_LOADING, + GET_ORG_REPOS_ERROR, + GET_ORG_MEMBERS, + GET_ORG_MEMBERS_LOADING, + GET_ORG_MEMBERS_ERROR, +} from './organization.constants'; const initialState = { organization: {}, @@ -7,63 +19,65 @@ const initialState = { isPendingOrg: false, isPendingRepos: false, isPendingMembers: false, - error: '', + organizationError: '', + organizationRepositoriesError: '', + organizationMembersError: '', }; -export const organizationReducer = (state = initialState, action = {}) => { - switch (action.type) { - case GET_ORG.PENDING: - return { - ...state, - isPendingOrg: true, - }; - case GET_ORG.SUCCESS: - return { - ...state, - organization: action.payload, - isPendingOrg: false, - }; - case GET_ORG.ERROR: - return { - ...state, - error: action.payload, - isPendingOrg: false, - }; - case GET_ORG_REPOS.PENDING: - return { - ...state, - isPendingRepos: true, - }; - case GET_ORG_REPOS.SUCCESS: - return { - ...state, - repositories: action.payload, - isPendingRepos: false, - }; - case GET_ORG_REPOS.ERROR: - return { - ...state, - error: action.payload, - isPendingRepos: false, - }; - case GET_ORG_MEMBERS.PENDING: - return { - ...state, - isPendingMembers: true, - }; - case GET_ORG_MEMBERS.SUCCESS: - return { - ...state, - members: action.payload, - isPendingMembers: false, - }; - case GET_ORG_MEMBERS.ERROR: - return { - ...state, - error: action.payload, - isPendingMembers: false, - }; - default: - return state; - } -}; +export const organizationReducer = handleActions({ + [GET_ORG]: (state, payload) => { + return { + ...state, + organization: payload, + }; + }, + [GET_ORG_LOADING]: (state, payload) => { + return { + ...state, + isPendingOrg: payload, + }; + }, + [GET_ORG_ERROR]: (state, payload) => { + return { + ...state, + organizationError: payload, + }; + }, + [GET_ORG_REPOS]: (state, payload) => { + return { + ...state, + repositories: payload, + }; + }, + [GET_ORG_REPOS_LOADING]: (state, payload) => { + return { + ...state, + isPendingRepos: payload, + }; + }, + [GET_ORG_REPOS_ERROR]: (state, payload) => { + return { + ...state, + organizationRepositoriesError: payload, + }; + }, + [GET_ORG_MEMBERS]: (state, payload) => { + return { + ...state, + members: payload, + }; + }, + [GET_ORG_MEMBERS_LOADING]: (state, payload) => { + return { + ...state, + isPendingMembers: payload, + }; + }, + [GET_ORG_MEMBERS_ERROR]: (state, payload) => { + return { + ...state, + organizationMembersError: payload, + }; + }, +}, initialState); + diff --git a/src/organization/organization.selectors.js b/src/organization/organization.selectors.js new file mode 100644 index 000000000..18b574b7d --- /dev/null +++ b/src/organization/organization.selectors.js @@ -0,0 +1,3 @@ +import { createSelector } from 'reselect'; + +// WIP diff --git a/src/organization/organization.type.js b/src/organization/organization.type.js deleted file mode 100644 index 2e953d2aa..000000000 --- a/src/organization/organization.type.js +++ /dev/null @@ -1,5 +0,0 @@ -import { createActionSet } from 'utils'; - -export const GET_ORG = createActionSet('GET_ORG'); -export const GET_ORG_REPOS = createActionSet('GET_ORG_REPOS'); -export const GET_ORG_MEMBERS = createActionSet('GET_ORG_MEMBERS'); From ee8f82130949b09aa61606a8ada6227c55117299 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Sat, 19 Aug 2017 10:18:14 -0500 Subject: [PATCH 3/8] Add reselect into organizations --- root.reducer.js | 3 ++ src/organization/index.js | 1 + src/organization/organization.selectors.js | 46 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/root.reducer.js b/root.reducer.js index 07ca2eabf..31171a7b6 100644 --- a/root.reducer.js +++ b/root.reducer.js @@ -16,3 +16,6 @@ export const rootReducer = combineReducers({ search: searchReducer, notifications: notificationsReducer, }); + +// Used to get organization information in selectors +export const getOrganization = state => state.organization; diff --git a/src/organization/index.js b/src/organization/index.js index 56d5364cd..09c167b26 100644 --- a/src/organization/index.js +++ b/src/organization/index.js @@ -1,5 +1,6 @@ export * from './organization.action'; export * from './organization.reducer'; export * from './organization.type'; +export * from './organization.selectors'; export * from './screens'; diff --git a/src/organization/organization.selectors.js b/src/organization/organization.selectors.js index 18b574b7d..4617dd6f1 100644 --- a/src/organization/organization.selectors.js +++ b/src/organization/organization.selectors.js @@ -1,3 +1,47 @@ import { createSelector } from 'reselect'; +import { getOrganization as getOrganizationFromStore } from '../../root.reducer'; -// WIP +export const getOrganization = createSelector( + getOrganizationFromStore, + organization => organization.organization || {} +); + +export const getOrganizationRepositories = createSelector( + getOrganizationFromStore, + organization => organization.repositories || [] +); + +export const getOrganizationMemebers = createSelector( + getOrganizationFromStore, + organization => organization.repositories || [] +); + +export const getOrganizationIsPendingOrg = createSelector( + getOrganizationFromStore, + organization => organization.isPendingOrg || [] +); + +export const getOrganizationIsPendingRepos = createSelector( + getOrganizationFromStore, + organization => organization.isPendingRepos || [] +); + +export const getOrganizationIsPendingMembers = createSelector( + getOrganizationFromStore, + organization => organization.isPendingMembers || [] +); + +export const getOrganizationError = createSelector( + getOrganizationFromStore, + organization => organization.organizationError || [] +); + +export const getOrganizationRepositoriesError = createSelector( + getOrganizationFromStore, + organization => organization.organizationRepositoriesError || [] +); + +export const getOrganizationMembersError = createSelector( + getOrganizationFromStore, + organization => organization.organizationMembersError || [] +); From 9c7970f99ca17403c3f4feebb3b3d3d7cef4b5ff Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Sat, 19 Aug 2017 11:02:08 -0500 Subject: [PATCH 4/8] =?UTF-8?q?More=20refactor=C2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- root.reducer.js | 1 + src/auth/auth.selectors.js | 8 ++++ src/auth/index.js | 1 + src/organization/organization.selectors.js | 12 +++--- .../screens/organization-profile.screen.js | 43 +++++++++++++------ 5 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 src/auth/auth.selectors.js diff --git a/root.reducer.js b/root.reducer.js index 31171a7b6..5d91a886f 100644 --- a/root.reducer.js +++ b/root.reducer.js @@ -19,3 +19,4 @@ export const rootReducer = combineReducers({ // Used to get organization information in selectors export const getOrganization = state => state.organization; +export const getAuth = state => state.auth; diff --git a/src/auth/auth.selectors.js b/src/auth/auth.selectors.js new file mode 100644 index 000000000..4af737229 --- /dev/null +++ b/src/auth/auth.selectors.js @@ -0,0 +1,8 @@ +import { createSelector } from 'reselect'; + +import { getAuth as getAuthFromStore } from '../../root.reducer'; + +export const getAuthLanguage = createSelector( + getAuthFromStore, + auth => auth.getAuthLanguage +); diff --git a/src/auth/index.js b/src/auth/index.js index 9ef35c4bd..f3be03aea 100644 --- a/src/auth/index.js +++ b/src/auth/index.js @@ -1,5 +1,6 @@ export * from './auth.action'; export * from './auth.reducer'; export * from './auth.type'; +export * from './auth.selectors'; export * from './screens'; diff --git a/src/organization/organization.selectors.js b/src/organization/organization.selectors.js index 4617dd6f1..6e5c92666 100644 --- a/src/organization/organization.selectors.js +++ b/src/organization/organization.selectors.js @@ -18,30 +18,30 @@ export const getOrganizationMemebers = createSelector( export const getOrganizationIsPendingOrg = createSelector( getOrganizationFromStore, - organization => organization.isPendingOrg || [] + organization => organization.isPendingOrg || false ); export const getOrganizationIsPendingRepos = createSelector( getOrganizationFromStore, - organization => organization.isPendingRepos || [] + organization => organization.isPendingRepos || false ); export const getOrganizationIsPendingMembers = createSelector( getOrganizationFromStore, - organization => organization.isPendingMembers || [] + organization => organization.isPendingMembers || false ); export const getOrganizationError = createSelector( getOrganizationFromStore, - organization => organization.organizationError || [] + organization => organization.organizationError || '' ); export const getOrganizationRepositoriesError = createSelector( getOrganizationFromStore, - organization => organization.organizationRepositoriesError || [] + organization => organization.organizationRepositoriesError || '' ); export const getOrganizationMembersError = createSelector( getOrganizationFromStore, - organization => organization.organizationMembersError || [] + organization => organization.organizationMembersError || '' ); diff --git a/src/organization/screens/organization-profile.screen.js b/src/organization/screens/organization-profile.screen.js index 8ab15a4d2..ae398d431 100644 --- a/src/organization/screens/organization-profile.screen.js +++ b/src/organization/screens/organization-profile.screen.js @@ -2,7 +2,10 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { StyleSheet, RefreshControl } from 'react-native'; import { ListItem } from 'react-native-elements'; - +import { createStructuredSelector } from 'reselect'; +import { + getAuthLanguage, +} from 'auth'; import { ViewContainer, UserProfile, @@ -12,18 +15,32 @@ import { ParallaxScroll, EntityInfo, } from 'components'; -import { emojifyText, translate } from 'utils'; +import { + emojifyText, + translate, +} from 'utils'; import { colors, fonts } from 'config'; -import { getOrg, getOrgRepos, getOrgMembers } from '../index'; - -const mapStateToProps = state => ({ - organization: state.organization.organization, - repositories: state.organization.repositories, - members: state.organization.members, - isPendingOrg: state.organization.isPendingOrg, - isPendingRepos: state.organization.isPendingRepos, - isPendingMembers: state.organization.isPendingMembers, - language: state.auth.language, +import { + getOrg, + getOrgRepos, + getOrgMembers, + // Selectors + getOrganization, + getOrganizationRepositories, + getOrganizationMembers, + getOrganizationIsPendingOrg, + getOrganizationIsPendingRepos, + getOrganizationIsPendingMembers, +} from '../index'; + +const selectors = createStructuredSelector({ + organization: getOrganization, + repositories: getOrganizationRepositories, + members: getOrganizationMembers, + isPendingOrg: getOrganizationIsPendingOrg, + isPendingRepos: getOrganizationIsPendingRepos, + isPendingMembers: getOrganizationIsPendingMembers, + language: getAuthLanguage, }); const mapDispatchToProps = dispatch => ({ @@ -157,6 +174,6 @@ class OrganizationProfile extends Component { } export const OrganizationProfileScreen = connect( - mapStateToProps, + selectors, mapDispatchToProps )(OrganizationProfile); From 800fb1ea21ab012e92907a2e94755559909e3d68 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Sat, 19 Aug 2017 16:59:32 -0500 Subject: [PATCH 5/8] Fixing base selector errors --- root.reducer.js | 4 ---- src/auth/auth.selectors.js | 2 +- src/organization/index.js | 2 +- src/organization/organization.selectors.js | 5 +++-- .../screens/organization-profile.screen.js | 11 ++++++++++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/root.reducer.js b/root.reducer.js index 5d91a886f..07ca2eabf 100644 --- a/root.reducer.js +++ b/root.reducer.js @@ -16,7 +16,3 @@ export const rootReducer = combineReducers({ search: searchReducer, notifications: notificationsReducer, }); - -// Used to get organization information in selectors -export const getOrganization = state => state.organization; -export const getAuth = state => state.auth; diff --git a/src/auth/auth.selectors.js b/src/auth/auth.selectors.js index 4af737229..d11542d69 100644 --- a/src/auth/auth.selectors.js +++ b/src/auth/auth.selectors.js @@ -1,6 +1,6 @@ import { createSelector } from 'reselect'; -import { getAuth as getAuthFromStore } from '../../root.reducer'; +export const getAuthFromStore = state => state.auth; export const getAuthLanguage = createSelector( getAuthFromStore, diff --git a/src/organization/index.js b/src/organization/index.js index 09c167b26..ec9c14b2a 100644 --- a/src/organization/index.js +++ b/src/organization/index.js @@ -1,6 +1,6 @@ export * from './organization.action'; export * from './organization.reducer'; -export * from './organization.type'; +export * from './organization.constants'; export * from './organization.selectors'; export * from './screens'; diff --git a/src/organization/organization.selectors.js b/src/organization/organization.selectors.js index 6e5c92666..9f6f9aa00 100644 --- a/src/organization/organization.selectors.js +++ b/src/organization/organization.selectors.js @@ -1,5 +1,6 @@ import { createSelector } from 'reselect'; -import { getOrganization as getOrganizationFromStore } from '../../root.reducer'; + +const getOrganizationFromStore = state => state.organization; export const getOrganization = createSelector( getOrganizationFromStore, @@ -11,7 +12,7 @@ export const getOrganizationRepositories = createSelector( organization => organization.repositories || [] ); -export const getOrganizationMemebers = createSelector( +export const getOrganizationMembers = createSelector( getOrganizationFromStore, organization => organization.repositories || [] ); diff --git a/src/organization/screens/organization-profile.screen.js b/src/organization/screens/organization-profile.screen.js index ae398d431..aa217e191 100644 --- a/src/organization/screens/organization-profile.screen.js +++ b/src/organization/screens/organization-profile.screen.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { StyleSheet, RefreshControl } from 'react-native'; import { ListItem } from 'react-native-elements'; @@ -43,6 +44,14 @@ const selectors = createStructuredSelector({ language: getAuthLanguage, }); +const actionCreators = { + getOrg, + getOrgRepos, + getOrgMembers, +}; + +const actions = dispatch => bindActionCreators(actionCreators, dispatch); + const mapDispatchToProps = dispatch => ({ getOrgByDispatch: orgName => dispatch(getOrg(orgName)), getOrgReposByDispatch: url => dispatch(getOrgRepos(url)), @@ -175,5 +184,5 @@ class OrganizationProfile extends Component { export const OrganizationProfileScreen = connect( selectors, - mapDispatchToProps + actions )(OrganizationProfile); From 37f1d83360161c7af174fe3229c9aaab8b32bb52 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Sat, 19 Aug 2017 17:34:36 -0500 Subject: [PATCH 6/8] Completed refactor for Organization's code --- src/organization/organization.action.js | 4 +-- src/organization/organization.reducer.js | 18 ++++++------ src/organization/organization.selectors.js | 2 +- .../screens/organization-profile.screen.js | 29 +++++++------------ 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/organization/organization.action.js b/src/organization/organization.action.js index b0dc05157..51189fb25 100644 --- a/src/organization/organization.action.js +++ b/src/organization/organization.action.js @@ -70,11 +70,11 @@ export const fetchOrganizationMembers = orgName => (dispatch, getState) => { return fetchOrgMembers(orgName, accessToken) .then(data => { - dispatch(getOrgMembersLoading(true)); + dispatch(getOrgMembersLoading(false)); dispatch(getOrgMembers(data)); }) .catch(error => { - dispatch(getOrgMembersLoading(true)); + dispatch(getOrgMembersLoading(false)); dispatch(getOrgMembersError(error)); }); }; diff --git a/src/organization/organization.reducer.js b/src/organization/organization.reducer.js index c0a5544a8..e719ee919 100644 --- a/src/organization/organization.reducer.js +++ b/src/organization/organization.reducer.js @@ -25,55 +25,55 @@ const initialState = { }; export const organizationReducer = handleActions({ - [GET_ORG]: (state, payload) => { + [GET_ORG]: (state, { payload }) => { return { ...state, organization: payload, }; }, - [GET_ORG_LOADING]: (state, payload) => { + [GET_ORG_LOADING]: (state, { payload }) => { return { ...state, isPendingOrg: payload, }; }, - [GET_ORG_ERROR]: (state, payload) => { + [GET_ORG_ERROR]: (state, { payload }) => { return { ...state, organizationError: payload, }; }, - [GET_ORG_REPOS]: (state, payload) => { + [GET_ORG_REPOS]: (state, { payload }) => { return { ...state, repositories: payload, }; }, - [GET_ORG_REPOS_LOADING]: (state, payload) => { + [GET_ORG_REPOS_LOADING]: (state, { payload }) => { return { ...state, isPendingRepos: payload, }; }, - [GET_ORG_REPOS_ERROR]: (state, payload) => { + [GET_ORG_REPOS_ERROR]: (state, { payload }) => { return { ...state, organizationRepositoriesError: payload, }; }, - [GET_ORG_MEMBERS]: (state, payload) => { + [GET_ORG_MEMBERS]: (state, { payload }) => { return { ...state, members: payload, }; }, - [GET_ORG_MEMBERS_LOADING]: (state, payload) => { + [GET_ORG_MEMBERS_LOADING]: (state, { payload }) => { return { ...state, isPendingMembers: payload, }; }, - [GET_ORG_MEMBERS_ERROR]: (state, payload) => { + [GET_ORG_MEMBERS_ERROR]: (state, { payload }) => { return { ...state, organizationMembersError: payload, diff --git a/src/organization/organization.selectors.js b/src/organization/organization.selectors.js index 9f6f9aa00..a8f170a29 100644 --- a/src/organization/organization.selectors.js +++ b/src/organization/organization.selectors.js @@ -14,7 +14,7 @@ export const getOrganizationRepositories = createSelector( export const getOrganizationMembers = createSelector( getOrganizationFromStore, - organization => organization.repositories || [] + organization => organization.members || [] ); export const getOrganizationIsPendingOrg = createSelector( diff --git a/src/organization/screens/organization-profile.screen.js b/src/organization/screens/organization-profile.screen.js index aa217e191..56ce2726e 100644 --- a/src/organization/screens/organization-profile.screen.js +++ b/src/organization/screens/organization-profile.screen.js @@ -22,9 +22,9 @@ import { } from 'utils'; import { colors, fonts } from 'config'; import { - getOrg, - getOrgRepos, - getOrgMembers, + // actions + fetchOrganizations, + fetchOrganizationMembers, // Selectors getOrganization, getOrganizationRepositories, @@ -45,19 +45,12 @@ const selectors = createStructuredSelector({ }); const actionCreators = { - getOrg, - getOrgRepos, - getOrgMembers, + fetchOrganizations, + fetchOrganizationMembers, }; const actions = dispatch => bindActionCreators(actionCreators, dispatch); -const mapDispatchToProps = dispatch => ({ - getOrgByDispatch: orgName => dispatch(getOrg(orgName)), - getOrgReposByDispatch: url => dispatch(getOrgRepos(url)), - getOrgMembersByDispatch: orgName => dispatch(getOrgMembers(orgName)), -}); - const styles = StyleSheet.create({ listTitle: { color: colors.black, @@ -71,9 +64,9 @@ const styles = StyleSheet.create({ class OrganizationProfile extends Component { props: { - getOrgByDispatch: Function, + fetchOrganizations: Function, // getOrgReposByDispatch: Function, - getOrgMembersByDispatch: Function, + fetchOrganizationMembers: Function, organization: Object, // repositories: Array, members: Array, @@ -98,8 +91,8 @@ class OrganizationProfile extends Component { componentDidMount() { const organization = this.props.navigation.state.params.organization; - this.props.getOrgByDispatch(organization.login); - this.props.getOrgMembersByDispatch(organization.login); + this.props.fetchOrganizations(organization.login); + this.props.fetchOrganizationMembers(organization.login); } getOrgData = () => { @@ -107,8 +100,8 @@ class OrganizationProfile extends Component { this.setState({ refreshing: true }); Promise.all( - this.props.getOrgByDispatch(organization.login), - this.props.getOrgMembersByDispatch(organization.login) + this.props.fetchOrganizations(organization.login), + this.props.fetchOrganizationMembers(organization.login) ).then(() => { this.setState({ refreshing: false }); }); From 3e0e03813e227c01c02cc1d6d0218ca5f77f51f0 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Sat, 19 Aug 2017 17:36:29 -0500 Subject: [PATCH 7/8] Fix eslint error --- src/organization/organization.record.js | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/organization/organization.record.js diff --git a/src/organization/organization.record.js b/src/organization/organization.record.js deleted file mode 100644 index d25099e8e..000000000 --- a/src/organization/organization.record.js +++ /dev/null @@ -1,3 +0,0 @@ -import { Record } from 'immutable'; - -// WIP From a08f0b428af9d603b7f9c95eb11db0893d060300 Mon Sep 17 00:00:00 2001 From: Alejandro Nanez Date: Sat, 19 Aug 2017 17:46:28 -0500 Subject: [PATCH 8/8] Removing immutable --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index cf6f4a4c7..f5e0dc66a 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ }, "dependencies": { "fuzzy-search": "^1.4.0", - "immutable": "^3.8.1", "lodash.uniqby": "^4.7.0", "lowlight": "^1.5.0", "md5": "^2.2.1",