mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 18:28:47 +00:00
added UI for follow and unfollow other user
This commit is contained in:
parent
42c53fdbc4
commit
2de3da928a
@ -450,6 +450,7 @@ exports.addSubscription = (req, res) => {
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
return res.status(500).json({ err });
|
||||||
});
|
});
|
||||||
|
return res.status(500).json({ error: "shouldn't execute" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -489,5 +490,6 @@ exports.removeSub = (req, res) => {
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
return res.status(500).json({ err });
|
||||||
});
|
});
|
||||||
|
return res.status(500).json({ error: "shouldn't execute" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -65,7 +65,7 @@ app.get("/getSubs", fbAuth, getSubs);
|
|||||||
app.post("/addSubscription", fbAuth, addSubscription);
|
app.post("/addSubscription", fbAuth, addSubscription);
|
||||||
|
|
||||||
// remove one subscription
|
// remove one subscription
|
||||||
app.delete("/removeSub", fbAuth, removeSub);
|
app.post("/removeSub", fbAuth, removeSub);
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
|||||||
import "../App.css";
|
import "../App.css";
|
||||||
import noImage from "../images/no-img.png";
|
import noImage from "../images/no-img.png";
|
||||||
import Writing_Microblogs from "../Writing_Microblogs";
|
import Writing_Microblogs from "../Writing_Microblogs";
|
||||||
|
|
||||||
const MyChip = styled(Chip)({
|
const MyChip = styled(Chip)({
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: "primary"
|
color: "primary"
|
||||||
@ -34,17 +35,48 @@ class user extends Component {
|
|||||||
profile: window.location.pathname.split("/").pop(),
|
profile: window.location.pathname.split("/").pop(),
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
topics: null,
|
topics: null,
|
||||||
following: null // boolean value
|
user: null,
|
||||||
|
following: null
|
||||||
|
};
|
||||||
|
|
||||||
|
handleSub = () => {
|
||||||
|
if (this.state.following === true) {
|
||||||
|
axios
|
||||||
|
.post("/removeSub", {
|
||||||
|
unfollow: this.state.profile
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
console.log("removed sub");
|
||||||
|
this.setState({
|
||||||
|
following: false
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
axios
|
||||||
|
.post("/addSubscription", {
|
||||||
|
following: this.state.profile
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
console.log("adding sub");
|
||||||
|
this.setState({
|
||||||
|
following: true
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
console.log(this.state.profile);
|
|
||||||
axios
|
axios
|
||||||
.post("/getUserDetails", {
|
.post("/getUserDetails", {
|
||||||
handle: this.state.profile
|
handle: this.state.profile
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res.data.userData);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
imageUrl: res.data.userData.imageUrl,
|
imageUrl: res.data.userData.imageUrl,
|
||||||
topics: res.data.userData.followedTopics
|
topics: res.data.userData.followedTopics
|
||||||
@ -53,20 +85,16 @@ class user extends Component {
|
|||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get("/getallPostsforUser")
|
.get("/user")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res.data);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
posts: res.data
|
following: res.data.credentials.following.includes(this.state.profile)
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let authenticated = this.props.user.authenticated;
|
|
||||||
let classes = this.props;
|
|
||||||
|
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="h5">
|
<Typography variant="h5">
|
||||||
@ -93,35 +121,27 @@ class user extends Component {
|
|||||||
<img src={noImage} height="150" width="150" />
|
<img src={noImage} height="150" width="150" />
|
||||||
);
|
);
|
||||||
|
|
||||||
let postMarkup = this.state.posts ? (
|
let followMarkup = this.state.following ? (
|
||||||
this.state.posts.map(post => (
|
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
||||||
<Card>
|
unfollow
|
||||||
<CardContent>
|
</Button>
|
||||||
<Typography>
|
|
||||||
{this.state.imageUrl ? (
|
|
||||||
<img src={this.state.imageUrl} height="250" width="250" />
|
|
||||||
) : (
|
) : (
|
||||||
<img src={noImage} height="50" width="50" />
|
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
||||||
)}
|
follow
|
||||||
</Typography>
|
</Button>
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<p>My Posts</p>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log(this.state.following);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={24}>
|
<Grid container spacing={24}>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
{imageMarkup}
|
{imageMarkup}
|
||||||
{profileMarkup}
|
{profileMarkup}
|
||||||
|
{followMarkup}
|
||||||
{topicsMarkup}
|
{topicsMarkup}
|
||||||
<br />
|
<br />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={4} xs={8}>
|
|
||||||
{postMarkup}
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user