Files
freeCodeCamp/common/app/redux/fetch-user-epic.js
Stuart Taylor 3131c55782 feat(Profile): Reactify profile page (#16743)
* feat(Profile): Reactify profile page

* chore(tidyup): Remove console.log

* fix(timeline): Remove legacy challenges from Timeline render

* fix(style): Remove underline on a:hover
2018-02-19 14:32:14 -06:00

43 lines
1.1 KiB
JavaScript

import { Observable } from 'rx';
import { ofType, combineEpics } from 'redux-epic';
import { getJSON$ } from '../../utils/ajax-stream';
import {
types,
fetchUserComplete,
fetchOtherUserComplete,
createErrorObservable,
showSignIn
} from './';
import { userFound } from '../routes/Profile/redux';
function getUserEpic(actions, _, { services }) {
return actions::ofType('' + types.fetchUser)
.flatMap(() => {
return services.readService$({ service: 'user' })
.filter(({ entities, result }) => entities && !!result)
.map(fetchUserComplete)
.defaultIfEmpty(showSignIn())
.catch(createErrorObservable);
});
}
function getOtherUserEpic(actions$) {
return actions$::ofType(types.fetchOtherUser.start)
.distinctUntilChanged()
.flatMap(({ payload: otherUser }) => {
return getJSON$(`/api/users/get-public-profile?username=${otherUser}`)
.flatMap(response => Observable.of(
fetchOtherUserComplete(response),
userFound(!!response.result)
))
.catch(createErrorObservable);
});
}
export default combineEpics(
getUserEpic,
getOtherUserEpic
);