fix: order imports and remove circular dependencies (#41824)
* fix: remove circular dependency redux depended on templates/Challenges/redux and vice versa. This meant that import order mattered and confusing bugs could arise. (cherry picked from commit 7d67a4e70922bbb3051f2f9982dcc69e240d43dc) * feat: require imports to be in alphabetical order Import order generally does not matter, but there are edge cases (circular imports and css imports, for example) where changing order changes behaviour (cherry picked from commit b8d1393a91ec6e068caf8e8498a5c95df68c2b2c) * chore: order imports * fix: lift up challenge description + title comps This brings the classic Show closer to the others as they now all create the description and title components * fix: remove donation-saga/index circular import (cherry picked from commit 51a44ca668a700786d2744feffeae4fdba5fd207) * refactor: extract action-types from settings (cherry picked from commit 25e26124d691c84a0d0827d41dafb761c686fadd) * fix: lint errors * feat: prevent useless renames
This commit is contained in:
committed by
GitHub
parent
c7b27a53e7
commit
e118dda13a
@@ -1,27 +1,26 @@
|
||||
import { createAction, handleActions } from 'redux-actions';
|
||||
import { uniqBy } from 'lodash-es';
|
||||
import { createAction, handleActions } from 'redux-actions';
|
||||
import store from 'store';
|
||||
|
||||
import { createTypes, createAsyncTypes } from '../utils/create-types';
|
||||
import { createFetchUserSaga } from './fetch-user-saga';
|
||||
import { actionTypes as challengeTypes } from '../templates/Challenges/redux/action-types';
|
||||
import { CURRENT_CHALLENGE_KEY } from '../templates/Challenges/redux/current-challenge-saga';
|
||||
import { createAcceptTermsSaga } from './accept-terms-saga';
|
||||
import { actionTypes, ns } from './action-types';
|
||||
import { createAppMountSaga } from './app-mount-saga';
|
||||
import { createReportUserSaga } from './report-user-saga';
|
||||
import { createShowCertSaga } from './show-cert-saga';
|
||||
import { createNightModeSaga } from './night-mode-saga';
|
||||
import { createDonationSaga } from './donation-saga';
|
||||
import failedUpdatesEpic from './failed-updates-epic';
|
||||
import { createFetchUserSaga } from './fetch-user-saga';
|
||||
import { createGaSaga } from './ga-saga';
|
||||
|
||||
import hardGoToEpic from './hard-go-to-epic';
|
||||
import failedUpdatesEpic from './failed-updates-epic';
|
||||
import { createNightModeSaga } from './night-mode-saga';
|
||||
import { createReportUserSaga } from './report-user-saga';
|
||||
|
||||
import { actionTypes as settingsTypes } from './settings/action-types';
|
||||
import { createShowCertSaga } from './show-cert-saga';
|
||||
import updateCompleteEpic from './update-complete-epic';
|
||||
|
||||
import { types as settingsTypes } from './settings';
|
||||
import { types as challengeTypes } from '../templates/Challenges/redux/';
|
||||
// eslint-disable-next-line max-len
|
||||
import { CURRENT_CHALLENGE_KEY } from '../templates/Challenges/redux/current-challenge-saga';
|
||||
|
||||
export const ns = 'app';
|
||||
export { ns };
|
||||
|
||||
export const defaultFetchState = {
|
||||
pending: true,
|
||||
@@ -62,114 +61,92 @@ const initialState = {
|
||||
}
|
||||
};
|
||||
|
||||
export const types = createTypes(
|
||||
[
|
||||
'appMount',
|
||||
'hardGoTo',
|
||||
'allowBlockDonationRequests',
|
||||
'closeDonationModal',
|
||||
'preventBlockDonationRequests',
|
||||
'preventProgressDonationRequests',
|
||||
'openDonationModal',
|
||||
'onlineStatusChange',
|
||||
'resetUserData',
|
||||
'tryToShowDonationModal',
|
||||
'executeGA',
|
||||
'submitComplete',
|
||||
'updateComplete',
|
||||
'updateCurrentChallengeId',
|
||||
'updateFailed',
|
||||
'updateDonationFormState',
|
||||
...createAsyncTypes('fetchUser'),
|
||||
...createAsyncTypes('addDonation'),
|
||||
...createAsyncTypes('fetchProfileForUser'),
|
||||
...createAsyncTypes('acceptTerms'),
|
||||
...createAsyncTypes('showCert'),
|
||||
...createAsyncTypes('reportUser')
|
||||
],
|
||||
ns
|
||||
);
|
||||
|
||||
export const epics = [hardGoToEpic, failedUpdatesEpic, updateCompleteEpic];
|
||||
|
||||
export const sagas = [
|
||||
...createAcceptTermsSaga(types),
|
||||
...createAppMountSaga(types),
|
||||
...createDonationSaga(types),
|
||||
...createGaSaga(types),
|
||||
...createFetchUserSaga(types),
|
||||
...createShowCertSaga(types),
|
||||
...createReportUserSaga(types),
|
||||
...createNightModeSaga({ ...types, ...settingsTypes })
|
||||
...createAcceptTermsSaga(actionTypes),
|
||||
...createAppMountSaga(actionTypes),
|
||||
...createDonationSaga(actionTypes),
|
||||
...createGaSaga(actionTypes),
|
||||
...createFetchUserSaga(actionTypes),
|
||||
...createShowCertSaga(actionTypes),
|
||||
...createReportUserSaga(actionTypes),
|
||||
...createNightModeSaga({ ...actionTypes, ...settingsTypes })
|
||||
];
|
||||
|
||||
export const appMount = createAction(types.appMount);
|
||||
export const appMount = createAction(actionTypes.appMount);
|
||||
|
||||
export const tryToShowDonationModal = createAction(
|
||||
types.tryToShowDonationModal
|
||||
actionTypes.tryToShowDonationModal
|
||||
);
|
||||
|
||||
export const executeGA = createAction(types.executeGA);
|
||||
export const executeGA = createAction(actionTypes.executeGA);
|
||||
|
||||
export const allowBlockDonationRequests = createAction(
|
||||
types.allowBlockDonationRequests
|
||||
actionTypes.allowBlockDonationRequests
|
||||
);
|
||||
export const closeDonationModal = createAction(types.closeDonationModal);
|
||||
export const openDonationModal = createAction(types.openDonationModal);
|
||||
export const closeDonationModal = createAction(actionTypes.closeDonationModal);
|
||||
export const openDonationModal = createAction(actionTypes.openDonationModal);
|
||||
export const preventBlockDonationRequests = createAction(
|
||||
types.preventBlockDonationRequests
|
||||
actionTypes.preventBlockDonationRequests
|
||||
);
|
||||
export const preventProgressDonationRequests = createAction(
|
||||
types.preventProgressDonationRequests
|
||||
actionTypes.preventProgressDonationRequests
|
||||
);
|
||||
export const updateDonationFormState = createAction(
|
||||
types.updateDonationFormState
|
||||
actionTypes.updateDonationFormState
|
||||
);
|
||||
|
||||
export const onlineStatusChange = createAction(types.onlineStatusChange);
|
||||
export const onlineStatusChange = createAction(actionTypes.onlineStatusChange);
|
||||
|
||||
// TODO: re-evaluate this since /internal is no longer used.
|
||||
// `hardGoTo` is used to hit the API server directly
|
||||
// without going through /internal
|
||||
// used for things like /signin and /signout
|
||||
export const hardGoTo = createAction(types.hardGoTo);
|
||||
export const hardGoTo = createAction(actionTypes.hardGoTo);
|
||||
|
||||
export const submitComplete = createAction(types.submitComplete);
|
||||
export const updateComplete = createAction(types.updateComplete);
|
||||
export const updateFailed = createAction(types.updateFailed);
|
||||
export const submitComplete = createAction(actionTypes.submitComplete);
|
||||
export const updateComplete = createAction(actionTypes.updateComplete);
|
||||
export const updateFailed = createAction(actionTypes.updateFailed);
|
||||
|
||||
export const acceptTerms = createAction(types.acceptTerms);
|
||||
export const acceptTermsComplete = createAction(types.acceptTermsComplete);
|
||||
export const acceptTermsError = createAction(types.acceptTermsError);
|
||||
export const acceptTerms = createAction(actionTypes.acceptTerms);
|
||||
export const acceptTermsComplete = createAction(
|
||||
actionTypes.acceptTermsComplete
|
||||
);
|
||||
export const acceptTermsError = createAction(actionTypes.acceptTermsError);
|
||||
|
||||
export const fetchUser = createAction(types.fetchUser);
|
||||
export const fetchUserComplete = createAction(types.fetchUserComplete);
|
||||
export const fetchUserError = createAction(types.fetchUserError);
|
||||
export const fetchUser = createAction(actionTypes.fetchUser);
|
||||
export const fetchUserComplete = createAction(actionTypes.fetchUserComplete);
|
||||
export const fetchUserError = createAction(actionTypes.fetchUserError);
|
||||
|
||||
export const addDonation = createAction(types.addDonation);
|
||||
export const addDonationComplete = createAction(types.addDonationComplete);
|
||||
export const addDonationError = createAction(types.addDonationError);
|
||||
export const addDonation = createAction(actionTypes.addDonation);
|
||||
export const addDonationComplete = createAction(
|
||||
actionTypes.addDonationComplete
|
||||
);
|
||||
export const addDonationError = createAction(actionTypes.addDonationError);
|
||||
|
||||
export const fetchProfileForUser = createAction(types.fetchProfileForUser);
|
||||
export const fetchProfileForUser = createAction(
|
||||
actionTypes.fetchProfileForUser
|
||||
);
|
||||
export const fetchProfileForUserComplete = createAction(
|
||||
types.fetchProfileForUserComplete
|
||||
actionTypes.fetchProfileForUserComplete
|
||||
);
|
||||
export const fetchProfileForUserError = createAction(
|
||||
types.fetchProfileForUserError
|
||||
actionTypes.fetchProfileForUserError
|
||||
);
|
||||
|
||||
export const reportUser = createAction(types.reportUser);
|
||||
export const reportUserComplete = createAction(types.reportUserComplete);
|
||||
export const reportUserError = createAction(types.reportUserError);
|
||||
export const reportUser = createAction(actionTypes.reportUser);
|
||||
export const reportUserComplete = createAction(actionTypes.reportUserComplete);
|
||||
export const reportUserError = createAction(actionTypes.reportUserError);
|
||||
|
||||
export const resetUserData = createAction(types.resetUserData);
|
||||
export const resetUserData = createAction(actionTypes.resetUserData);
|
||||
|
||||
export const showCert = createAction(types.showCert);
|
||||
export const showCertComplete = createAction(types.showCertComplete);
|
||||
export const showCertError = createAction(types.showCertError);
|
||||
export const showCert = createAction(actionTypes.showCert);
|
||||
export const showCertComplete = createAction(actionTypes.showCertComplete);
|
||||
export const showCertError = createAction(actionTypes.showCertError);
|
||||
|
||||
export const updateCurrentChallengeId = createAction(
|
||||
types.updateCurrentChallengeId
|
||||
actionTypes.updateCurrentChallengeId
|
||||
);
|
||||
|
||||
export const completedChallengesSelector = state =>
|
||||
@@ -384,7 +361,7 @@ function spreadThePayloadOnUser(state, payload) {
|
||||
|
||||
export const reducer = handleActions(
|
||||
{
|
||||
[types.acceptTermsComplete]: (state, { payload }) => {
|
||||
[actionTypes.acceptTermsComplete]: (state, { payload }) => {
|
||||
const { appUsername } = state;
|
||||
return {
|
||||
...state,
|
||||
@@ -405,21 +382,21 @@ export const reducer = handleActions(
|
||||
}
|
||||
};
|
||||
},
|
||||
[types.allowBlockDonationRequests]: (state, { payload }) => {
|
||||
[actionTypes.allowBlockDonationRequests]: (state, { payload }) => {
|
||||
return {
|
||||
...state,
|
||||
recentlyClaimedBlock: payload
|
||||
};
|
||||
},
|
||||
[types.updateDonationFormState]: (state, { payload }) => ({
|
||||
[actionTypes.updateDonationFormState]: (state, { payload }) => ({
|
||||
...state,
|
||||
donationFormState: { ...state.donationFormState, ...payload }
|
||||
}),
|
||||
[types.addDonation]: state => ({
|
||||
[actionTypes.addDonation]: state => ({
|
||||
...state,
|
||||
donationFormState: { ...defaultDonationFormState, processing: true }
|
||||
}),
|
||||
[types.addDonationComplete]: state => {
|
||||
[actionTypes.addDonationComplete]: state => {
|
||||
const { appUsername } = state;
|
||||
return {
|
||||
...state,
|
||||
@@ -434,19 +411,19 @@ export const reducer = handleActions(
|
||||
donationFormState: { ...defaultDonationFormState, success: true }
|
||||
};
|
||||
},
|
||||
[types.addDonationError]: (state, { payload }) => ({
|
||||
[actionTypes.addDonationError]: (state, { payload }) => ({
|
||||
...state,
|
||||
donationFormState: { ...defaultDonationFormState, error: payload }
|
||||
}),
|
||||
[types.fetchUser]: state => ({
|
||||
[actionTypes.fetchUser]: state => ({
|
||||
...state,
|
||||
userFetchState: { ...defaultFetchState }
|
||||
}),
|
||||
[types.fetchProfileForUser]: state => ({
|
||||
[actionTypes.fetchProfileForUser]: state => ({
|
||||
...state,
|
||||
userProfileFetchState: { ...defaultFetchState }
|
||||
}),
|
||||
[types.fetchUserComplete]: (
|
||||
[actionTypes.fetchUserComplete]: (
|
||||
state,
|
||||
{ payload: { user, username, sessionMeta } }
|
||||
) => ({
|
||||
@@ -468,7 +445,7 @@ export const reducer = handleActions(
|
||||
...sessionMeta
|
||||
}
|
||||
}),
|
||||
[types.fetchUserError]: (state, { payload }) => ({
|
||||
[actionTypes.fetchUserError]: (state, { payload }) => ({
|
||||
...state,
|
||||
userFetchState: {
|
||||
pending: false,
|
||||
@@ -477,7 +454,7 @@ export const reducer = handleActions(
|
||||
error: payload
|
||||
}
|
||||
}),
|
||||
[types.fetchProfileForUserComplete]: (
|
||||
[actionTypes.fetchProfileForUserComplete]: (
|
||||
state,
|
||||
{ payload: { user, username } }
|
||||
) => {
|
||||
@@ -496,7 +473,7 @@ export const reducer = handleActions(
|
||||
}
|
||||
};
|
||||
},
|
||||
[types.fetchProfileForUserError]: (state, { payload }) => ({
|
||||
[actionTypes.fetchProfileForUserError]: (state, { payload }) => ({
|
||||
...state,
|
||||
userProfileFetchState: {
|
||||
pending: false,
|
||||
@@ -505,37 +482,37 @@ export const reducer = handleActions(
|
||||
error: payload
|
||||
}
|
||||
}),
|
||||
[types.onlineStatusChange]: (state, { payload: isOnline }) => ({
|
||||
[actionTypes.onlineStatusChange]: (state, { payload: isOnline }) => ({
|
||||
...state,
|
||||
isOnline
|
||||
}),
|
||||
[types.closeDonationModal]: state => ({
|
||||
[actionTypes.closeDonationModal]: state => ({
|
||||
...state,
|
||||
showDonationModal: false
|
||||
}),
|
||||
[types.openDonationModal]: state => ({
|
||||
[actionTypes.openDonationModal]: state => ({
|
||||
...state,
|
||||
showDonationModal: true
|
||||
}),
|
||||
[types.preventBlockDonationRequests]: state => ({
|
||||
[actionTypes.preventBlockDonationRequests]: state => ({
|
||||
...state,
|
||||
recentlyClaimedBlock: null
|
||||
}),
|
||||
[types.preventProgressDonationRequests]: state => ({
|
||||
[actionTypes.preventProgressDonationRequests]: state => ({
|
||||
...state,
|
||||
canRequestProgressDonation: false
|
||||
}),
|
||||
[types.resetUserData]: state => ({
|
||||
[actionTypes.resetUserData]: state => ({
|
||||
...state,
|
||||
appUsername: '',
|
||||
user: {}
|
||||
}),
|
||||
[types.showCert]: state => ({
|
||||
[actionTypes.showCert]: state => ({
|
||||
...state,
|
||||
showCert: {},
|
||||
showCertFetchState: { ...defaultFetchState }
|
||||
}),
|
||||
[types.showCertComplete]: (state, { payload }) => ({
|
||||
[actionTypes.showCertComplete]: (state, { payload }) => ({
|
||||
...state,
|
||||
showCert: payload,
|
||||
showCertFetchState: {
|
||||
@@ -544,7 +521,7 @@ export const reducer = handleActions(
|
||||
complete: true
|
||||
}
|
||||
}),
|
||||
[types.showCertError]: (state, { payload }) => ({
|
||||
[actionTypes.showCertError]: (state, { payload }) => ({
|
||||
...state,
|
||||
showCert: {},
|
||||
showCertFetchState: {
|
||||
@@ -554,7 +531,7 @@ export const reducer = handleActions(
|
||||
error: payload
|
||||
}
|
||||
}),
|
||||
[types.submitComplete]: (state, { payload }) => {
|
||||
[actionTypes.submitComplete]: (state, { payload }) => {
|
||||
let submittedchallenges = [{ ...payload, completedDate: Date.now() }];
|
||||
if (payload.challArray) {
|
||||
submittedchallenges = payload.challArray;
|
||||
|
Reference in New Issue
Block a user