From df283c820636ef6966f03b0a3e0d8dc2565cf867 Mon Sep 17 00:00:00 2001 From: "Rayyan (Rayy)" Date: Tue, 28 Nov 2023 08:21:23 +0000 Subject: [PATCH] Add Firestore Context --- src/App.js | 3 +++ src/components/ReviewForm.js | 4 ++++ src/contexts/FSContext.js | 3 +++ src/pages/Detail.js | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/contexts/FSContext.js diff --git a/src/App.js b/src/App.js index 9d1e00e..214383e 100644 --- a/src/App.js +++ b/src/App.js @@ -27,6 +27,7 @@ import { Detail } from "./pages/Detail"; // contexts import { AuthContext } from "./contexts/AuthContext" import { StorageContext } from "./contexts/StorageContext"; +import { FSContext } from "./contexts/FSContext"; @@ -145,6 +146,7 @@ const readData = async () => {
+ } /> } /> @@ -154,6 +156,7 @@ const readData = async () => { } /> } /> + diff --git a/src/components/ReviewForm.js b/src/components/ReviewForm.js index ae0c065..8361189 100644 --- a/src/components/ReviewForm.js +++ b/src/components/ReviewForm.js @@ -2,7 +2,9 @@ import Form from "react-bootstrap/Form" import Button from "react-bootstrap/Button" import { AuthContext } from "../contexts/AuthContext" +import { FSContext } from "../contexts/FSContext" import { useContext, useState } from "react" +import { collection, addDoc } from "firebase/firestore"; const submitHandler = (event) => { event.preventDefault() @@ -10,6 +12,8 @@ event.preventDefault() export function ReviewForm(props) { const auth = useContext(AuthContext) + const db = useContext(FSContext) + const[star, setStar ] = useState() const[title, setTitle ] = useState() const[review, setReview ] = useState() diff --git a/src/contexts/FSContext.js b/src/contexts/FSContext.js new file mode 100644 index 0000000..1a8452d --- /dev/null +++ b/src/contexts/FSContext.js @@ -0,0 +1,3 @@ +import { createContext } from 'react'; + +export const FSContext = createContext() \ No newline at end of file diff --git a/src/pages/Detail.js b/src/pages/Detail.js index 167966b..6475fbd 100644 --- a/src/pages/Detail.js +++ b/src/pages/Detail.js @@ -50,7 +50,7 @@ export function Detail(props) { - +