From 9177719daf40ca63b73f78602283902b3c615bae Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jun 2018 21:37:35 +0300 Subject: real login --- vnext/src/components/Discover.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'vnext/src/components/Discover.js') 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 (); + return (); }); return this.state.msgs.length > 0 ? (
{nodes}
-- cgit v1.2.3