/* eslint-disable */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import axios from 'axios';
// Material UI and React Router
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from "@material-ui/core/Typography";
// component
import '../App.css';
import logo from '../images/twistter-logo.png';
import noImage from '../images/no-img.png';
import Writing_Microblogs from '../Writing_Microblogs';
import ReactModal from 'react-modal';
class Home extends Component {
state = {
};
componentDidMount() {
axios
.get("/getallPosts")
.then(res => {
console.log(res.data);
this.setState({
posts: res.data
})
this.setState({posts: (this.state.posts).sort((a,b) =>
-a.createdAt.localeCompare(b.createdAt))
})
})
.catch(err => console.log(err));
}
render() {
let authenticated = this.props.user.authenticated;
let postMarkup = this.state.posts ? (
this.state.posts.map(post =>
{
this.state.imageUrl ? (
) :
(
)
}
{post.userHandle}
{post.createdAt.substring(0,10) +
" " + post.createdAt.substring(11,19)}
{post.microBlogTitle}
{post.body}
Topics: {post.microBlogTopics.join("," + " ")}
Likes {post.likeCount}
)
) : (
My Posts
);
return (
authenticated ?
{postMarkup}
:
Welcome to Twistter!
See the most interesting topics people are following right now.
Join today or sign in if you already have an account.
);
}
}
const mapStateToProps = (state) => ({
user: state.user
})
Home.propTypes = {
user: PropTypes.object.isRequired
}
class Quote extends Component {
constructor(props) {
super(props);
this.state = {
characterCount: 250,
showModal: false,
value: ""
}
this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
this.handleOpenModal = this.handleOpenModal.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmitWithoutPost(event) {
const headers = {
headers: { "Content-Type": "application/json" }
};
axios.post(`/quoteWithoutPost/${this.props.microblog}`, headers)
.then((res) => {
console.log(res.data);
})
.catch(err => {
console.error(err);
});
event.preventDefault();
}
handleOpenModal() {
this.setState({ showModal: true });
}
handleCloseModal() {
this.setState({ showModal: false });
}
handleChangeforPost(event) {
this.setState({ value: event.target.value });
}
handleChangeforCharacterCount(event) {
const charCount = event.target.value.length;
const charRemaining = 250 - charCount;
this.setState({ characterCount: charRemaining });
}
handleSubmit(event) {
const quotedPost = {
quotePost: this.state.value,
};
const headers = {
headers: { "Content-Type": "application/json" }
};
axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
.then((res) => {
console.log(res.data);
})
.catch(err => {
console.error(err);
});
event.preventDefault();
this.setState({ showModal: false, characterCount: 250, value: "" });
}
render() {
return (
)
}
}
class Like extends Component {
constructor(props) {
super(props)
this.state = {
like: false
}
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
this.setState({
like: !this.state.like
});
if(this.state.like == false)
{
axios.get(`/like/${this.props.microBlog}`)
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.log(err);
})
}
else
{
axios.get(`/unlike/${this.props.microBlog}`)
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.log(err);
})
}
}
render() {
const label = this.state.like ? 'Unlike' : 'Like'
return(
)
}
}
export default connect(mapStateToProps)(Home);