2016-04-24 21:54:48 -07:00
|
|
|
import { Observable } from 'rx';
|
2016-01-27 11:34:44 -08:00
|
|
|
import { createAction } from 'redux-actions';
|
|
|
|
import types from './types';
|
|
|
|
|
2016-07-21 16:35:37 -07:00
|
|
|
const throwIfUndefined = () => {
|
|
|
|
throw new TypeError('Argument must not be of type `undefined`');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createEventMeta = ({
|
|
|
|
category = throwIfUndefined,
|
|
|
|
action = throwIfUndefined,
|
|
|
|
label,
|
|
|
|
value
|
|
|
|
} = throwIfUndefined) => ({
|
|
|
|
analytics: {
|
|
|
|
type: 'event',
|
|
|
|
category,
|
|
|
|
action,
|
|
|
|
label,
|
|
|
|
value
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export const trackEvent = createAction(
|
|
|
|
types.analytics,
|
|
|
|
null,
|
|
|
|
createEventMeta
|
|
|
|
);
|
|
|
|
|
|
|
|
export const trackSocial = createAction(
|
|
|
|
types.analytics,
|
|
|
|
null,
|
|
|
|
(
|
|
|
|
network = throwIfUndefined,
|
|
|
|
action = throwIfUndefined,
|
|
|
|
target = throwIfUndefined
|
|
|
|
) => ({
|
|
|
|
analytics: {
|
|
|
|
type: 'event',
|
|
|
|
network,
|
|
|
|
action,
|
|
|
|
target
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2016-01-27 11:34:44 -08:00
|
|
|
// updateTitle(title: String) => Action
|
|
|
|
export const updateTitle = createAction(types.updateTitle);
|
|
|
|
|
|
|
|
// fetchUser() => Action
|
|
|
|
// used in combination with fetch-user-saga
|
|
|
|
export const fetchUser = createAction(types.fetchUser);
|
|
|
|
|
2016-07-19 16:36:34 -07:00
|
|
|
// addUser(
|
2016-06-20 11:35:19 -07:00
|
|
|
// entities: { [userId]: User }
|
|
|
|
// ) => Action
|
|
|
|
export const addUser = createAction(
|
|
|
|
types.addUser,
|
|
|
|
() => {},
|
|
|
|
entities => ({ entities })
|
|
|
|
);
|
|
|
|
export const updateThisUser = createAction(types.updateThisUser);
|
2016-06-23 20:05:30 -07:00
|
|
|
export const showSignIn = createAction(types.showSignIn);
|
2016-08-03 15:32:22 -07:00
|
|
|
export const loadCurrentChallenge = createAction(
|
|
|
|
types.loadCurrentChallenge,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'clicked',
|
|
|
|
label: 'fcc logo clicked'
|
|
|
|
})
|
|
|
|
);
|
2016-08-03 15:26:05 -07:00
|
|
|
export const updateMyCurrentChallenge = createAction(
|
|
|
|
types.updateMyCurrentChallenge,
|
|
|
|
(username, currentChallengeId) => ({ username, currentChallengeId })
|
|
|
|
);
|
2016-01-27 11:34:44 -08:00
|
|
|
|
2016-06-20 11:35:19 -07:00
|
|
|
// updateUserPoints(username: String, points: Number) => Action
|
|
|
|
export const updateUserPoints = createAction(
|
|
|
|
types.updateUserPoints,
|
|
|
|
(username, points) => ({ username, points })
|
|
|
|
);
|
2016-07-19 16:36:34 -07:00
|
|
|
// updateUserFlag(username: String, flag: String) => Action
|
2016-07-16 10:38:06 -07:00
|
|
|
export const updateUserFlag = createAction(
|
|
|
|
types.updateUserFlag,
|
|
|
|
(username, flag) => ({ username, flag })
|
|
|
|
);
|
2016-07-19 16:36:34 -07:00
|
|
|
// updateUserEmail(username: String, email: String) => Action
|
|
|
|
export const updateUserEmail = createAction(
|
|
|
|
types.updateUserFlag,
|
|
|
|
(username, email) => ({ username, email })
|
|
|
|
);
|
|
|
|
// updateUserLang(username: String, lang: String) => Action
|
|
|
|
export const updateUserLang = createAction(
|
|
|
|
types.updateUserLang,
|
|
|
|
(username, lang) => ({ username, lang })
|
|
|
|
);
|
2016-07-20 15:06:44 -07:00
|
|
|
export const updateAppLang = createAction(types.updateAppLang);
|
2016-06-20 13:38:49 -07:00
|
|
|
// updateCompletedChallenges(username: String) => Action
|
|
|
|
export const updateCompletedChallenges = createAction(
|
|
|
|
types.updateCompletedChallenges
|
|
|
|
);
|
|
|
|
|
2016-06-09 16:02:51 -07:00
|
|
|
// used when server needs client to redirect
|
|
|
|
export const delayedRedirect = createAction(types.delayedRedirect);
|
2016-03-02 22:19:04 -08:00
|
|
|
|
|
|
|
// hardGoTo(path: String) => Action
|
|
|
|
export const hardGoTo = createAction(types.hardGoTo);
|
2016-03-05 21:06:04 -08:00
|
|
|
|
2016-05-11 21:14:08 -07:00
|
|
|
export const initWindowHeight = createAction(types.initWindowHeight);
|
2016-03-05 21:06:04 -08:00
|
|
|
export const updateWindowHeight = createAction(types.updateWindowHeight);
|
|
|
|
export const updateNavHeight = createAction(types.updateNavHeight);
|
2016-03-10 17:21:46 -08:00
|
|
|
|
|
|
|
|
|
|
|
// data
|
|
|
|
export const updateChallengesData = createAction(types.updateChallengesData);
|
|
|
|
export const updateJobsData = createAction(types.updateJobsData);
|
|
|
|
export const updateHikesData = createAction(types.updateHikesData);
|
2016-04-24 21:54:48 -07:00
|
|
|
|
2016-05-31 15:26:24 -07:00
|
|
|
export const createErrorObservable = error => Observable.just({
|
2016-04-24 21:54:48 -07:00
|
|
|
type: types.handleError,
|
|
|
|
error
|
|
|
|
});
|
2016-07-19 16:36:34 -07:00
|
|
|
// doActionOnError(
|
|
|
|
// actionCreator: (() => Action|Null)
|
|
|
|
// ) => (error: Error) => Observable[Action]
|
|
|
|
export const doActionOnError = actionCreator => error => Observable.of(
|
|
|
|
{
|
|
|
|
type: types.handleError,
|
|
|
|
error
|
|
|
|
},
|
|
|
|
actionCreator()
|
|
|
|
);
|
2016-06-03 13:43:42 -07:00
|
|
|
|
|
|
|
|
|
|
|
// drawers
|
2016-07-21 16:35:37 -07:00
|
|
|
export const toggleMapDrawer = createAction(
|
|
|
|
types.toggleMapDrawer,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'toggled',
|
|
|
|
label: 'Map drawer toggled'
|
|
|
|
})
|
|
|
|
);
|
2016-07-29 16:51:32 -07:00
|
|
|
export const closeMapDrawer = createAction(
|
|
|
|
types.closeMapDrawer,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'clicked',
|
|
|
|
label: 'Map drawer closed'
|
|
|
|
})
|
|
|
|
);
|
2016-07-21 16:35:37 -07:00
|
|
|
export const toggleMainChat = createAction(
|
|
|
|
types.toggleMainChat,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'toggled',
|
|
|
|
label: 'Main chat toggled'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
export const toggleHelpChat = createAction(
|
|
|
|
types.toggleHelpChat,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Challenge',
|
|
|
|
action: 'toggled',
|
|
|
|
label: 'help chat toggled'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
export const openHelpChat = createAction(
|
|
|
|
types.openHelpChat,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Challenge',
|
|
|
|
action: 'opened',
|
|
|
|
label: 'help chat opened'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
export const closeHelpChat = createAction(
|
|
|
|
types.closeHelpChat,
|
|
|
|
null,
|
|
|
|
() => createEventMeta({
|
|
|
|
category: 'Challenge',
|
|
|
|
action: 'closed',
|
|
|
|
label: 'help chat closed'
|
|
|
|
})
|
|
|
|
);
|
2016-07-11 17:44:50 -07:00
|
|
|
|
2016-06-17 22:20:20 -07:00
|
|
|
export const toggleNightMode = createAction(types.toggleNightMode);
|