Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
52d80de
Test committing from another branch
JCamyre Nov 5, 2022
13bcae2
Add basic route for posts with a URL parameter and a basic Post page
JCamyre Nov 12, 2022
755e157
Test committing from another branch
JCamyre Nov 5, 2022
d61a95d
Add basic route for posts with a URL parameter and a basic Post page
JCamyre Nov 12, 2022
86d7347
Fix
JCamyre Nov 12, 2022
7855b5d
Test id url and react-responsive-carousel
JCamyre Nov 12, 2022
c511017
Test committing from another branch
JCamyre Nov 5, 2022
cdf7a6e
Add more components to Post.jsx and fix rebasing
JCamyre Nov 12, 2022
1d68fa6
Add more components to Post.jsx and fix rebasing
JCamyre Nov 12, 2022
15a2078
Readd Post.jsx progress I lost from rebase fiasco
JCamyre Nov 12, 2022
6a59de2
Fix
JCamyre Nov 12, 2022
bace62a
Finally fix rebase
JCamyre Nov 12, 2022
fc30a66
Add skeleton of Login page. Add input fields, submit button, link to …
JCamyre Nov 19, 2022
116f941
Add React state to track and submit password and email
JCamyre Nov 19, 2022
1769b69
Add skeleton of Post page, including Image Carousel, title, price, lo…
JCamyre Nov 19, 2022
254f007
added firebase setup and registration function for email/password reg…
justinsheu Nov 19, 2022
7dc1c8c
added basic registration page which allows user to input username, em…
justinsheu Nov 19, 2022
df856df
Add redirect to home page after successfully logging in
JCamyre Nov 23, 2022
98b30ee
Add comments for code
JCamyre Nov 23, 2022
298119e
Finish basic post page
JCamyre Nov 23, 2022
e4482ae
Add comments to show where to implement backend calls for authentication
JCamyre Nov 25, 2022
85e5ab9
Merge branch 'login-page' into add-authentication
JCamyre Nov 25, 2022
4d3a935
Merge pull request #1 from JCamyre/add-authentication
JCamyre Nov 25, 2022
97835ba
added login function and basic login flow
justinsheu Nov 25, 2022
74bf982
added protected routing to restrict access to pages based on login st…
justinsheu Nov 25, 2022
3faaee7
added logout flow, registering now logs user in, user data is now pas…
justinsheu Nov 25, 2022
931e573
moved sensitive keys to .env rather than being hardcoded, fixed lint …
justinsheu Nov 26, 2022
4c3520a
modified registration function, fixed flow for failed registration
justinsheu Nov 26, 2022
8c7bbef
added basic frontend check for g.ucla.edu email when registering
justinsheu Nov 26, 2022
2a7570f
Merge changes between auth and create-post
JCamyre Nov 30, 2022
4eb3347
Merge branch 'add-authentication' into auth-flow
JCamyre Nov 30, 2022
e64302a
Merge pull request #9 from JCamyre/auth-flow
JCamyre Nov 30, 2022
2f2e48a
Added post functionality to send data to firestore and cloud storage
Nov 30, 2022
f95fe87
Added price to creating post and fixed bugs
Nov 30, 2022
d7205bd
Add star rating system frontend
JCamyre Nov 30, 2022
c513fa3
Merge branch 'stars' into add-authentication
JCamyre Nov 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bruinmarket/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
REACT_APP_APIKEY = AIzaSyBCCQ4AhObIjdEv1OMfx9pbUqGcEKsNkd8
REACT_APP_AUTHDOMAIN = bruinmarket-cc504.firebaseapp.com
REACT_APP_PROJECTID = bruinmarket-cc504
REACT_APP_STORAGEBUCKET = bruinmarket-cc504.appspot.com
REACT_APP_MESSAGINGSENDERID = 6631642670
REACT_APP_APPID = 1:6631642670:web:ae6d95485d0d40895bf1bf
REACT_APP_MEASUREMENTID = G-PNENCNQE2Q
1 change: 1 addition & 0 deletions bruinmarket/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
60 changes: 53 additions & 7 deletions bruinmarket/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bruinmarket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"framer-motion": "^7.6.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-firebase-hooks": "^5.1.0",
"react-firebase-hooks": "^5.1.1",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.4.3",
"react-scripts": "5.0.1",
"react-star-ratings": "^2.3.0",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
67 changes: 60 additions & 7 deletions bruinmarket/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,74 @@ import React from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Home from "./components/pages/Home.jsx";
import AllPosts from "./components/pages/AllPosts.jsx";
import TempRegister from "./components/pages/TempRegister.jsx";
import CreatePost from "./components/pages/CreatePost.jsx";
import Post from "./components/pages/Post.jsx";
import { ChakraProvider } from "@chakra-ui/react";
import Login from "./components/pages/Login.jsx";
import ProtectedRoute from "./utilities/ProtectedRoute"
import { auth, firestore, database } from "./firebase"

const AuthContext = React.createContext(null)

function App() {
const [loggedIn, setLoggedIn] = React.useState(-1); //initialize to -1 to account for period of time when login state is indeterminate
const [userUID, setUserUID] = React.useState(null)
const [userData, setData] = React.useState(null)
React.useEffect(() => {
auth.onAuthStateChanged((user) => {
if (user) {
setLoggedIn(1);
setUserUID(user.uid);
// console.log(userData.username)
} else {
console.log ("successfully logged out")
setLoggedIn(0);
setUserUID(null);
// console.log(userData.username)
}
});
}, []); //useEffect prevents onAuthStateChanged listener from being set multiple times
React.useEffect(() => {
async function getUserData (uid) {
const q = firestore.query(firestore.collection(database, "users"), firestore.where("uid", "==", uid))
const docs = await firestore.getDocs(q)
let data = null
docs.forEach((doc) => {
// console.log(doc.data().username)
data = doc.data()
})
console.log(data)
setData(data)
}
if (userUID) {
getUserData(userUID)
}
}, [userUID])
return (
<ChakraProvider>
<BrowserRouter>
<Routes>
<Route index element={<Home />} />
<Route path="/allposts" element={<AllPosts />} />
<Route path="/createpost" element={<CreatePost />} />
</Routes>
</BrowserRouter>
<AuthContext.Provider value={userData}>
<BrowserRouter>
<Routes>
{loggedIn === -1 ? null :
<>
<Route element={<ProtectedRoute allowed={loggedIn===1} alternateRoute="/login" />} >
<Route path="/" element={<Home />} />
<Route path="/allposts" element={<AllPosts />} />
<Route path="/createpost" element={<CreatePost />} />
</Route>
<Route element={<ProtectedRoute allowed={loggedIn===0} alternateRoute="/" />} >
<Route path="/testregister" element={<TempRegister />} />
<Route path="/login" element={<Login />} />
</Route>
</>
}
</Routes>
</BrowserRouter>
</AuthContext.Provider>
</ChakraProvider>
);
}

export {AuthContext};
export default App;
3 changes: 3 additions & 0 deletions bruinmarket/src/components/Navbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a:hover {
text-decoration: none;
}
27 changes: 27 additions & 0 deletions bruinmarket/src/components/Stars.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useState } from "react";
import StarRatings from "react-star-ratings";

function Stars() {
const [stars, setStars] = useState(3.78);
const [totalReviews, setTotalReviews] = useState(6);

function updateStars(newRating) {
//setTotalReviews(totalReviews + 1);
setStars((stars * totalReviews + newRating) / (totalReviews + 1));
setTotalReviews(totalReviews + 1);
console.log(stars, totalReviews);
}

return (
<div>
<StarRatings
rating={stars}
changeRating={(stars) => updateStars(stars)}
starHoverColor="yellow"
starRatedColor="blue"
/>
</div>
);
}

export default Stars;
64 changes: 45 additions & 19 deletions bruinmarket/src/components/pages/CreatePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
Container,
Stack,
Input,
InputGroup,
InputLeftElement,
Link,
Button,
FormControl,
Expand All @@ -12,39 +14,49 @@ import {
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import { storage } from './../../firebase';
import { AuthContext } from '../../App';
import { ref, getDownloadURL, uploadBytesResumable } from "firebase/storage";
import {db} from "./../../firebase"
import { getFireStore, collection, addDoc } from "firebase/firestore";

import {database} from "./../../firebase";
import {collection, addDoc, getDocs} from "firebase/firestore";
import {getAuth, onAuthStateChanged} from "firebase/auth";
function CreatePost() {
const [title, setTitle] = useState("");
const [summary, setSummary] = useState("");
const [category, setCategory] = useState("");
const [imgUrl, setImgUrl] = useState(null);
const [progresspercent, setProgresspercent] = useState(0);
const format = (val) => `$` + val
const parse = (val) => val.replace(/^\$/, '')

const navigate = useNavigate();
const [price, setPrice] = React.useState('5.50')

function Submit(e) {
const navigate = useNavigate();
const userData = React.useContext(AuthContext);
async function Submit(e) {
e.preventDefault();
console.log();
// need to redirect to / page
console.log(`Title: ${title}, Summary: ${summary}, Category: ${category}`);

// Maybe we'll add a check to check for duplicate posts, but for now, just push to the Post table
// WE NEED TO ADD A DATABASE CALL THAT RETURNS THE ID OF THE CURRENT USER LOGGED IN

if(userData == null){
console.log("UserData is null u messed up")
}
if(summary == "" || title == "" || category == ""){
return;
}
const docRef = await addDoc(collection(database, "posts"), {
uid: userData.uid,
title: title,
summary: summary,
category: category,
price: price
});

// database.post(user_id, title, summary, category)
db.collection("cities").add({
name: "Tokyo",
country: "Japan"
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
uploadPicture(e.currentTarget.files)
console.log(e.target)
uploadPicture(e.target[4].files, docRef.id)

// pictures we will figure out.

Expand All @@ -57,15 +69,15 @@ function CreatePost() {
}

// img should be a file
function uploadPicture(imgs) {
function uploadPicture(imgs, post_id) {
const imgsArr = [...imgs];

imgsArr.forEach((img, i) => {
// FOR EACH IMAGE, UPLOAD THE FILE TO FIREBASE, WITH THE OUR WACKY NAMING SYSTEM
// POSTID + _ + PICTURE NUMBER (use the i variable for PICTURE NUMBER)
const file = img;
if (!file) return;
const storageRef = ref(storage, `files/${file.name}`);
const storageRef = ref(storage, `${post_id}/${file.name}`);
const uploadTask = uploadBytesResumable(storageRef, file);

uploadTask.on("state_changed",
Expand Down Expand Up @@ -111,6 +123,20 @@ function CreatePost() {
<option>Books</option>
</Select>
</FormControl>

<InputGroup>
<InputLeftElement
pointerEvents='none'
color='gray.300'
fontSize='1.2em'
children='$'
/>
<Input
placeholder="Enter price"
onChange={(e) => setPrice(e.currentTarget.value)}
/>
</InputGroup>

<Input
type="file"
placeholder="filename"
Expand Down
21 changes: 20 additions & 1 deletion bruinmarket/src/components/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import React from "react";
import { AuthContext } from '../../App'
import { Button } from "@chakra-ui/react"
import { useNavigate } from "react-router-dom";
import logout from "../../logout"
import Stars from "../Stars";

function Home() {
return <div>Home</div>;
const navigate = useNavigate();
const userData = React.useContext(AuthContext)
// console.log(userData.username)
return (
<>
<div>Home</div>
<div>Logged in as {userData?.username}</div>
<Button onClick={() => {
if (logout()) {
navigate("/login")
}
}}>Logout</Button>
<Stars />
</>
);
}

export default Home;
Loading