diff --git a/functions/handlers/topic.js b/functions/handlers/topic.js index c4d7b10..7a84488 100644 --- a/functions/handlers/topic.js +++ b/functions/handlers/topic.js @@ -1,9 +1,8 @@ -/* eslint-disable promise/always-return */ +/* eslint-disable promise/always-return */ const { admin, db } = require("../util/admin"); exports.putTopic = (req, res) => { const newTopic = { - topic: req.body.topic, - topicId: null + topic: req.body.topic }; admin @@ -12,12 +11,11 @@ exports.putTopic = (req, res) => { .add(newTopic) .then(doc => { const resTopic = newTopic; - newTopic.topicId = doc.id; return res.status(200).json(resTopic); }) .catch(err => { console.error(err); - return res.status(500).json({ error: "something is wrong" }); + return res.status(500).json({ error: "something is wrong" }); }); }; @@ -29,13 +27,16 @@ exports.getAllTopics = (req, res) => { .then(data => { let topics = []; data.forEach(function(doc) { - topics.push(doc.data()); + topics.push({ + topic: doc.data().topic, + id: doc.id + }); }); return res.status(200).json(topics); }) .catch(err => { console.error(err); - return res.status(500).json({ error: "Failed to fetch all topics." }); + return res.status(500).json({ error: "Failed to fetch all topics." }); }); }; @@ -45,16 +46,16 @@ exports.deleteTopic = (req, res) => { .get() .then(doc => { if (!doc.exists) { - return res.status(404).json({ error: "Topic not found" }); + return res.status(404).json({ error: "Topic not found" }); } else { return topic.delete(); } }) .then(() => { - res.json({ message: "Topic successfully deleted!" }); + res.json({ message: "Topic successfully deleted!" }); }) .catch(err => { console.error(err); - return res.status(500).json({ error: "Failed to delete topic." }); + return res.status(500).json({ error: "Failed to delete topic." }); }); }; diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index f4f325c..1096fa4 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -1,8 +1,8 @@ -/* eslint-disable */ +/* eslint-disable */ import React, { Component } from "react"; import PropTypes from "prop-types"; import axios from "axios"; -//import '../App.css'; +//import '../App.css'; import { makeStyles, styled } from "@material-ui/core/styles"; import Grid from "@material-ui/core/Grid"; import Card from "@material-ui/core/Card"; @@ -11,8 +11,7 @@ import Typography from "@material-ui/core/Typography"; import AddCircle from "@material-ui/icons/AddCircle"; import TextField from "@material-ui/core/TextField"; -// component -import Userline from "../Userline"; +// component import noImage from "../images/no-img.png"; const MyChip = styled(Chip)({ @@ -25,22 +24,18 @@ class user extends Component { profile: null, imageUrl: null, topics: null, - newTopic: null, - deleteTopic: null + newTopic: null }; - handleDelete = event => { - // axios - // .delete(`/deleteTopic/${topic}`) - // .then( - // function (response) { - // console.log(response); - // } - // ) - // .catch(function (err) { - // console.log(err); - // }); - console.log(event); + handleDelete = topic => { + axios + .delete(`/deleteTopic/${topic.id}`) + .then(function() { + location.reload(); + }) + .catch(function(err) { + console.log(err); + }); }; handleAddCircle = () => { @@ -84,22 +79,25 @@ class user extends Component { render() { let profileMarkup = this.state.profile ? (

- {this.state.profile} +         {this.state.profile} +       

) : ( -

loading username...

+

loading username...

); let topicsMarkup = this.state.topics ? ( - this.state.topics.map(topic => ( - - )) + this.state.topics.map( + topic => ( + this.handleDelete(topic)} + /> + ) // console.log({ topic }.topic.id) + ) ) : ( -

loading topics...

+

 loading topics...

); let imageMarkup = this.state.imageUrl ? ( @@ -110,24 +108,31 @@ class user extends Component { return ( +          -

Post

+           

Post

+         
+          - {imageMarkup} - {profileMarkup} - {topicsMarkup} +           {imageMarkup} +           {profileMarkup} +           {topicsMarkup} +            this.handleChange(event)} /> +            +          +       
); }