Merge pull request #8359 from FreeCodeCamp/greenkeeper-react-15.0.2
Update react to version 15.0.2 🚀
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
import { Actions } from 'thundercats';
|
||||
import { Observable } from 'rx';
|
||||
|
||||
|
||||
export default Actions({
|
||||
shouldBindMethods: true,
|
||||
refs: { displayName: 'AppActions' },
|
||||
|
||||
setTitle(title = 'Learn To Code') {
|
||||
return { title: title + ' | Free Code Camp' };
|
||||
},
|
||||
|
||||
getUser() {
|
||||
return this.readService$('user', null, null)
|
||||
.map(({
|
||||
username,
|
||||
picture,
|
||||
progressTimestamps = [],
|
||||
isFrontEndCert,
|
||||
isBackEndCert,
|
||||
isFullStackCert
|
||||
}) => {
|
||||
return {
|
||||
username,
|
||||
picture,
|
||||
points: progressTimestamps.length,
|
||||
isFrontEndCert,
|
||||
isBackEndCert,
|
||||
isFullStackCert
|
||||
};
|
||||
})
|
||||
.catch(err => Observable.just({ err }));
|
||||
},
|
||||
|
||||
// routing
|
||||
// goTo(path: String) => path
|
||||
goTo: null,
|
||||
|
||||
// goBack(arg?) => arg?
|
||||
goBack: null,
|
||||
|
||||
// toast(args: { type?: String, message: String, title: String }) => args
|
||||
toast(args) {
|
||||
return {
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
toast: {
|
||||
...args,
|
||||
id: state.toast && state.toast.id ? state.toast.id : 1
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
// updateLocation(location: { pathname: String }) => location
|
||||
updateLocation(location) {
|
||||
return {
|
||||
transform(state) {
|
||||
return { ...state, location };
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
@ -1,361 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import { Observable } from 'rx';
|
||||
import { Actions } from 'thundercats';
|
||||
import debugFactory from 'debug';
|
||||
|
||||
const debug = debugFactory('fcc:hikes:actions');
|
||||
const noOp = { transform: () => {} };
|
||||
|
||||
function getCurrentHike(hikes = [{}], dashedName, currentHike) {
|
||||
if (!dashedName) {
|
||||
debug('no dashedName');
|
||||
return hikes[0];
|
||||
}
|
||||
|
||||
const filterRegex = new RegExp(dashedName, 'i');
|
||||
if (currentHike && filterRegex.test(currentHike.dashedName)) {
|
||||
return currentHike;
|
||||
}
|
||||
|
||||
debug('setting new hike');
|
||||
return hikes
|
||||
.filter(({ dashedName }) => {
|
||||
return filterRegex.test(dashedName);
|
||||
})
|
||||
.reduce((throwAway, hike) => {
|
||||
return hike;
|
||||
}, currentHike || {});
|
||||
}
|
||||
|
||||
function findNextHike(hikes, id) {
|
||||
if (!id) {
|
||||
debug('find next hike no id provided');
|
||||
return hikes[0];
|
||||
}
|
||||
const currentIndex = _.findIndex(hikes, ({ id: _id }) => _id === id);
|
||||
return hikes[currentIndex + 1] || hikes[0];
|
||||
}
|
||||
|
||||
|
||||
function getMouse(e, [dx, dy]) {
|
||||
let { pageX, pageY, touches, changedTouches } = e;
|
||||
|
||||
// touches can be empty on touchend
|
||||
if (touches || changedTouches) {
|
||||
e.preventDefault();
|
||||
// these re-assigns the values of pageX, pageY from touches
|
||||
({ pageX, pageY } = touches[0] || changedTouches[0]);
|
||||
}
|
||||
|
||||
return [pageX - dx, pageY - dy];
|
||||
}
|
||||
|
||||
export default Actions({
|
||||
refs: { displayName: 'HikesActions' },
|
||||
shouldBindMethods: true,
|
||||
fetchHikes({ isPrimed, dashedName }) {
|
||||
if (isPrimed) {
|
||||
return {
|
||||
transform: (state) => {
|
||||
|
||||
const { hikesApp: oldState } = state;
|
||||
const currentHike = getCurrentHike(
|
||||
oldState.hikes,
|
||||
dashedName,
|
||||
oldState.currentHike
|
||||
);
|
||||
|
||||
const hikesApp = { ...oldState, currentHike };
|
||||
return Object.assign({}, state, { hikesApp });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return this.readService$('hikes', null, null)
|
||||
.map(hikes => {
|
||||
const currentHike = getCurrentHike(hikes, dashedName);
|
||||
return {
|
||||
transform(state) {
|
||||
const hikesApp = { ...state.hikesApp, currentHike, hikes };
|
||||
return { ...state, hikesApp };
|
||||
}
|
||||
};
|
||||
})
|
||||
.catch(err => Observable.just({
|
||||
transform(state) { return { ...state, err }; }
|
||||
}));
|
||||
},
|
||||
|
||||
toggleQuestions() {
|
||||
return {
|
||||
transform(state) {
|
||||
const hikesApp = {
|
||||
...state.hikesApp,
|
||||
showQuestions: !state.hikesApp.showQuestions,
|
||||
currentQuestion: 1
|
||||
};
|
||||
return { ...state, hikesApp };
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
grabQuestion(e) {
|
||||
let { pageX, pageY, touches } = e;
|
||||
if (touches) {
|
||||
e.preventDefault();
|
||||
// these re-assigns the values of pageX, pageY from touches
|
||||
({ pageX, pageY } = touches[0]);
|
||||
}
|
||||
const delta = [pageX, pageY];
|
||||
const mouse = [0, 0];
|
||||
|
||||
return {
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
isPressed: true,
|
||||
delta,
|
||||
mouse
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
releaseQuestion() {
|
||||
return {
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
isPressed: false,
|
||||
mouse: [0, 0]
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
moveQuestion({ e, delta }) {
|
||||
const mouse = getMouse(e, delta);
|
||||
|
||||
return {
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
mouse
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
answer({
|
||||
e,
|
||||
answer,
|
||||
userAnswer,
|
||||
hike: { id, name, tests, challengeType },
|
||||
currentQuestion,
|
||||
isSignedIn,
|
||||
delta,
|
||||
info,
|
||||
threshold
|
||||
}) {
|
||||
if (typeof userAnswer === 'undefined') {
|
||||
const [positionX] = getMouse(e, delta);
|
||||
|
||||
// question released under threshold
|
||||
if (Math.abs(positionX) < threshold) {
|
||||
return noOp;
|
||||
}
|
||||
|
||||
if (positionX >= threshold) {
|
||||
userAnswer = true;
|
||||
}
|
||||
|
||||
if (positionX <= -threshold) {
|
||||
userAnswer = false;
|
||||
}
|
||||
}
|
||||
|
||||
// incorrect question
|
||||
if (answer !== userAnswer) {
|
||||
const startShake = {
|
||||
transform(state) {
|
||||
const toast = !info ?
|
||||
state.toast :
|
||||
{
|
||||
id: state.toast && state.toast.id ? state.toast.id + 1 : 1,
|
||||
title: 'Hint',
|
||||
message: info,
|
||||
type: 'info'
|
||||
};
|
||||
|
||||
return {
|
||||
...state,
|
||||
toast,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
shake: true
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const removeShake = {
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
shake: false
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return Observable
|
||||
.just(removeShake)
|
||||
.delay(500)
|
||||
.startWith(startShake);
|
||||
}
|
||||
|
||||
// move to next question
|
||||
// index 0
|
||||
if (tests[currentQuestion]) {
|
||||
|
||||
return Observable.just({
|
||||
transform(state) {
|
||||
const hikesApp = {
|
||||
...state.hikesApp,
|
||||
mouse: [0, 0]
|
||||
};
|
||||
return { ...state, hikesApp };
|
||||
}
|
||||
})
|
||||
.delay(300)
|
||||
.startWith({
|
||||
transform(state) {
|
||||
|
||||
const hikesApp = {
|
||||
...state.hikesApp,
|
||||
currentQuestion: currentQuestion + 1,
|
||||
mouse: [ userAnswer ? 1000 : -1000, 0],
|
||||
isPressed: false
|
||||
};
|
||||
|
||||
return { ...state, hikesApp };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// challenge completed
|
||||
let update$;
|
||||
if (isSignedIn) {
|
||||
const body = { id, name, challengeType: +challengeType };
|
||||
update$ = this.postJSON$('/completed-challenge', body)
|
||||
// if post fails, will retry once
|
||||
.retry(3)
|
||||
.map(({ alreadyCompleted, points }) => ({
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
points,
|
||||
toast: {
|
||||
message:
|
||||
'Challenge saved.' +
|
||||
(alreadyCompleted ? '' : ' First time Completed!'),
|
||||
title: 'Saved',
|
||||
type: 'info',
|
||||
id: state.toast && state.toast.id ? state.toast.id + 1 : 1
|
||||
}
|
||||
};
|
||||
}
|
||||
}))
|
||||
.catch((errObj => {
|
||||
const err = new Error(errObj.message);
|
||||
err.stack = errObj.stack;
|
||||
return {
|
||||
transform(state) { return { ...state, err }; }
|
||||
};
|
||||
}));
|
||||
} else {
|
||||
update$ = Observable.just({ transform: (() => {}) });
|
||||
}
|
||||
|
||||
const challengeCompleted$ = Observable.just({
|
||||
transform(state) {
|
||||
const { hikes, currentHike: { id } } = state.hikesApp;
|
||||
const currentHike = findNextHike(hikes, id);
|
||||
|
||||
return {
|
||||
...state,
|
||||
points: isSignedIn ? state.points + 1 : state.points,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
currentHike,
|
||||
showQuestions: false,
|
||||
currentQuestion: 1,
|
||||
mouse: [0, 0]
|
||||
},
|
||||
toast: {
|
||||
title: 'Congratulations!',
|
||||
message: 'Challenge completed.' + (isSignedIn ? ' Saving...' : ''),
|
||||
id: state.toast && state.toast.id ?
|
||||
state.toast.id + 1 :
|
||||
1,
|
||||
type: 'success'
|
||||
},
|
||||
location: {
|
||||
action: 'PUSH',
|
||||
pathname: currentHike && currentHike.dashedName ?
|
||||
`/videos/${ currentHike.dashedName }` :
|
||||
'/videos'
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
const correctAnswer = {
|
||||
transform(state) {
|
||||
return {
|
||||
...state,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
isCorrect: true,
|
||||
isPressed: false,
|
||||
delta: [0, 0],
|
||||
mouse: [ userAnswer ? 1000 : -1000, 0]
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return Observable.merge(challengeCompleted$, update$)
|
||||
.delay(300)
|
||||
.startWith(correctAnswer)
|
||||
.catch(err => Observable.just({
|
||||
transform(state) { return { ...state, err }; }
|
||||
}));
|
||||
},
|
||||
resetHike() {
|
||||
return {
|
||||
transform(state) {
|
||||
return { ...state,
|
||||
hikesApp: {
|
||||
...state.hikesApp,
|
||||
currentQuestion: 1,
|
||||
showQuestions: false,
|
||||
mouse: [0, 0],
|
||||
delta: [0, 0]
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
@ -1,197 +0,0 @@
|
||||
import { Actions } from 'thundercats';
|
||||
import store from 'store';
|
||||
import { Observable } from 'rx';
|
||||
|
||||
import { nameSpacedTransformer } from '../../../../utils';
|
||||
|
||||
const assign = Object.assign;
|
||||
const jobsTranformer = nameSpacedTransformer('jobsApp');
|
||||
const noOper = { transform: () => {} };
|
||||
|
||||
export default Actions({
|
||||
refs: { displayName: 'JobActions' },
|
||||
shouldBindMethods: true,
|
||||
// findJob assumes that the job is already in the list of jobs
|
||||
findJob(id) {
|
||||
return {
|
||||
transform: jobsTranformer(oldState => {
|
||||
const { currentJob = {}, jobs = [] } = oldState;
|
||||
// currentJob already set
|
||||
// do nothing
|
||||
if (currentJob.id === id) {
|
||||
return null;
|
||||
}
|
||||
const foundJob = jobs.reduce((newJob, job) => {
|
||||
if (job.id === id) {
|
||||
return job;
|
||||
}
|
||||
return newJob;
|
||||
}, null);
|
||||
|
||||
// if no job found this will be null which is a op noop
|
||||
return foundJob ?
|
||||
assign({}, oldState, { currentJob: foundJob }) :
|
||||
null;
|
||||
})
|
||||
};
|
||||
},
|
||||
saveJobToDb({ goTo, job }) {
|
||||
return this.createService$('jobs', { job })
|
||||
.map(job => ({
|
||||
transform(state) {
|
||||
state.location = {
|
||||
action: 'PUSH',
|
||||
pathname: goTo
|
||||
};
|
||||
return {
|
||||
...state,
|
||||
jobsApp: {
|
||||
...state.jobs,
|
||||
currentJob: job
|
||||
}
|
||||
};
|
||||
}
|
||||
}))
|
||||
.catch(err => Observable.just({
|
||||
transform(state) {
|
||||
return { ...state, err };
|
||||
}
|
||||
}));
|
||||
},
|
||||
getJob(id) {
|
||||
return this.readService$('jobs', { id })
|
||||
.map(job => ({
|
||||
transform: jobsTranformer(state => {
|
||||
return { ...state, currentJob: job };
|
||||
})
|
||||
}))
|
||||
.catch(err => Observable.just({
|
||||
transform(state) {
|
||||
return { ...state, err };
|
||||
}
|
||||
}));
|
||||
},
|
||||
getJobs() {
|
||||
return this.readService$('jobs')
|
||||
.map(jobs => ({
|
||||
transform: jobsTranformer(state => {
|
||||
return { ...state, jobs };
|
||||
})
|
||||
}))
|
||||
.catch(err => Observable.just({
|
||||
transform(state) {
|
||||
return { ...state, err };
|
||||
}
|
||||
}));
|
||||
},
|
||||
openModal() {
|
||||
return {
|
||||
transform: jobsTranformer(state => ({ ...state, showModal: true }))
|
||||
};
|
||||
},
|
||||
closeModal() {
|
||||
return {
|
||||
transform: jobsTranformer(state => ({ ...state, showModal: false }))
|
||||
};
|
||||
},
|
||||
handleForm(value) {
|
||||
return {
|
||||
transform: jobsTranformer(oldState => {
|
||||
const { form } = oldState;
|
||||
const newState = assign({}, oldState);
|
||||
newState.form = assign(
|
||||
{},
|
||||
form,
|
||||
value
|
||||
);
|
||||
return newState;
|
||||
})
|
||||
};
|
||||
},
|
||||
saveForm: null,
|
||||
clearSavedForm: null,
|
||||
getSavedForm() {
|
||||
const form = store.get('newJob');
|
||||
if (form && !Array.isArray(form) && typeof form === 'object') {
|
||||
return {
|
||||
transform: jobsTranformer(state => {
|
||||
return { ...state, form };
|
||||
})
|
||||
};
|
||||
}
|
||||
return noOper;
|
||||
},
|
||||
setPromoCode({ target: { value = '' }} = {}) {
|
||||
return {
|
||||
transform: jobsTranformer(state => ({
|
||||
...state,
|
||||
promoCode: value.replace(/[^\d\w\s]/, '')
|
||||
}))
|
||||
};
|
||||
},
|
||||
applyCode({ id, code = '', type = null}) {
|
||||
const body = {
|
||||
id,
|
||||
code: code.replace(/[^\d\w\s]/, '')
|
||||
};
|
||||
if (type) {
|
||||
body.type = type;
|
||||
}
|
||||
return this.postJSON$('/api/promos/getButton', body)
|
||||
.map(({ promo }) => {
|
||||
if (!promo || !promo.buttonId) {
|
||||
return noOper;
|
||||
}
|
||||
const {
|
||||
fullPrice: price,
|
||||
buttonId,
|
||||
discountAmount,
|
||||
code: promoCode,
|
||||
name: promoName
|
||||
} = promo;
|
||||
|
||||
return {
|
||||
transform: jobsTranformer(state => ({
|
||||
...state,
|
||||
price,
|
||||
buttonId,
|
||||
discountAmount,
|
||||
promoCode,
|
||||
promoApplied: true,
|
||||
promoName
|
||||
}))
|
||||
};
|
||||
})
|
||||
.catch(err => Observable.just({
|
||||
transform(state) {
|
||||
return { ...state, err };
|
||||
}
|
||||
}));
|
||||
},
|
||||
clearPromo() {
|
||||
return {
|
||||
/* eslint-disable no-undefined */
|
||||
transform: jobsTranformer(state => ({
|
||||
...state,
|
||||
price: undefined,
|
||||
buttonId: undefined,
|
||||
discountAmount: undefined,
|
||||
promoCode: undefined,
|
||||
promoApplied: false,
|
||||
promoName: undefined
|
||||
}))
|
||||
/* eslint-enable no-undefined */
|
||||
};
|
||||
},
|
||||
init({ instance: jobActions }) {
|
||||
jobActions.saveForm.subscribe((form) => {
|
||||
store.set('newJob', form);
|
||||
});
|
||||
|
||||
jobActions.clearSavedForm.subscribe(() => {
|
||||
store.remove('newJob');
|
||||
});
|
||||
|
||||
return jobActions;
|
||||
}
|
||||
});
|
@ -105,9 +105,9 @@
|
||||
"passport-oauth": "^1.0.0",
|
||||
"passport-twitter": "^1.0.3",
|
||||
"pmx": "~0.5.5",
|
||||
"react": "~0.14.3",
|
||||
"react": "^15.0.2",
|
||||
"react-bootstrap": "~0.28.1",
|
||||
"react-dom": "~0.14.3",
|
||||
"react-dom": "^15.0.2",
|
||||
"react-motion": "~0.4.2",
|
||||
"react-pure-render": "^1.0.2",
|
||||
"react-redux": "^4.0.6",
|
||||
@ -127,8 +127,6 @@
|
||||
"sort-keys": "^1.1.1",
|
||||
"stampit": "^2.1.1",
|
||||
"store": "https://github.com/berkeleytrue/store.js.git#feature/noop-server",
|
||||
"thundercats": "^3.1.0",
|
||||
"thundercats-react": "~0.5.1",
|
||||
"url-regex": "^3.0.0",
|
||||
"validator": "^5.0.0",
|
||||
"webpack": "^1.9.12",
|
||||
|
Reference in New Issue
Block a user