diff --git a/functions/handlers/topic.js b/functions/handlers/topic.js index a55f748..bb5b9f1 100644 --- a/functions/handlers/topic.js +++ b/functions/handlers/topic.js @@ -58,3 +58,16 @@ exports.deleteTopic = (req, res) => { return res.status(500).json({ error: "Failed to delete topic." }); }); }; + +exports.getUserTopics = (req, res) => { + let data = []; + db.doc(`/users/${req.body.handle}`) + .get() + .then(doc => { + data = doc.data().followedTopics; + return res.status(200).json({ data }); + }) + .catch(err => { + return res.status(500).json({ err }); + }); +}; diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 2fdcd51..84463c2 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -450,6 +450,7 @@ exports.addSubscription = (req, res) => { .catch(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 => { return res.status(500).json({ err }); }); + return res.status(500).json({ error: "shouldn't execute" }); }); }; diff --git a/functions/index.js b/functions/index.js index 86231d0..eb87142 100644 --- a/functions/index.js +++ b/functions/index.js @@ -37,7 +37,7 @@ app.post("/login", login); //Deletes user account app.delete("/delete", fbAuth, deleteUser); -app.get("/getUser", fbAuth, getUserDetails); +app.post("/getUserDetails", fbAuth, getUserDetails); // Returns all profile data of the currently logged in user app.get("/getProfileInfo", fbAuth, getProfileInfo); @@ -65,7 +65,7 @@ app.get("/getSubs", fbAuth, getSubs); app.post("/addSubscription", fbAuth, addSubscription); // remove one subscription -app.delete("/removeSub", fbAuth, removeSub); +app.post("/removeSub", fbAuth, removeSub); /*------------------------------------------------------------------* * handlers/post.js * @@ -82,7 +82,12 @@ app.post("/putPost", fbAuth, putPost); /*------------------------------------------------------------------* * handlers/topic.js * *------------------------------------------------------------------*/ -const { putTopic, getAllTopics, deleteTopic } = require("./handlers/topic"); +const { + putTopic, + getAllTopics, + deleteTopic, + getUserTopics +} = require("./handlers/topic"); // add topic to database app.post("/putTopic", fbAuth, putTopic); @@ -93,4 +98,7 @@ app.get("/getAllTopics", fbAuth, getAllTopics); // delete a specific topic app.delete("/deleteTopic/:topicId", fbAuth, deleteTopic); +// get topic for this user +app.post("/getUserTopics", fbAuth, getUserTopics); + exports.api = functions.https.onRequest(app); diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index aeec8ee..9e29d2e 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -19,8 +19,6 @@ import { logoutUser, getUserData } from "./redux/actions/userActions"; // Components import AuthRoute from "./util/AuthRoute"; -// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api'; - // Pages import home from "./pages/Home"; import signup from "./pages/Signup"; @@ -33,6 +31,7 @@ import editProfile from "./pages/editProfile"; import userLine from "./Userline.js"; import verify from "./pages/verify"; import Search from "./pages/Search.js"; +import otherUser from "./pages/otherUser"; const theme = createMuiTheme(themeObject); @@ -65,11 +64,10 @@ class App extends Component {
loading username...
+ ); + let topicsMarkup = this.state.topics ? ( + this.state.topics.map( + topic =>loading topics...
+ ); + + let imageMarkup = this.state.imageUrl ? ( +