diff --git a/package-lock.json b/package-lock.json index 7ecf9b306..2859259b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "react-dom": "^18.2.0", "react-icons": "^4.7.1", "react-lazy-load-image-component": "^1.5.6", + "react-router-dom": "^5.3.0", "uuid": "^9.0.0" }, "devDependencies": { @@ -2507,6 +2508,19 @@ "node": ">=4" } }, + "node_modules/history": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", + "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "dependencies": { + "@babel/runtime": "^7.1.2", + "loose-envify": "^1.2.0", + "resolve-pathname": "^3.0.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0", + "value-equal": "^1.0.1" + } + }, "node_modules/hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -2595,6 +2609,11 @@ "resolved": "https://registry.npmjs.org/is-in-browser/-/is-in-browser-1.1.3.tgz", "integrity": "sha512-FeXIBgG/CPGd/WUxuEyvgGTEfwiG9Z4EKGxjNMRqviiIIfsmgrpnHLffEDdwUHqNva1VEW91o3xBT/m8Elgl9g==" }, + "node_modules/isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -2991,6 +3010,14 @@ "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, + "node_modules/path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dependencies": { + "isarray": "0.0.1" + } + }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -3175,6 +3202,47 @@ "node": ">=0.10.0" } }, + "node_modules/react-router": { + "version": "5.3.4", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.3.4.tgz", + "integrity": "sha512-Ys9K+ppnJah3QuaRiLxk+jDWOR1MekYQrlytiXxC1RyfbdsZkS5pvKAzCCr031xHixZwpnsYNT5xysdFHQaYsA==", + "dependencies": { + "@babel/runtime": "^7.12.13", + "history": "^4.9.0", + "hoist-non-react-statics": "^3.1.0", + "loose-envify": "^1.3.1", + "path-to-regexp": "^1.7.0", + "prop-types": "^15.6.2", + "react-is": "^16.6.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + }, + "peerDependencies": { + "react": ">=15" + } + }, + "node_modules/react-router-dom": { + "version": "5.3.4", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.3.4.tgz", + "integrity": "sha512-m4EqFMHv/Ih4kpcBCONHbkT68KoAeHN4p3lAGoNryfHi0dMy0kCzEZakiKRsvg5wHZ/JLrLW8o8KomWiz/qbYQ==", + "dependencies": { + "@babel/runtime": "^7.12.13", + "history": "^4.9.0", + "loose-envify": "^1.3.1", + "prop-types": "^15.6.2", + "react-router": "5.3.4", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + }, + "peerDependencies": { + "react": ">=15" + } + }, + "node_modules/react-router/node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" + }, "node_modules/react-transition-group": { "version": "4.4.5", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz", @@ -3227,6 +3295,11 @@ "node": ">=4" } }, + "node_modules/resolve-pathname": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", + "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==" + }, "node_modules/rollup": { "version": "3.17.2", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.17.2.tgz", @@ -3368,6 +3441,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/tiny-invariant": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.1.tgz", + "integrity": "sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==" + }, "node_modules/tiny-warning": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", @@ -3455,6 +3533,11 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/value-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", + "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==" + }, "node_modules/vite": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/vite/-/vite-4.1.4.tgz", diff --git a/package.json b/package.json index fc5f4ee91..669ba07aa 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "react-dom": "^18.2.0", "react-icons": "^4.7.1", "react-lazy-load-image-component": "^1.5.6", + "react-router-dom": "^5.3.0", "uuid": "^9.0.0" }, "devDependencies": { diff --git a/src/App.jsx b/src/App.jsx index e87f95ec2..c64bd7300 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,29 +1,19 @@ -import React, { useState, useEffect, useMemo } from "react"; +import React, { useState, useEffect } from "react"; import Post from "./components/Post"; -import { - db, - auth, - storage, - googleProvider, - facebookProvider, -} from "./lib/firebase"; -import { - Modal, - Button, - Input, - Dialog, - DialogTitle, - DialogContent, -} from "@mui/material"; +import { db, auth } from "./lib/firebase"; +import { Button, Dialog, Modal, DialogContent } from "@mui/material"; import { makeStyles } from "@mui/styles"; import ImgUpload from "./components/ImgUpload"; import Loader from "./components/Loader"; -import AnimatedButton from "./components/AnimatedButton"; import { FaArrowCircleUp } from "react-icons/fa"; import { useSnackbar } from "notistack"; import logo from "./assets/logo.png"; +import { Switch, Route, useHistory } from "react-router-dom"; +import LoginScreen from "./pages/Login"; +import SignupScreen from "./pages/Signup"; +import AnimatedButton from "./components/AnimatedButton"; -function getModalStyle() { +export function getModalStyle() { const top = 50; const left = 50; const padding = 5; @@ -36,43 +26,35 @@ function getModalStyle() { padding: `${padding}%`, borderRadius: `${radius}%`, textAlign: "center", + backgroundColor: "var(--bg-color)", }; } -const useStyles = makeStyles((theme) => ({ +export const useStyles = makeStyles((theme) => ({ paper: { position: "absolute", width: 200, - backgroundColor: theme.palette.background.paper, - border: "2px solid #000", + border: "1px solid var(--color)", borderRadius: theme.shape.borderRadius, - boxShadow: theme.shadows[5], + boxShadow: theme.shadows[10], padding: theme.spacing(2, 4, 3), + color: "var(--color)", }, })); function App() { const classes = useStyles(); - const [modalStyle] = useState(getModalStyle); + const history = useHistory(); + const [posts, setPosts] = useState([]); - const [openSignUp, setOpenSignUp] = useState(false); - const [openSignIn, setOpenSignIn] = useState(false); - const [username, setUsername] = useState(""); - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); const [user, setUser] = useState(null); - const [signingUp, setSigningUp] = useState(false); - const [loggingIn, setLoggingIn] = useState(false); const [loadingPosts, setLoadingPosts] = useState(true); const [pageSize, setPageSize] = useState(10); const [loadMorePosts, setLoadMorePosts] = useState(false); const [openNewUpload, setOpenNewUpload] = useState(false); const [logout, setLogout] = useState(false); - const processingAuth = useMemo( - () => loggingIn || signingUp || loadingPosts, - [loggingIn, signingUp, loadingPosts] - ); + const buttonStyle = { background: "linear-gradient(40deg, #e107c1, #59afc7)", borderRadius: "20px", @@ -81,19 +63,9 @@ function App() { }, }; - const [image, setImage] = useState(null); - const [address, setAddress] = useState(null); - const { enqueueSnackbar } = useSnackbar(); const [showScroll, setShowScroll] = useState(false); - const handleChange = (e) => { - if (e.target.files[0]) { - setImage(e.target.files[0]); - setAddress(e.target.value); - } - }; - const checkScrollTop = () => { if (!showScroll && window.pageYOffset > 400) { setShowScroll(true); @@ -111,20 +83,34 @@ function App() { useEffect(() => { const unsubscribe = auth.onAuthStateChanged((authUser) => { if (authUser) { - // user has logged in setUser(authUser); + history.push("/dummygram/"); } else { - // user has logged out setUser(null); + history.push("/dummygram/login"); } }); + return () => { - // perform some cleanup actions unsubscribe(); }; - }, [user, username]); + }, [user]); useEffect(() => { + if (document.body.classList.contains("darkmode--activated")) { + window.document.body.style.setProperty("--bg-color", "black"); + window.document.body.style.setProperty("--color", "white"); + window.document.body.style.setProperty("--val", 1); + document.getElementsByClassName("app__header__img").item(0).style.filter = + "invert(100%)"; + } else { + window.document.body.style.setProperty("--bg-color", "white"); + window.document.body.style.setProperty("--color", "#2B1B17"); + window.document.body.style.setProperty("--val", 0); + document.getElementsByClassName("app__header__img").item(0).style.filter = + "invert(0%)"; + } + window.addEventListener("scroll", handleMouseScroll); db.collection("posts") .orderBy("timestamp", "desc") @@ -170,79 +156,6 @@ function App() { setLoadMorePosts(false); }, [loadMorePosts]); - const signUp = (e) => { - e.preventDefault(); - setSigningUp(true); - auth - .createUserWithEmailAndPassword(email, password) - .then((authUser) => { - const uploadTask = storage.ref(`images/${image.name}`).put(image); - uploadTask.on( - "state_changed", - (snapshot) => { - // // progress function ... - // setProgress(Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100)); - }, - (error) => { - // error function ... - - enqueueSnackbar(error.message, { - variant: "error", - }); - }, - () => { - // complete function ... - storage - .ref("images") - .child(image.name) - .getDownloadURL() - .then((url) => { - authUser.user.updateProfile({ - displayName: username, - photoURL: url, - }); - enqueueSnackbar("Signup Successful!", { - variant: "success", - }); - setOpenSignUp(false); - }); - } - ); - }) - // .then(() => { - - // }) - .catch((error) => - enqueueSnackbar(error.message, { - variant: "error", - }) - ) - .finally(() => { - setSigningUp(false); - }); - }; - - const signIn = (e) => { - e.preventDefault(); - setLoggingIn(true); - auth - .signInWithEmailAndPassword(email, password) - .then(() => { - enqueueSnackbar("Login successful!", { - variant: "success", - }); - setOpenSignIn(false); - }) - .catch((error) => - enqueueSnackbar(error.message, { - variant: "error", - }) - ) - .finally(() => { - setLoggingIn(false); - }); - }; - const signOut = () => { auth.signOut().finally(); enqueueSnackbar("Logged out Successfully !", { @@ -250,48 +163,6 @@ function App() { }); }; - const signInWithGoogle = (e) => { - e.preventDefault(); - setLoggingIn(true); - auth - .signInWithPopup(googleProvider) - .then(() => { - enqueueSnackbar("Login successful!", { - variant: "success", - }); - setOpenSignIn(false); - }) - .catch((error) => - enqueueSnackbar(error.message, { - variant: "error", - }) - ) - .finally(() => { - setLoggingIn(false); - }); - }; - - const signInWithFacebook = (e) => { - e.preventDefault(); - setLoggingIn(true); - auth - .signInWithPopup(facebookProvider) - .then(() => { - enqueueSnackbar("Login successful!", { - variant: "success", - }); - setOpenSignIn(false); - }) - .catch((error) => - enqueueSnackbar(error.message, { - variant: "error", - }) - ) - .finally(() => { - setLoggingIn(false); - }); - }; - return (