feat: prep for modern challenges (#15781)
* feat(seed): Add modern challenge * chore(react): Use prop-types package * feat: Initial refactor to redux-first-router BREAKING CHANGE: Everything is different! * feat: First rendering * feat(routes): Challenges view render but failing * fix(Challenges): Remove contain HOC * fix(RFR): Add params selector * fix(RFR): :en should be :lang * fix: Update berks utils for redux * fix(Map): Challenge link to arg * fix(Map): Add trailing slash to map page * fix(RFR): Use FCC Link Use fcc Link to get around issue of lang being undefined * fix(Router): Link to is required * fix(app): Rely on RFR state for app lang * chore(RFR): Remove unused RFR Link * fix(RFR): Hydrate initial challenge using RFR and RO * fix: Casing issue * fix(RFR): Undefined links * fix(RFR): Use onRoute<name> convention for route types * feat(server/react): Add helpful redux logging/throwing * fix(server/react): Strip out nonjson from state This prevents thunks in routesMap from breaking serialization * fix(RFR/Link): Should accept any renderable * fix(RFR): Get redirects working * fix(RFR): Redirects and not found's * fix(Map): Move challenge onClick handler * fix(Map): Allow Router.link to handle clicks after onClick * fix(routes): Remove react-router-redux * feat(Router): Add lang to all route actions by default * fix(entities): Only fetch challenge if not already loaded * fix(Files): Move files to own feature * chore(Challenges): Remove vestigial hints logic * fix(RFR): Update challenges on route challenges * fix(code-storage): Should use events instead of commands * fix(Map): ClickOnMap should not hold on to event * chore(lint): Use eslint-config-freecodecamp Closes #15938 * feat(Panes): Update panes on route instead of render * fix(Panes): Store panesmap and update on fetchchallenges * fix(Panes): Normalize panesmaps * fix(Panes): Remove filter from createpanemap * fix(Panes): Middleware on location meta object * feat(Panes): Filter preview on nonhtml challenges * build(babel): Add lodash babel plugin * chore(lint): Lint js files * fix(server/user-stats): Remove use of lodash chain this interferes with babel-plugin-lodash * feat(dev): Add remote redux devtools for ssr * fix(Panes): Dispatch mount action this is needed to trigger window/divider epics * fix(Panes): Getpane to use new panesmap format * fix(Panes): Always update panes after state this lets the panes logic be affected by changes in state
This commit is contained in:
committed by
Quincy Larson
parent
2e46e60557
commit
dbecdc5618
@@ -1,6 +1,11 @@
|
||||
import { Observable } from 'rx';
|
||||
import { createTypes, createAsyncTypes } from 'redux-create-types';
|
||||
import { combineActions, createAction, handleActions } from 'redux-actions';
|
||||
import {
|
||||
combineActions,
|
||||
createAction,
|
||||
createAsyncTypes,
|
||||
createTypes,
|
||||
handleActions
|
||||
} from 'berkeleys-redux-utils';
|
||||
import { createSelector } from 'reselect';
|
||||
import noop from 'lodash/noop';
|
||||
import identity from 'lodash/identity';
|
||||
@@ -10,6 +15,7 @@ import fetchUserEpic from './fetch-user-epic.js';
|
||||
import updateMyCurrentChallengeEpic from './update-my-challenge-epic.js';
|
||||
import fetchChallengesEpic from './fetch-challenges-epic.js';
|
||||
import navSizeEpic from './nav-size-epic.js';
|
||||
import { types as challenges } from '../routes/Challenges/redux';
|
||||
|
||||
import ns from '../ns.json';
|
||||
|
||||
@@ -21,14 +27,14 @@ export const epics = [
|
||||
];
|
||||
|
||||
export const types = createTypes([
|
||||
'onRouteHome',
|
||||
|
||||
'appMounted',
|
||||
'analytics',
|
||||
'updateTitle',
|
||||
'updateAppLang',
|
||||
|
||||
createAsyncTypes('fetchChallenge'),
|
||||
createAsyncTypes('fetchChallenges'),
|
||||
'updateCurrentChallenge',
|
||||
|
||||
'fetchUser',
|
||||
'addUser',
|
||||
@@ -80,6 +86,7 @@ export const createEventMetaCreator = ({
|
||||
}
|
||||
});
|
||||
|
||||
export const onRouteHome = createAction(types.onRouteHome);
|
||||
export const appMounted = createAction(types.appMounted);
|
||||
export const fetchChallenge = createAction(
|
||||
'' + types.fetchChallenge,
|
||||
@@ -96,9 +103,6 @@ export const fetchChallengesCompleted = createAction(
|
||||
(entities, result) => ({ entities, result }),
|
||||
entities => ({ entities })
|
||||
);
|
||||
export const updateCurrentChallenge = createAction(
|
||||
types.updateCurrentChallenge
|
||||
);
|
||||
|
||||
// updateTitle(title: String) => Action
|
||||
export const updateTitle = createAction(types.updateTitle);
|
||||
@@ -118,8 +122,6 @@ export const addUser = createAction(
|
||||
export const updateThisUser = createAction(types.updateThisUser);
|
||||
export const showSignIn = createAction(types.showSignIn);
|
||||
|
||||
export const updateAppLang = createAction(types.updateAppLang);
|
||||
|
||||
// used when server needs client to redirect
|
||||
export const delayedRedirect = createAction(types.delayedRedirect);
|
||||
|
||||
@@ -156,7 +158,6 @@ const initialState = {
|
||||
title: 'Learn To Code | freeCodeCamp',
|
||||
isSignInAttempted: false,
|
||||
user: '',
|
||||
lang: '',
|
||||
csrfToken: '',
|
||||
theme: 'default',
|
||||
// eventually this should be only in the user object
|
||||
@@ -165,7 +166,6 @@ const initialState = {
|
||||
};
|
||||
|
||||
export const getNS = state => state[ns];
|
||||
export const langSelector = state => getNS(state).lang;
|
||||
export const csrfSelector = state => getNS(state).csrfToken;
|
||||
export const themeSelector = state => getNS(state).theme;
|
||||
export const titleSelector = state => getNS(state).title;
|
||||
@@ -180,6 +180,8 @@ export const userSelector = createSelector(
|
||||
(username, userMap) => userMap[username] || {}
|
||||
);
|
||||
|
||||
export const isSignedInSelector = state => !!userSelector(state).username;
|
||||
|
||||
export const challengeSelector = createSelector(
|
||||
currentChallengeSelector,
|
||||
state => entitiesSelector(state).challenge,
|
||||
@@ -222,58 +224,46 @@ export const firstChallengeSelector = createSelector(
|
||||
}
|
||||
);
|
||||
|
||||
export default function createReducer() {
|
||||
const reducer = handleActions(
|
||||
{
|
||||
[types.updateTitle]: (state, { payload = 'Learn To Code' }) => ({
|
||||
...state,
|
||||
title: payload + ' | freeCodeCamp'
|
||||
}),
|
||||
export default handleActions(
|
||||
() => ({
|
||||
[types.updateTitle]: (state, { payload = 'Learn To Code' }) => ({
|
||||
...state,
|
||||
title: payload + ' | freeCodeCamp'
|
||||
}),
|
||||
|
||||
[types.updateThisUser]: (state, { payload: user }) => ({
|
||||
...state,
|
||||
user
|
||||
}),
|
||||
[types.fetchChallenge.complete]: (state, { payload }) => ({
|
||||
...state,
|
||||
currentChallenge: payload.currentChallenge
|
||||
}),
|
||||
[combineActions(
|
||||
types.fetchChallenge.complete,
|
||||
types.fetchChallenges.complete
|
||||
)]: (state, { payload }) => ({
|
||||
...state,
|
||||
superBlocks: payload.result.superBlocks
|
||||
}),
|
||||
[types.updateCurrentChallenge]: (state, { payload = '' }) => ({
|
||||
...state,
|
||||
currentChallenge: payload
|
||||
}),
|
||||
[types.updateAppLang]: (state, { payload = 'en' }) =>({
|
||||
...state,
|
||||
lang: payload
|
||||
}),
|
||||
[types.updateTheme]: (state, { payload = 'default' }) => ({
|
||||
...state,
|
||||
theme: payload
|
||||
}),
|
||||
[combineActions(types.showSignIn, types.updateThisUser)]: state => ({
|
||||
...state,
|
||||
isSignInAttempted: true
|
||||
}),
|
||||
[types.updateThisUser]: (state, { payload: user }) => ({
|
||||
...state,
|
||||
user
|
||||
}),
|
||||
[combineActions(
|
||||
types.fetchChallenge.complete,
|
||||
types.fetchChallenges.complete
|
||||
)]: (state, { payload }) => ({
|
||||
...state,
|
||||
superBlocks: payload.result.superBlocks
|
||||
}),
|
||||
[challenges.onRouteChallenges]: (state, { payload: { dashedName } }) => ({
|
||||
...state,
|
||||
currentChallenge: dashedName
|
||||
}),
|
||||
[types.updateTheme]: (state, { payload = 'default' }) => ({
|
||||
...state,
|
||||
theme: payload
|
||||
}),
|
||||
[combineActions(types.showSignIn, types.updateThisUser)]: state => ({
|
||||
...state,
|
||||
isSignInAttempted: true
|
||||
}),
|
||||
|
||||
[types.challengeSaved]: (state, { payload: { points = 0 } }) => ({
|
||||
...state,
|
||||
points
|
||||
}),
|
||||
[types.delayedRedirect]: (state, { payload }) => ({
|
||||
...state,
|
||||
delayedRedirect: payload
|
||||
})
|
||||
},
|
||||
initialState
|
||||
);
|
||||
|
||||
reducer.toString = () => ns;
|
||||
return reducer;
|
||||
}
|
||||
[types.challengeSaved]: (state, { payload: { points = 0 } }) => ({
|
||||
...state,
|
||||
points
|
||||
}),
|
||||
[types.delayedRedirect]: (state, { payload }) => ({
|
||||
...state,
|
||||
delayedRedirect: payload
|
||||
})
|
||||
}),
|
||||
initialState,
|
||||
ns
|
||||
);
|
||||
|
Reference in New Issue
Block a user