diff options
author | Vitaly Takmazov | 2018-07-18 10:46:00 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:53 +0300 |
commit | 85b33a0119e5a427eec18a25584f7140722dd2d9 (patch) | |
tree | ceacbfdd534104053ab60775955adba2a2207818 /vnext/src | |
parent | 4f65458afddd80ff0f4a36af0f9a228cd2805072 (diff) |
pass search to Blog and Discover components
Diffstat (limited to 'vnext/src')
-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 = { |