This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CALL_API } from 'middleware/api' | ||
import { LATEST } from 'reducers/latest' | ||
|
||
export const LATEST_REQUEST = 'LATEST_REQUEST' | ||
export const LATEST_SUCCESS = 'LATEST_SUCCESS' | ||
export const LATEST_FAILURE = 'LATEST_FAILURE' | ||
|
||
const fetchLatest = (page = 1) => { | ||
return { | ||
[CALL_API]: { | ||
types: [LATEST_REQUEST, LATEST_SUCCESS, LATEST_FAILURE], | ||
endpoint: '/latest?page=' + page, | ||
key: LATEST | ||
} | ||
} | ||
} | ||
|
||
export function loadLatest (page = 1) { | ||
return (dispatch, getState) => { | ||
return dispatch(fetchLatest(page = page)) | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { addNamedExtension } from 'config/extensions' | ||
import paginate from 'reducers/paginate' | ||
import { LATEST_SUCCESS, LATEST_FAILURE, LATEST_REQUEST } from 'actions/latest' | ||
|
||
export const LATEST = 'latest' | ||
|
||
addNamedExtension('reducers', LATEST, paginate({ | ||
mapActionToKey: x => LATEST, | ||
types: [LATEST_REQUEST, LATEST_SUCCESS, LATEST_FAILURE] | ||
})) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable react/no-multi-comp */ | ||
import React, { Component } from 'react' | ||
import { connect } from 'react-redux' | ||
import { getStoreEntity } from 'utils' | ||
import { LATEST } from 'reducers/latest' | ||
import { loadLatest } from 'actions/latest' | ||
import InfiniteList from 'components/InfiniteList' | ||
|
||
// This should be a stateless component but if it's to be | ||
// consumed by the InfiniteList later, we'll need to add | ||
// a ref and you can't do that on stateless components. | ||
class Link extends Component { | ||
render () { | ||
const props = this.props | ||
return ( | ||
<li key={props.key} style={{height: 20}}> | ||
<a target='_blank' href={props.url}>{props.title}</a> | ||
</li> | ||
) | ||
} | ||
} | ||
|
||
const LinksList = ({ | ||
meta, | ||
links, | ||
isFetching, | ||
loadMore | ||
}) => ( | ||
<InfiniteList | ||
meta={meta} | ||
loader={loadMore} | ||
minimalItemHeight={24} | ||
isFetching={isFetching} | ||
> | ||
{links.map(l => | ||
<Link key={l.id} {...l} /> | ||
)} | ||
</InfiniteList> | ||
) | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
meta: state[LATEST].meta, | ||
links: state[LATEST].data.map((item) => { | ||
return getStoreEntity(state, item) | ||
}), | ||
isFetching: state[LATEST].isFetching | ||
} | ||
} | ||
|
||
const mapDispatchToProps = (dispatch, props) => { | ||
return { | ||
loadMore: (page) => { | ||
console.log('loadMore', {page: page}) | ||
dispatch(loadLatest(page)) | ||
} | ||
} | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(LinksList) | ||
/* eslint-enable react/no-multi-comp */ |
This file contains 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
This file contains 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
This file contains 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
This file contains 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