This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const textHandler = mapPropsStream(props$ => { | |
| const { stream: onInput$, handler: handleChange } = createEventHandler() | |
| const text$ = onInput$.pipe(map(e => e.target.value), startWith('')) | |
| return props$.pipe( | |
| switchMap(props => text$.pipe(map(text => ({ ...props, text, handleChange })))) | |
| ) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const textHandler = mapPropsStream(props$ => { | |
| const { stream: onInput$, handler: handleChange } = createEventHandler() | |
| const text$ = onInput$.pipe(map(e => e.target.value), startWith('')) | |
| return props$.pipe( | |
| switchMap(props => text$.pipe(map(text => ({ ...props, text, handleChange })))) | |
| ) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const modalHandler = mapPropsStream(props$ => { | |
| const { stream: isOpen$, handler: toggleModal } = createEventHandler() | |
| return props$.pipe( | |
| switchMap(props => | |
| isOpen$.pipe( | |
| startWith(false), | |
| scan(bool => !bool), | |
| map(isOpen => ({ ...props, isOpen, toggleModal })) | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const LikesList = ({ | |
| user: { likes, user }, | |
| updateFunctions: { addLike, deleteLike } | |
| }) => ( | |
| <Fragment> | |
| <ListHeader> | |
| <h3 style={{ margin: 0 }}>Likes</h3> | |
| <i className="material-icons" style={{ cursor: 'pointer' }} > | |
| add | |
| </i> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const StreamIndex = compose( | |
| withState('userList', 'updateUserList', []), | |
| withHandlers({ | |
| setUserList: ({ updateUserList }) => users => updateUserList(state => users), | |
| addLike: ({ updateUserList }) => (user, like) => addUserLike(user, like), | |
| addDislike: ({ updateUserList }) => (user, dislike) => addUserDislike(user, dislike), | |
| deleteLike: ({ updateUserList }) => (user, like) => | |
| deleteUserLike(user, like.id).then(() => | |
| updateUserList(state => [ | |
| ...state.map(i => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| withContext( | |
| { updateFunctions: PropTypes.object, user: PropTypes.object }, | |
| ({ selectedUser, addLike, addDislike, deleteLike, deleteDislike }) => ({ | |
| user: selectedUser, | |
| updateFunctions: { addLike, addDislike, deleteLike, deleteDislike } | |
| }) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| withHandlers({ | |
| setUserList: ({ updateUserList }) => users => updateUserList(state => users), | |
| addLike: ({ updateUserList }) => (user, like) => addUserLike(user, like), | |
| addDislike: ({ updateUserList }) => (user, dislike) => addUserDislike(user, dislike), | |
| deleteLike: ({ updateUserList }) => (user, like) => | |
| deleteUserLike(user, like.id).then(() => | |
| updateUserList(state => [ | |
| ...state.map(i => { | |
| if (i.user === user) { | |
| i.likes = i.likes.filter(i => i.id !== like.id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { compose, withState, withHandlers } from 'recompose' | |
| import { withRouter } from 'react-router-dom' | |
| const StreamIndex = compose( | |
| withState('userList', 'updateUserList', []), | |
| withHandlers({ setUserList: ({ updateUserList }) => users => updateUserList(state => users) }), | |
| withRouter, | |
| load, | |
| selectUser | |
| )(IndexPage) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { PageWrapper, ListContainer, ListItem, Loader, UserContainer } from './styledComponents' | |
| const IndexPage = ({ status, userList, selectedUser, userSelect, message, match, history }) => { | |
| const userParam = get(match, 'params.user') | |
| if (selectedUser) { | |
| userParam !== selectedUser.user && history.push(`/${selectedUser.user}`) | |
| } | |
| return ( | |
| <PageWrapper> | |
| <UserContainer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Fragment } from 'react' | |
| import PropTypes from 'prop-types' | |
| import { render } from 'react-dom' | |
| import { from, to, of } from 'rxjs' | |
| import { switchMap, map, startWith, tap, catchError } from 'rxjs/operators' | |
| import { | |
| compose, | |
| mapPropsStream, | |
| createEventHandler, | |
| withState, |