diff options
Diffstat (limited to 'vnext/src/components/Feeds.js')
-rw-r--r-- | vnext/src/components/Feeds.js | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/vnext/src/components/Feeds.js b/vnext/src/components/Feeds.js index a504bbb8..5d084f3c 100644 --- a/vnext/src/components/Feeds.js +++ b/vnext/src/components/Feeds.js @@ -8,13 +8,15 @@ import moment from 'moment'; import Message from './Message'; import Spinner from './Spinner'; -import { getMessages } from '../api'; +import { getMessages } from '../api'; import { UserType } from './Types'; export function Discover(props) { + let search = qs.parse(props.location.search); const query = { baseUrl: '/messages', - pageParam: 'before_mid' + search: search, + pageParam: props.search ? 'page' : 'before_mid' }; return (<Feed authRequired={false} query={query} {...props} />); } @@ -29,12 +31,12 @@ export function Discussions(props) { export function Blog(props) { const { user } = props.match.params; + let search = qs.parse(props.location.search); + search.uname = user; const query = { baseUrl: '/messages', - search: { - uname: user - }, - pageParam: 'before_mid' + search: search, + pageParam: props.search ? 'page' : 'before_mid' }; return (<Feed authRequired={false} query={query} {...props} />); } @@ -97,16 +99,20 @@ class Feed extends React.Component { const { data } = response; const { pageParam } = this.props.query; const lastMessage = data.slice(-1)[0] || {}; - const pageValue = pageParam === 'before_mid' ? lastMessage.mid : moment.utc(lastMessage.updated).valueOf(); - let newFilter = Object.assign({}, filterParams); - newFilter[pageParam] = pageValue; - const nextpage = `?${qs.stringify(newFilter)}`; + const nextpage = this.getPageParam(pageParam, lastMessage, filterParams); this.setState({ msgs: data, loading: false, nextpage: nextpage }); }).catch(ex => { this.setState({ error: true }); }); } + getPageParam = (pageParam, lastMessage, filterParams) => { + const pageValue = pageParam === 'before_mid' ? lastMessage.mid : pageParam === 'page' ? (Number(filterParams.page) || 0) + 1 : moment.utc(lastMessage.updated).valueOf(); + let newFilter = Object.assign({}, filterParams); + newFilter[pageParam] = pageValue; + return `?${qs.stringify(newFilter)}`; + } + render() { const { tag } = qs.parse(this.props.location.search || {}); const nodes = ( @@ -139,8 +145,15 @@ class Feed extends React.Component { } } +Discover.propTypes = { + location: ReactRouterPropTypes.location.isRequired, + search: PropTypes.string +}; + Blog.propTypes = { - match: ReactRouterPropTypes.match.isRequired + match: ReactRouterPropTypes.match.isRequired, + location: ReactRouterPropTypes.location.isRequired, + search: PropTypes.string }; Tag.propTypes = { |