From 85b33a0119e5a427eec18a25584f7140722dd2d9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 18 Jul 2018 10:46:00 +0300 Subject: pass search to Blog and Discover components --- vnext/src/components/Feeds.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'vnext/src') 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 (); } @@ -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 (); } @@ -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 = { -- cgit v1.2.3