diff options
author | 2018-06-16 22:13:40 +0300 | |
---|---|---|
committer | 2023-01-13 10:37:52 +0300 | |
commit | 67afd8e9378c65bff11a2aac21d95577fa916dc5 (patch) | |
tree | 299ae99f74df6285687d978c74875fc583af98e3 /vnext/src/components | |
parent | 9177719daf40ca63b73f78602283902b3c615bae (diff) |
Discussions
Diffstat (limited to 'vnext/src/components')
-rw-r--r-- | vnext/src/components/Feeds.js (renamed from vnext/src/components/Discover.js) | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/vnext/src/components/Discover.js b/vnext/src/components/Feeds.js index a0e51160..3c183f7f 100644 --- a/vnext/src/components/Discover.js +++ b/vnext/src/components/Feeds.js @@ -6,7 +6,15 @@ import * as qs from 'query-string'; import Message from './Message'; import Spinner from './Spinner'; -export default class Discover extends React.Component { +export function Discover(props) { + return (<Feed baseUrl="https://api.juick.com/messages" {...props} />) +} + +export function Discussions(props) { + return (<Feed authRequired="true" baseUrl="https://api.juick.com/messages/discussions" {...props} />) +} + +class Feed extends React.Component { constructor(props) { super(props); this.state = { @@ -15,24 +23,27 @@ export default class Discover extends React.Component { this.loadMessages = this.loadMessages.bind(this); } componentDidMount() { - this.loadMessages(); + this.loadMessages(this.props.visitor.hash); } componentWillReceiveProps(nextProps) { - if (this.props.location.search != nextProps.location.search + if (this.props.location.search != nextProps.location.search || this.props.visitor != nextProps.visitor) { - this.loadMessages(nextProps.location.search) + this.loadMessages(nextProps.visitor.hash, nextProps.location.search) } } - loadMessages(filter = '') { + loadMessages(hash = '', filter = '') { this.setState({ msgs: [] }) let params = qs.parse(filter) || {} - let url = 'https://api.juick.com/messages'; - if (this.props.visitor && this.props.visitor.hash) { - params.hash = this.props.visitor.hash; + let url = this.props.baseUrl; + if (hash) { + params.hash = hash; } if (Object.keys(params).length > 0) { url = `${url}?${qs.stringify(params)}`; } + if (!params.hash && this.props.authRequired) { + return + } fetch(url) .then(response => { return response.json() @@ -54,6 +65,7 @@ export default class Discover extends React.Component { } } -Discover.propTypes = { - msgs: PropTypes.array +Feed.propTypes = { + msgs: PropTypes.array, + baseUrl: PropTypes.string }; |