diff --git a/functions/handlers/topic.js b/functions/handlers/topic.js index 498cd18..4d3dc3d 100644 --- a/functions/handlers/topic.js +++ b/functions/handlers/topic.js @@ -34,7 +34,6 @@ exports.getAllTopics = (req, res) => { }; exports.deleteTopic = (req, res) => { - // TODO: handle add and delete by topic id const topic = db.doc(`/topics/${req.params.topicId}`); topic.get().then((doc) => { if (!doc.exists) { diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index bec4ac6..2335b20 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -36,6 +36,7 @@ const theme = createMuiTheme(themeObject); const token = localStorage.FBIdToken; if (token) { + try { const decodedToken = jwtDecode(token); if (decodedToken.exp * 1000 < Date.now()) { diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 435c92c..27a0c94 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -6,66 +6,63 @@ import axios from 'axios'; import { makeStyles, styled } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; -import CardMedia from '@material-ui/core/CardMedia'; -import CardContent from '@material-ui/core/CardContent'; import Chip from '@material-ui/core/Chip'; -import Paper from '@material-ui/core/Paper'; import Typography from "@material-ui/core/Typography"; import AddCircle from '@material-ui/icons/AddCircle'; +import TextField from '@material-ui/core/TextField'; // component -import Profile from '../components/profile/Profile'; import Userline from '../Userline'; import noImage from '../images/no-img.png'; - -const PostCard = styled(Card)({ - background: 'linear-gradient(45deg, #1da1f2 90%)', - border: 3, - borderRadius: 3, - height:325, - width: 345, - padding: '0 30px', -}); - const MyChip = styled(Chip)({ margin: 2, color: 'primary' }); - -const styles = (theme) => ({ - ...theme -}); - -const handleDelete = () => { - alert("Delete this topic!"); -} - -const handleAddCircle = () => { - alert("Add topic"); -} - class user extends Component { state = { profile: null, - topics: null + imageUrl: null, + topics: null, + newTopic: null }; + + handleDelete = (topic) => { + alert(`Delete topic: ${topic}!`); + } + + handleAddCircle = () => { + axios.post('/putTopic', { + topic: this.state.newTopic + }) + .then(function () { + location.reload(); + }) + .catch(function (err) { + console.log(err); + }); + } + + handleChange(event) { + this.setState({ + newTopic: event.target.value + }) + } componentDidMount() { axios .get("/user") .then(res => { - console.log(res.data.credentials.handle); this.setState({ - profile: res.data.credentials.handle + profile: res.data.credentials.handle, + imageUrl: res.data.credentials.imageUrl }); }) .catch(err => console.log(err)); axios .get("/getAllTopics") .then(res => { - console.log(res.data[1]); this.setState({ topics: res.data }) @@ -83,22 +80,40 @@ class user extends Component { let topicsMarkup = this.state.topics ? ( this.state.topics.map(topic => ) + key={{topic}.topic.topicId} + onDelete={ (topic) => this.handleDelete(topic)}/>) ) : (

loading topics...

); + let imageMarkup = this.state.imageUrl ? ( + + ) : (); + return (

Post

- + {imageMarkup} {profileMarkup} {topicsMarkup} - } + this.handleChange(event)} + /> +
@@ -106,12 +121,4 @@ class user extends Component { } } -Userline.PropTypes = { - handle: PropTypes.object.isRequired -}; - -const mapStateToProps = (state) => ({ - user: state.user -}); - export default user;