mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +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) => {
|
exports.getAllTopics = (req, res) => {
|
||||||
admin
|
admin
|
||||||
.firestore()
|
.firestore()
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -144,7 +144,8 @@ const {
|
|||||||
putTopic,
|
putTopic,
|
||||||
getAllTopics,
|
getAllTopics,
|
||||||
deleteTopic,
|
deleteTopic,
|
||||||
getUserTopics
|
getUserTopics,
|
||||||
|
putNewTopic
|
||||||
} = require("./handlers/topic");
|
} = require("./handlers/topic");
|
||||||
|
|
||||||
// add topic to database
|
// add topic to database
|
||||||
@ -159,4 +160,6 @@ app.post("/deleteTopic", fbAuth, deleteTopic);
|
|||||||
// get topic for this user
|
// get topic for this user
|
||||||
app.post("/getUserTopics", fbAuth, getUserTopics);
|
app.post("/getUserTopics", fbAuth, getUserTopics);
|
||||||
|
|
||||||
|
app.post("/putNewTopic", fbAuth, putNewTopic);
|
||||||
|
|
||||||
exports.api = functions.https.onRequest(app);
|
exports.api = functions.https.onRequest(app);
|
||||||
|
|||||||
@ -168,7 +168,7 @@ class Home extends Component {
|
|||||||
<p></p>
|
<p></p>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<p>Loading</p>
|
<p></p>
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@ -77,7 +77,8 @@ class user extends Component {
|
|||||||
user: null,
|
user: null,
|
||||||
following: null,
|
following: null,
|
||||||
posts: 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() {
|
componentDidMount() {
|
||||||
axios
|
axios
|
||||||
.post("/getUserDetails", {
|
.post("/getUserDetails", {
|
||||||
@ -129,11 +148,19 @@ class user extends Component {
|
|||||||
axios
|
axios
|
||||||
.get("/user")
|
.get("/user")
|
||||||
.then(res => {
|
.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({
|
this.setState({
|
||||||
following: res.data.credentials.following.includes(
|
following: fol,
|
||||||
this.state.profile
|
myTopics: list
|
||||||
),
|
|
||||||
myTopics: res.data.credentials.followedTopics
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
@ -154,7 +181,7 @@ class user extends Component {
|
|||||||
.get("/getAlert")
|
.get("/getAlert")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
let temp = this.state.posts;
|
let temp = this.state.posts;
|
||||||
console.log(res.data);
|
// console.log(res.data);
|
||||||
res.data.forEach(element => {
|
res.data.forEach(element => {
|
||||||
element ? temp.push(element) : console.err;
|
element ? temp.push(element) : console.err;
|
||||||
});
|
});
|
||||||
@ -194,8 +221,8 @@ class user extends Component {
|
|||||||
<p>loading username...</p>
|
<p>loading username...</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(this.state.topics);
|
// console.log(this.state.topics);
|
||||||
console.log(this.state.myTopics);
|
// console.log(this.state.myTopics);
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(
|
this.state.topics.map(
|
||||||
topic =>
|
topic =>
|
||||||
@ -212,6 +239,8 @@ class user extends Component {
|
|||||||
label={topic}
|
label={topic}
|
||||||
key={{ topic }.topic.id}
|
key={{ topic }.topic.id}
|
||||||
color="secondary"
|
color="secondary"
|
||||||
|
clickable
|
||||||
|
onClick={key => this.handleAdd(topic)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
@ -228,7 +257,7 @@ class user extends Component {
|
|||||||
) : (
|
) : (
|
||||||
<img src={noImage} height="150" width="150" />
|
<img src={noImage} height="150" width="150" />
|
||||||
);
|
);
|
||||||
console.log(this.state.posts);
|
//(this.state.posts);
|
||||||
let postMarkup = this.state.posts ? (
|
let postMarkup = this.state.posts ? (
|
||||||
this.state.posts.map(post => (
|
this.state.posts.map(post => (
|
||||||
<Card className={classes.card}>
|
<Card className={classes.card}>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user