added user post tuple

This commit is contained in:
Leon Liang
2019-12-05 17:22:55 -05:00
parent de72bd9223
commit 30df98343e
5 changed files with 470 additions and 345 deletions

View File

@@ -168,7 +168,7 @@ class Home extends Component {
<p></p>
)
) : (
<p>Loading</p>
<p></p>
)
)
) : (

View File

@@ -77,7 +77,8 @@ class user extends Component {
user: null,
following: null,
posts: null,
myTopics: null
myTopics: null,
followingList: null
};
}
@@ -113,6 +114,24 @@ class user extends Component {
}
};
handleAdd = newTopic => {
axios
.post("/putNewTopic", {
handle: this.state.profile,
topic: newTopic
})
.then(() => {
let temp = this.state.myTopics;
temp.push(newTopic);
this.setState({
myTopics: temp
});
})
.catch(err => {
console.err(err);
});
};
componentDidMount() {
axios
.post("/getUserDetails", {
@@ -129,11 +148,19 @@ class user extends Component {
axios
.get("/user")
.then(res => {
// console.log(res.data.credentials.following);
let list = [];
let fol = false;
res.data.credentials.following.forEach(follow => {
console.log(follow);
if (this.state.profile === follow.handle) {
fol = true;
list = follow.topics;
}
});
this.setState({
following: res.data.credentials.following.includes(
this.state.profile
),
myTopics: res.data.credentials.followedTopics
following: fol,
myTopics: list
});
})
.catch(err => console.log(err));
@@ -154,7 +181,7 @@ class user extends Component {
.get("/getAlert")
.then(res => {
let temp = this.state.posts;
console.log(res.data);
// console.log(res.data);
res.data.forEach(element => {
element ? temp.push(element) : console.err;
});
@@ -194,8 +221,8 @@ class user extends Component {
<p>loading username...</p>
);
console.log(this.state.topics);
console.log(this.state.myTopics);
// console.log(this.state.topics);
// console.log(this.state.myTopics);
let topicsMarkup = this.state.topics ? (
this.state.topics.map(
topic =>
@@ -212,6 +239,8 @@ class user extends Component {
label={topic}
key={{ topic }.topic.id}
color="secondary"
clickable
onClick={key => this.handleAdd(topic)}
/>
)
) : (
@@ -228,7 +257,7 @@ class user extends Component {
) : (
<img src={noImage} height="150" width="150" />
);
console.log(this.state.posts);
//(this.state.posts);
let postMarkup = this.state.posts ? (
this.state.posts.map(post => (
<Card className={classes.card}>