move map as a supdirectory of challenges

This commit is contained in:
Berkeley Martinez
2016-05-10 19:28:40 -07:00
parent 33d3e94e62
commit 1eb6390b85
28 changed files with 93 additions and 383 deletions

View File

@ -10,7 +10,6 @@ import childRoutes from './routes';
// redux
import { createEpic } from 'redux-epic';
import createReducer from './create-reducer';
import middlewares from './middlewares';
import sagas from './sagas';
// general utils
@ -56,7 +55,6 @@ export default function createApp({
);
const enhancers = [
applyMiddleware(
...middlewares,
...sideMiddlewares,
sagaMiddleware
),

View File

@ -9,7 +9,6 @@ import {
reducer as jobsApp,
formNormalizer as jobsNormalizer
} from './routes/Jobs/redux';
import { reducer as map } from './routes/map/redux';
export default function createReducer(sideReducers = {}) {
return combineReducers({
@ -19,7 +18,6 @@ export default function createReducer(sideReducers = {}) {
hikesApp,
jobsApp,
challengesApp,
map,
form: formReducer.normalize(jobsNormalizer)
});
}

View File

@ -45,21 +45,3 @@ export const createErrorObserable = error => Observable.just({
type: types.handleError,
error
});
// challenges
// these need to be used by more than one route so we put them here
export const fetchChallenge = createAction(types.fetchChallenge);
export const fetchChallengeCompleted = createAction(
types.fetchChallengeCompleted,
(_, challenge) => challenge,
entities => ({ entities })
);
export const fetchChallenges = createAction(types.fetchChallenges);
export const fetchChallengesCompleted = createAction(
types.fetchChallengesCompleted,
(_, superBlocks) => superBlocks,
entities => ({ entities })
);
export const setChallenge = createAction(types.setChallenge);

View File

@ -3,5 +3,4 @@ export { default as actions } from './actions';
export { default as types } from './types';
import fetchUserSaga from './fetch-user-saga';
import fetchChallengesSaga from './fetch-challenges-saga';
export const sagas = [ fetchUserSaga, fetchChallengesSaga ];
export const sagas = [ fetchUserSaga ];

View File

@ -30,12 +30,6 @@ export default handleActions(
[types.updateNavHeight]: (state, { payload: navHeight }) => ({
...state,
navHeight
}),
// challenges
[types.fetchChallengesCompleted]: (state, { payload = [] }) => ({
...state,
superBlocks: payload
})
},
{
@ -46,7 +40,6 @@ export default handleActions(
isSignedIn: false,
csrfToken: '',
windowHeight: 0,
navHeight: 0,
superBlocks: []
navHeight: 0
}
);

View File

@ -18,12 +18,5 @@ export default createTypes([
// data handling
'updateChallengesData',
'updateJobsData',
'updateHikesData',
// challenges
'fetchChallenge',
'fetchChallenges',
'fetchChallengeCompleted',
'fetchChallengesCompleted',
'setChallenge'
'updateHikesData'
], 'app');

View File

@ -7,7 +7,7 @@ import PureComponent from 'react-pure-render/component';
import Challenge from './Challenge.jsx';
import Step from './step/Step.jsx';
import { fetchChallenge } from '../../../redux/actions';
import { fetchChallenge } from '../redux/actions';
import { challengeSelector } from '../redux/selectors';
const bindableActions = {

View File

@ -8,19 +8,20 @@ import { createSelector } from 'reselect';
import Map from './Map.jsx';
import {
clearFilter,
updateFilter
} from '../redux/actions';
import { setChallenge, fetchChallenges } from '../../../redux/actions';
updateFilter,
updateCurrentChallenge,
fetchChallenges
} from '../../redux/actions';
const bindableActions = {
clearFilter,
fetchChallenges,
updateFilter,
setChallenge
updateCurrentChallenge
};
const superBlocksSelector = createSelector(
state => state.app.superBlocks,
state => state.challengesApp.superBlocks,
state => state.entities.superBlock,
state => state.entities.block,
state => state.entities.challenge,
@ -49,7 +50,7 @@ const superBlocksSelector = createSelector(
const mapStateToProps = createSelector(
superBlocksSelector,
state => state.map.filter,
state => state.challengesApp.filter,
({ superBlocks }, filter) => {
return {
superBlocks,
@ -61,7 +62,7 @@ const mapStateToProps = createSelector(
const fetchOptions = {
fetchAction: 'fetchChallenges',
isPrimed({ superBlocks }) {
return Array.isArray(superBlocks) && superBlocks.length > 0;
return Array.isArray(superBlocks) && superBlocks.length > 1;
}
};
@ -72,7 +73,7 @@ export class ShowMap extends PureComponent {
filter: PropTypes.string,
superBlocks: PropTypes.array,
updateFilter: PropTypes.func,
setChallenge: PropTypes.func
updateCurrentChallenge: PropTypes.func
};
render() {

View File

@ -1,6 +1,7 @@
import Challenges from './components/Challenges.jsx';
import ShowMap from './components/map/Show.jsx';
export default {
export const challenges = {
path: 'challenges(/:dashedName)',
component: Challenges,
onEnter(nextState, replace) {
@ -10,3 +11,8 @@ export default {
}
}
};
export const map = {
path: 'map',
component: ShowMap
};

View File

@ -2,5 +2,33 @@ import { createAction } from 'redux-actions';
import types from './types';
// step
export const goToStep = createAction(types.goToStep);
export const setChallenge = createAction(types.setChallenge);
// challenges
export const fetchChallenge = createAction(types.fetchChallenge);
export const fetchChallengeCompleted = createAction(
types.fetchChallengeCompleted,
(_, challenge) => challenge,
entities => ({ entities })
);
export const fetchChallenges = createAction(types.fetchChallenges);
export const fetchChallengesCompleted = createAction(
types.fetchChallengesCompleted,
(_, superBlocks) => superBlocks,
entities => ({ entities })
);
export const updateCurrentChallenge = createAction(
types.updateCurrentChallenge
);
// map
export const updateFilter = createAction(
types.updateFilter,
e => e.target.value
);
export const clearFilter = createAction(types.clearFilter);

View File

@ -4,7 +4,7 @@ import {
createErrorObserable,
fetchChallengeCompleted,
fetchChallengesCompleted,
setChallenge
updateCurrentChallenge
} from './actions';
export default function fetchChallengesSaga(action$, getState, { services }) {
@ -22,7 +22,7 @@ export default function fetchChallengesSaga(action$, getState, { services }) {
if (type === fetchChallenge) {
return Observable.of(
fetchChallengeCompleted(entities, result),
setChallenge(entities.challenge[result])
updateCurrentChallenge(entities.challenge[result])
);
}
return Observable.just(fetchChallengesCompleted(entities, result));

View File

@ -1,3 +1,6 @@
export actions from './actions';
export reducer from './reducer';
export types from './types';
import fetchChallengesSaga from './fetch-challenges-saga';
export const sagas = [ fetchChallengesSaga ];

View File

@ -7,7 +7,9 @@ const initialState = {
challenge: '',
currentStep: 0,
previousStep: -1,
content: null
filter: '',
content: null,
superBlocks: []
};
function arrayToNewLineString(seedData = []) {
@ -21,12 +23,6 @@ function buildSeed({ challengeSeed = [] } = {}) {
export default handleActions(
{
[types.resetStep]: () => initialState,
[types.goToStep]: (state, { payload: step = 0 }) => ({
...state,
currentStep: step,
previousStep: state.currentStep
}),
[fetchChallengeCompleted]: (state, { payload = '' }) => ({
...state,
challenge: payload
@ -35,6 +31,28 @@ export default handleActions(
...state,
challenge: challenge.dashedName,
content: buildSeed(challenge)
}),
// map
[types.updateFilter]: (state, { payload = ''}) => ({
...state,
filter: payload
}),
[types.clearFilter]: (state) => ({
...state,
filter: ''
}),
[types.fetchChallengesCompleted]: (state, { payload = [] }) => ({
...state,
superBlocks: payload
}),
// step
[types.resetStep]: () => initialState,
[types.goToStep]: (state, { payload: step = 0 }) => ({
...state,
currentStep: step,
previousStep: state.currentStep
})
},
initialState

View File

@ -3,5 +3,15 @@ import createTypes from '../../../utils/create-types';
export default createTypes([
// step
'goToStep',
'setChallenge'
// challenges
'fetchChallenge',
'fetchChallenges',
'fetchChallengeCompleted',
'fetchChallengesCompleted',
'updateCurrentChallenge',
// map
'updateFilter',
'clearFilter'
], 'challenges');

View File

@ -1,274 +0,0 @@
import React, { PropTypes } from 'react';
import classnames from 'classnames';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { goToStep } from '../../redux/actions';
import PureComponent from 'react-pure-render/component';
import ReactTransitionReplace from 'react-css-transition-replace';
import { Button, Col, Image, Row } from 'react-bootstrap';
const mapStateToProps = createSelector(
state => state.challengesApp.currentStep,
state => state.challengesApp.previousStep,
(currentStep, previousStep) => ({
currentStep,
previousStep,
isGoingForward: currentStep > previousStep
})
);
const dispatchActions = {
goToStep
};
const transitionTimeout = 1000;
/* eslint-disable max-len, quotes */
const challenge = {
title: "Learn how Free Code Camp Works",
description: [
[
"http://i.imgur.com/6ibIavQ.jpg",
"A picture of Free Code Camp's 4 benefits: Get connected, Learn JavaScript, Build your Portfolio, Help nonprofits",
"Welcome to Free Code Camp. We're an open source community of busy people who learn to code and help nonprofits.",
"http://www.foo.com"
],
[
"http://i.imgur.com/Elb3dfj.jpg",
"A screenshot of some of our campers coding together in Toronto.",
"<bold>Learning to code is hard.</bold> To succeed, you'll need lots of practice and support. That's why we've created a rigorous curriculum and supportive community.",
""
],
[
"http://i.imgur.com/D7Y5luw.jpg",
"A graph of the rate of job growth against growth in computer science degree graduates. There are 1.4 million jobs and only 400 thousand people to fill them.",
"There are thousands of coding jobs currently going unfilled, and the demand for coders grows every year.",
""
],
[
"http://i.imgur.com/WD3STY6.jpg",
"Photos of three campers who've gotten jobs after learning to code at Free Code Camp.",
"Free Code Camp is a proven path to your first coding job. In fact, no one has actually completed our entire program, because campers get jobs before they're able to.",
""
],
[
"http://i.imgur.com/vLNso6h.jpg",
"An illustration showing that you will learn HTML5, CSS3, JavaScript, Databases, Git, Node.js, React and D3.",
"We have hundreds of optional coding challenges that will teach you fundamental web development technologies like HTML5, Node.js and databases.",
""
],
[
"http://i.imgur.com/UVB9hxp.jpg",
"An image of a camper at a cafe building projects on Free Code Camp.",
"We believe humans learn best by doing. So you'll spend most of your time actually building projects. We'll give you a list of specifications (agile user stories), and you'll figure out how to build apps that fulfill those specifications.",
""
],
[
"http://i.imgur.com/pbW7K5S.jpg",
"An image of showing our front end, back end, and data visualization certifications (400 hours each), our nonprofit projects (800 hours), and interview prep (80 hours) for a total of 2,080 hours of coding experience.",
"Our curriculum is divided into 4 certifications. These certifications are standardized, and instantly verifiable by your freelance clients and future employers. Like everything else at Free Code Camp, these certifications are free. We recommend doing them in order, but you are free to jump around. The first three certifications take 400 hours each, and the final certification takes 800 hours, and involves building real-life projects for nonprofits.",
""
],
[
"http://i.imgur.com/k8btNUB.jpg",
"A screenshot of our Front End Development Certificate",
"To earn our verified Front End Development Certification, you'll build 10 projects using HTML, CSS, jQuery, and JavaScript.",
""
],
[
"http://i.imgur.com/Et3iD74.jpg",
"A screenshot of our Data Visualization Certificate",
"To earn our Data Visualization Certification, you'll build 10 projects using React, Sass and D3.js.",
""
],
[
"http://i.imgur.com/8v3t84p.jpg",
"A screenshot of our Back End Development Certificate",
"To earn our Back End Development Certification, you'll build 10 projects using Node.js, Express, and MongoDB. You'll use Git and Heroku to deploy them to the cloud.",
""
],
[
"http://i.imgur.com/yXyxbDd.jpg",
"A screen shot of our nonprofit project directory.",
"After you complete all three of these certificates, you'll team up with another camper and use agile software development methodologies to build two real-life projects for nonprofits. You'll also add functionality to two legacy code nonprofit projects. By the time you finish, you'll have a portfolio of real apps that people use every day.",
""
],
[
"http://i.imgur.com/PDGQ9ZM.jpg",
"An image of campers building projects together in a cafe in Seoul.",
"If you complete all 2,080 hours worth of challenges and projects, you'll earn our Full Stack Development Certification. We'll offer you free coding interview practice. We even offer a job board where employers specifically hire campers who've earned Free Code Camp certifications.",
"http://foo.com"
]
]
};
/* eslint-disable max-len, quotes */
export class StepChallenge extends PureComponent {
static displayName = 'StepChallenge';
static defaultProps = {
currentStep: 0,
previousStep: -1
};
static propTypes = {
currentStep: PropTypes.number,
previousStep: PropTypes.number,
isGoingForward: PropTypes.bool,
goToStep: PropTypes.func
};
renderActionButton(action) {
if (!action) {
return null;
}
return (
<div>
<Button
block={ true }
bsSize='large'
bsStyle='primary'
href={ action }
target='_blank'>
Open link in new tab (this unlocks the next step)
</Button>
<div className='spacer' />
</div>
);
}
renderBackButton(index) {
const { goToStep } = this.props;
if (index === 0) {
return (
<Col
className='hidden-xs'
md={ 4 }>
{ ' ' }
</Col>
);
}
return (
<Button
bsSize='large'
bsStyle='primary'
className='col-sm-4 col-xs-12'
onClick={ () => goToStep(index - 1) }>
Go to my previous step
</Button>
);
}
renderNextButton(hasAction, index, numOfSteps, isCompleted) {
const { goToStep } = this.props;
const isLastStep = index + 1 >= numOfSteps;
const btnClass = classnames({
'col-sm-4 col-xs-12': true,
disabled: hasAction && !isCompleted
});
return (
<Button
bsSize='large'
bsStyle='primary'
className={ btnClass }
onClick={ () => !isLastStep ? goToStep(index + 1) : () => {} }>
{ isLastStep ? 'Finish challenge' : 'Go to my next step'}
</Button>
);
}
renderStep(step, currentStep, numOfSteps) {
if (!Array.isArray(step)) {
return null;
}
const [imgUrl, imgAlt, info, action] = step;
return (
<div
className=''
key={ imgUrl }>
<a href={ imgUrl }>
<Image
alt={ imgAlt }
responsive={ true }
src={ imgUrl } />
</a>
<Row>
<div className='spacer' />
<Col
md={ 8 }
mdOffset={ 2 }
sm={ 10 }
smOffset={ 1 }
xs={ 12 }>
<p
className='challenge-step-description'
dangerouslySetInnerHTML={{ __html: info }} />
</Col>
</Row>
<div className='spacer' />
<div className='challenge-button-block'>
{ this.renderActionButton(action) }
{ this.renderBackButton(currentStep) }
<Col
className='challenge-step-counter large-p text-center'
sm={ 4 }
xs={ 12 }>
( { currentStep + 1 } / { numOfSteps })
</Col>
{
this.renderNextButton(
!!action,
currentStep,
numOfSteps,
true
)
}
</div>
<div className='clearfix' />
</div>
);
}
renderImages(steps) {
// will preload all the image
if (!Array.isArray(steps)) {
return null;
}
return steps.map(([imgUrl, imgAlt]) => (
<div key={ imgUrl }>
<Image
alt={ imgAlt }
responsive={ true }
src={ imgUrl } />
</div>
));
}
render() {
const { currentStep, isGoingForward } = this.props;
const numOfSteps = Array.isArray(challenge.description) ?
challenge.description.length :
0;
const step = challenge.description[currentStep];
const transitionName = 'challenge-step-' +
(isGoingForward ? 'forward' : 'backward');
return (
<Col
md={ 8 }
mdOffset={ 2 }>
<ReactTransitionReplace
transitionEnterTimeout={ transitionTimeout }
transitionLeaveTimeout={ transitionTimeout }
transitionName={ transitionName }>
{ this.renderStep(step, currentStep, numOfSteps) }
</ReactTransitionReplace>
<div className='hidden'>
{ this.renderImages(challenge.description) }
</div>
<div className='spacer' />
</Col>
);
}
}
export default connect(mapStateToProps, dispatchActions)(StepChallenge);

View File

@ -1,7 +1,6 @@
import Jobs from './Jobs';
import Hikes from './Hikes';
import challenges from './challenges';
import map from './map';
import { map, challenges } from './challenges';
import NotFound from '../components/NotFound/index.jsx';
export default {

View File

@ -1,6 +0,0 @@
import ShowMap from './components/Show.jsx';
export default {
path: 'map',
component: ShowMap
};

View File

@ -1,9 +0,0 @@
import { createAction } from 'redux-actions';
import types from './types';
export const updateFilter = createAction(
types.updateFilter,
e => e.target.value
);
export const clearFilter = createAction(types.clearFilter);

View File

@ -1,5 +0,0 @@
export actions from './actions';
export reducer from './reducer';
export types from './types';
export const sagas = [];

View File

@ -1,18 +0,0 @@
import { handleActions } from 'redux-actions';
import types from './types';
const initialState = { filter: '' };
export default handleActions(
{
[types.updateFilter]: (state, { payload = ''}) => ({
...state,
filter: payload
}),
[types.clearFilter]: (state) => ({
...state,
filter: ''
})
},
initialState
);

View File

@ -1,6 +0,0 @@
import createTypes from '../../../utils/create-types';
export default createTypes([
'updateFilter',
'clearFilter'
], 'map');

View File

@ -1,11 +1,11 @@
import { sagas as appSagas } from './redux';
import { sagas as hikesSagas} from './routes/Hikes/redux';
import { sagas as jobsSagas } from './routes/Jobs/redux';
import { sagas as mapSagas } from './routes/map/redux';
import { sagas as challengeSagas } from './routes/challenges/redux';
export default [
...appSagas,
...hikesSagas,
...jobsSagas,
...mapSagas
...challengeSagas
];