aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/Discover.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-16 21:37:35 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:52 +0300
commit9177719daf40ca63b73f78602283902b3c615bae (patch)
tree67d5abf09069c62b77f1d27c2f5500dcdd348a05 /vnext/src/components/Discover.js
parent445f9d694df84bf6a4aedbeae47f8df7baa55c29 (diff)
real login
Diffstat (limited to 'vnext/src/components/Discover.js')
-rw-r--r--vnext/src/components/Discover.js37
1 files changed, 22 insertions, 15 deletions
diff --git a/vnext/src/components/Discover.js b/vnext/src/components/Discover.js
index fc1ab707..a0e51160 100644
--- a/vnext/src/components/Discover.js
+++ b/vnext/src/components/Discover.js
@@ -1,6 +1,7 @@
import 'whatwg-fetch';
import React from 'react';
import PropTypes from 'prop-types';
+import * as qs from 'query-string';
import Message from './Message';
import Spinner from './Spinner';
@@ -9,9 +10,7 @@ export default class Discover extends React.Component {
constructor(props) {
super(props);
this.state = {
- msgs: [],
- loading: false,
- search: this.props.location.search
+ msgs: []
};
this.loadMessages = this.loadMessages.bind(this);
}
@@ -19,27 +18,35 @@ export default class Discover extends React.Component {
this.loadMessages();
}
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)
}
}
loadMessages(filter = '') {
- this.setState({ msgs: []})
- const url = 'https://api.juick.com/messages' + 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;
+ }
+ if (Object.keys(params).length > 0) {
+ url = `${url}?${qs.stringify(params)}`;
+ }
fetch(url)
- .then(response => {
- return response.json()
- })
- .then(data =>
- this.setState({ msgs: data })
- ).catch(ex => {
- console.log(ex);
- });
+ .then(response => {
+ return response.json()
+ })
+ .then(data =>
+ this.setState({ msgs: data })
+ ).catch(ex => {
+ console.log(ex);
+ });
}
render() {
var nodes = this.state.msgs.map(msg => {
- return (<Message key={msg.mid} data={msg}/>);
+ return (<Message key={msg.mid} data={msg} />);
});
return this.state.msgs.length > 0 ? (
<div className="msgs" id="content">{nodes}</div>