mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-15 18:08:46 +00:00
added user post tuple
This commit is contained in:
parent
de72bd9223
commit
30df98343e
@ -26,6 +26,41 @@ exports.putTopic = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.putNewTopic = (req, res) => {
|
||||
let new_following = [];
|
||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
||||
userRef
|
||||
.get()
|
||||
.then(doc => {
|
||||
let topics = [];
|
||||
new_following = doc.data().following;
|
||||
// new_following.push(req.body.following);
|
||||
new_following.forEach(follow => {
|
||||
if (follow.handle === req.body.handle) {
|
||||
// topics = follow.topics;
|
||||
follow.topics.push(req.body.topic);
|
||||
}
|
||||
});
|
||||
// return res.status(201).json({ new_following });
|
||||
|
||||
// add stuff
|
||||
userRef
|
||||
.set({ following: new_following }, { merge: true })
|
||||
.then(doc => {
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: `Following ${req.body.topic}` });
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
return res.status(200).json({ message: "OK" });
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
};
|
||||
|
||||
exports.getAllTopics = (req, res) => {
|
||||
admin
|
||||
.firestore()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -144,7 +144,8 @@ const {
|
||||
putTopic,
|
||||
getAllTopics,
|
||||
deleteTopic,
|
||||
getUserTopics
|
||||
getUserTopics,
|
||||
putNewTopic
|
||||
} = require("./handlers/topic");
|
||||
|
||||
// add topic to database
|
||||
@ -159,4 +160,6 @@ app.post("/deleteTopic", fbAuth, deleteTopic);
|
||||
// get topic for this user
|
||||
app.post("/getUserTopics", fbAuth, getUserTopics);
|
||||
|
||||
app.post("/putNewTopic", fbAuth, putNewTopic);
|
||||
|
||||
exports.api = functions.https.onRequest(app);
|
||||
|
||||
@ -168,7 +168,7 @@ class Home extends Component {
|
||||
<p></p>
|
||||
)
|
||||
) : (
|
||||
<p>Loading</p>
|
||||
<p></p>
|
||||
)
|
||||
)
|
||||
) : (
|
||||
|
||||
@ -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}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user