mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-12 13:26:45 +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/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.4.0",
|
"@testing-library/react": "^9.4.0",
|
||||||
"@testing-library/user-event": "^7.2.1",
|
"@testing-library/user-event": "^7.2.1",
|
||||||
"dotenv": "^8.2.0",
|
|
||||||
"firebase": "^7.13.2",
|
"firebase": "^7.13.2",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.12.0",
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ const MainRouter = ({
|
||||||
<HomeController buttonUrl={buttonUrl} />
|
<HomeController buttonUrl={buttonUrl} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<PrivateRoute exact path="/profile">
|
<PrivateRoute exact path="/profile" component={ProfileController} />
|
||||||
<ProfileController />
|
|
||||||
</PrivateRoute>
|
|
||||||
|
|
||||||
<Route exact path={buttonUrl}>
|
<Route exact path={buttonUrl}>
|
||||||
<MealController
|
<MealController
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export const MealController = ({ meal, getMeal, getRandomMeal }) => {
|
||||||
}
|
}
|
||||||
// };
|
// };
|
||||||
// add2Fav(user, idMeal, isFav).then((data) => console.log(data));
|
// add2Fav(user, idMeal, isFav).then((data) => console.log(data));
|
||||||
}, [user, idMeal, isFav]);
|
}, [user, idMeal, isFav, fb, isAuthenticated]);
|
||||||
|
|
||||||
const item = {
|
const item = {
|
||||||
mealName: strMeal,
|
mealName: strMeal,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ export const ProfileController = () => {
|
||||||
const db = useFirebase();
|
const db = useFirebase();
|
||||||
|
|
||||||
useEffect(() => {
|
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]);
|
}, [db, user.email]);
|
||||||
|
|
||||||
return loading || !user ? ( // is catched by PrivateRoute
|
return loading || !user ? ( // is catched by PrivateRoute
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,21 @@ import React from "react";
|
||||||
export const ProfilePage = ({ user, data }) => {
|
export const ProfilePage = ({ user, data }) => {
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<div className="row">
|
<div className="row valign-wrapper">
|
||||||
<img
|
<img
|
||||||
className="circle responsive-img"
|
className="left circle responsive-img"
|
||||||
src={user.picture}
|
src={user.picture}
|
||||||
alt="Avatar"
|
alt="Avatar"
|
||||||
width="20%"
|
width="15%"
|
||||||
/>
|
/>
|
||||||
<h2>{user.name}</h2>
|
<h2 className="col s9">{user.name}</h2>
|
||||||
<p>
|
|
||||||
<b>Email: </b>
|
|
||||||
{user.email}
|
|
||||||
{JSON.stringify(data, null, 2)}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<p>
|
||||||
|
<b>Email: </b>
|
||||||
|
{user.email}
|
||||||
|
<br />
|
||||||
|
{JSON.stringify(data, null, 2)}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export default class Firebase {
|
||||||
// this should put email, idMeal, strMeal and isFav
|
// this should put email, idMeal, strMeal and isFav
|
||||||
add = async (email, id, fav) => {
|
add = async (email, id, fav) => {
|
||||||
await this.db
|
await this.db
|
||||||
.collection("MealPlannerFavs")
|
.collection("mealPlannerUsers")
|
||||||
.add({ email: email, idMeal: id, isfav: fav })
|
.add({ email: email, idMeal: id, isfav: fav })
|
||||||
.then((ref) => {
|
.then((ref) => {
|
||||||
console.log("Added document with ID: ", ref.id);
|
console.log("Added document with ID: ", ref.id);
|
||||||
|
|
@ -31,23 +31,34 @@ export default class Firebase {
|
||||||
.catch((error) => console.error("Error adding document: ", error));
|
.catch((error) => console.error("Error adding document: ", error));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// get infos for user 'email'
|
||||||
getByEmail = async (email) => {
|
getByEmail = async (email) => {
|
||||||
const query = await this.db
|
const query = await this.db
|
||||||
.collection("MealPlannerFavs")
|
.collection("mealPlannerUsers")
|
||||||
.where("email", "==", email)
|
.where("email", "==", email)
|
||||||
|
.limit(1)
|
||||||
.get();
|
.get();
|
||||||
const snapshot = query.docs[0];
|
|
||||||
return snapshot.data();
|
return query.docs[0].data();
|
||||||
};
|
};
|
||||||
|
|
||||||
// get all favs for user 'email'
|
getFavsByEmail = async (email) => {
|
||||||
get = async (email) => {
|
|
||||||
const query = await this.db
|
const query = await this.db
|
||||||
.collection("mealPlannerUsers")
|
.collection("mealPlannerUsers")
|
||||||
.where("email", "==", email)
|
.where("email", "==", email)
|
||||||
.get();
|
.get();
|
||||||
// .then((doc) => doc.data());
|
return query.docs[0].collection("favs").get();
|
||||||
const snapshot = query.docs[0];
|
|
||||||
return snapshot.data();
|
// .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