import React from 'react';
import PropTypes from 'prop-types';
import * as qs from 'query-string';
import Message from './Message';
import Spinner from './Spinner';
export function Discover(props) {
return ()
}
export function Discussions(props) {
return ()
}
export function Blog(props) {
const { user } = props.match.params;
return ()
}
class Feed extends React.Component {
constructor(props) {
super(props);
this.state = {
msgs: []
};
this.loadMessages = this.loadMessages.bind(this);
}
componentDidMount() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
this.loadMessages(this.props.visitor.hash);
}
componentWillReceiveProps(nextProps) {
if (this.props.location.search != nextProps.location.search
|| this.props.visitor != nextProps.visitor) {
this.loadMessages(nextProps.visitor.hash, nextProps.location.search)
}
}
loadMessages(hash = '', filter = '') {
this.setState({ msgs: [] })
let params = Object.assign({}, qs.parse(filter) || {}, this.props.query.search || {});
let url = this.props.query.baseUrl;
if (hash) {
params.hash = hash;
}
if (Object.keys(params).length > 0) {
url = `${url}?${qs.stringify(params)}`;
}
if (!params.hash && this.props.authRequired) {
this.props.history.push('/')
}
fetch(url)
.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 this.state.msgs.length > 0 ? (
{nodes}
) :
;
}
}
Feed.propTypes = {
msgs: PropTypes.array,
query: PropTypes.shape({
baseUrl: PropTypes.string.isRequired,
search: PropTypes.array
})
};