Add Firestore Context

This commit is contained in:
Ray 2023-11-28 08:21:23 +00:00 committed by GitHub
parent 47312b9868
commit df283c8206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import { Detail } from "./pages/Detail";
// contexts // contexts
import { AuthContext } from "./contexts/AuthContext" import { AuthContext } from "./contexts/AuthContext"
import { StorageContext } from "./contexts/StorageContext"; import { StorageContext } from "./contexts/StorageContext";
import { FSContext } from "./contexts/FSContext";
@ -145,6 +146,7 @@ const readData = async () => {
<Header items={nav} user={auth} /> <Header items={nav} user={auth} />
<AuthContext.Provider value={auth}> <AuthContext.Provider value={auth}>
<StorageContext.Provider value={FBstorage}> <StorageContext.Provider value={FBstorage}>
<FSContext.Provider value={FBdb}>
<Routes> <Routes>
<Route path="/" element={<Home items = {data} />} /> <Route path="/" element={<Home items = {data} />} />
<Route path="/about" element={<About greeting="Hey you, this is about page!" handler={saySomething} />} /> <Route path="/about" element={<About greeting="Hey you, this is about page!" handler={saySomething} />} />
@ -154,6 +156,7 @@ const readData = async () => {
<Route path="/signin" element={ <Signin handler={signIn} authstate={auth}/> } /> <Route path="/signin" element={ <Signin handler={signIn} authstate={auth}/> } />
<Route path="/detail/:id" element={<Detail handler={getDocument} />} /> <Route path="/detail/:id" element={<Detail handler={getDocument} />} />
</Routes> </Routes>
</FSContext.Provider>
</StorageContext.Provider> </StorageContext.Provider>
</AuthContext.Provider> </AuthContext.Provider>
</div> </div>

View File

@ -2,7 +2,9 @@ import Form from "react-bootstrap/Form"
import Button from "react-bootstrap/Button" import Button from "react-bootstrap/Button"
import { AuthContext } from "../contexts/AuthContext" import { AuthContext } from "../contexts/AuthContext"
import { FSContext } from "../contexts/FSContext"
import { useContext, useState } from "react" import { useContext, useState } from "react"
import { collection, addDoc } from "firebase/firestore";
const submitHandler = (event) => { const submitHandler = (event) => {
event.preventDefault() event.preventDefault()
@ -10,6 +12,8 @@ event.preventDefault()
export function ReviewForm(props) { export function ReviewForm(props) {
const auth = useContext(AuthContext) const auth = useContext(AuthContext)
const db = useContext(FSContext)
const[star, setStar ] = useState() const[star, setStar ] = useState()
const[title, setTitle ] = useState() const[title, setTitle ] = useState()
const[review, setReview ] = useState() const[review, setReview ] = useState()

View File

@ -0,0 +1,3 @@
import { createContext } from 'react';
export const FSContext = createContext()

View File

@ -50,7 +50,7 @@ export function Detail(props) {
</Row> </Row>
<Row> <Row>
<Col> <Col>
<ReviewForm movietitle={movieData.movie_title} /> <ReviewForm movietitle={movieData.movie_title} movieId={movieData.movieId} />
</Col> </Col>
</Row> </Row>
</Container> </Container>