mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-09 20:06:46 +00:00
adds firebase functions; update ProfileUI;
This commit is contained in:
parent
29087ca71f
commit
99a7226d40
9 changed files with 3075 additions and 25 deletions
8
functions/index.js
Normal file
8
functions/index.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
const functions = require('firebase-functions');
|
||||
|
||||
// // Create and Deploy Your First Cloud Functions
|
||||
// // https://firebase.google.com/docs/functions/write-firebase-functions
|
||||
//
|
||||
// exports.helloWorld = functions.https.onRequest((request, response) => {
|
||||
// response.send("Hello from Firebase!");
|
||||
// });
|
||||
3007
functions/package-lock.json
generated
Normal file
3007
functions/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
25
functions/package.json
Normal file
25
functions/package.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "functions",
|
||||
"description": "Cloud Functions for Firebase",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"serve": "firebase emulators:start --only functions",
|
||||
"shell": "firebase functions:shell",
|
||||
"start": "npm run shell",
|
||||
"deploy": "firebase deploy --only functions",
|
||||
"logs": "firebase functions:log"
|
||||
},
|
||||
"engines": {
|
||||
"node": "8"
|
||||
},
|
||||
"dependencies": {
|
||||
"firebase-admin": "^8.10.0",
|
||||
"firebase-functions": "^3.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.12.0",
|
||||
"eslint-plugin-promise": "^4.0.1",
|
||||
"firebase-functions-test": "^0.2.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.4.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"firebase": "^7.13.2",
|
||||
"react": "^16.12.0",
|
||||
"react-dom": "^16.12.0",
|
||||
|
|
@ -35,4 +34,4 @@
|
|||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,9 +27,7 @@ const MainRouter = ({
|
|||
<HomeController buttonUrl={buttonUrl} />
|
||||
</Route>
|
||||
|
||||
<PrivateRoute exact path="/profile">
|
||||
<ProfileController />
|
||||
</PrivateRoute>
|
||||
<PrivateRoute exact path="/profile" component={ProfileController} />
|
||||
|
||||
<Route exact path={buttonUrl}>
|
||||
<MealController
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export const MealController = ({ meal, getMeal, getRandomMeal }) => {
|
|||
}
|
||||
// };
|
||||
// add2Fav(user, idMeal, isFav).then((data) => console.log(data));
|
||||
}, [user, idMeal, isFav]);
|
||||
}, [user, idMeal, isFav, fb, isAuthenticated]);
|
||||
|
||||
const item = {
|
||||
mealName: strMeal,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ export const ProfileController = () => {
|
|||
const db = useFirebase();
|
||||
|
||||
useEffect(() => {
|
||||
db.get(user.email).then((res) => setData(res));
|
||||
db.getByEmail(user.email).then((res) => setData(res));
|
||||
// db.getFavsByEmail(user.email).then((res) => setData(res));
|
||||
}, [db, user.email]);
|
||||
|
||||
return loading || !user ? ( // is catched by PrivateRoute
|
||||
|
|
|
|||
|
|
@ -3,20 +3,21 @@ import React from "react";
|
|||
export const ProfilePage = ({ user, data }) => {
|
||||
return (
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="row valign-wrapper">
|
||||
<img
|
||||
className="circle responsive-img"
|
||||
className="left circle responsive-img"
|
||||
src={user.picture}
|
||||
alt="Avatar"
|
||||
width="20%"
|
||||
width="15%"
|
||||
/>
|
||||
<h2>{user.name}</h2>
|
||||
<p>
|
||||
<b>Email: </b>
|
||||
{user.email}
|
||||
{JSON.stringify(data, null, 2)}
|
||||
</p>
|
||||
<h2 className="col s9">{user.name}</h2>
|
||||
</div>
|
||||
<p>
|
||||
<b>Email: </b>
|
||||
{user.email}
|
||||
<br />
|
||||
{JSON.stringify(data, null, 2)}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export default class Firebase {
|
|||
// this should put email, idMeal, strMeal and isFav
|
||||
add = async (email, id, fav) => {
|
||||
await this.db
|
||||
.collection("MealPlannerFavs")
|
||||
.collection("mealPlannerUsers")
|
||||
.add({ email: email, idMeal: id, isfav: fav })
|
||||
.then((ref) => {
|
||||
console.log("Added document with ID: ", ref.id);
|
||||
|
|
@ -31,23 +31,34 @@ export default class Firebase {
|
|||
.catch((error) => console.error("Error adding document: ", error));
|
||||
};
|
||||
|
||||
// get infos for user 'email'
|
||||
getByEmail = async (email) => {
|
||||
const query = await this.db
|
||||
.collection("MealPlannerFavs")
|
||||
.collection("mealPlannerUsers")
|
||||
.where("email", "==", email)
|
||||
.limit(1)
|
||||
.get();
|
||||
const snapshot = query.docs[0];
|
||||
return snapshot.data();
|
||||
|
||||
return query.docs[0].data();
|
||||
};
|
||||
|
||||
// get all favs for user 'email'
|
||||
get = async (email) => {
|
||||
getFavsByEmail = async (email) => {
|
||||
const query = await this.db
|
||||
.collection("mealPlannerUsers")
|
||||
.where("email", "==", email)
|
||||
.get();
|
||||
// .then((doc) => doc.data());
|
||||
const snapshot = query.docs[0];
|
||||
return snapshot.data();
|
||||
return query.docs[0].collection("favs").get();
|
||||
|
||||
// .limit(1)
|
||||
// .get();
|
||||
|
||||
// return query.docs[0].data();
|
||||
// const user = await this.getByEmail(email);
|
||||
// const query = user.collection("favs").get();
|
||||
|
||||
// const favs = [];
|
||||
// query.docs.forEach((doc) => favs.push(doc.data()));
|
||||
// console.log(favs);
|
||||
// return favs;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue