diff --git a/index.html b/index.html
index 3b98a8df4..365a877b1 100644
--- a/index.html
+++ b/index.html
@@ -2,7 +2,7 @@
-
+
DummyGram
diff --git a/src/App.jsx b/src/App.jsx
index 6ae0c8bf0..9e8dd227f 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,9 +1,11 @@
-import React, { useState, useEffect } from "react";
+import React, { useState, useEffect, useMemo } from "react";
import Post from "./components/Post";
import { db, auth } from "./lib/firebase";
import { Modal, Button, Input } from "@mui/material";
import { makeStyles } from "@mui/styles";
import ImgUpload from "./components/ImgUpload";
+import Loader from "./components/Loader";
+import AnimatedButton from "./components/AnimatedButton";
function getModalStyle() {
const top = 50;
@@ -39,6 +41,12 @@ function App() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [user, setUser] = useState(null);
+ const [signingUp, setSigningUp] = useState(false);
+ const [logginIn, setLogginIn] = useState(false);
+ const processingAuth = useMemo(
+ () => logginIn || signingUp,
+ [logginIn, signingUp]
+ );
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((authUser) => {
@@ -73,6 +81,7 @@ function App() {
const signUp = (e) => {
e.preventDefault();
+ setSigningUp(true);
auth
.createUserWithEmailAndPassword(email, password)
.then((authUser) => {
@@ -80,16 +89,35 @@ function App() {
displayName: username,
});
})
- .catch((error) => alert(error.message));
- setOpenSignUp(false);
+ .then(() => {
+ alert("Signup Successful!");
+ setOpenSignUp(false);
+ })
+ .catch((error) => alert(error.message))
+ .finally(() => {
+ setSigningUp(false);
+ });
};
const signIn = (e) => {
e.preventDefault();
+ setLogginIn(true);
auth
.signInWithEmailAndPassword(email, password)
- .catch((error) => alert(error.message));
- setOpenSignIn(false);
+ .then(() => {
+ alert("Login successful!");
+ setOpenSignIn(false);
+ })
+ .catch((error) => alert(error.message))
+ .finally(() => {
+ setLogginIn(false);
+ });
+ };
+
+ const signOut = () => {
+ if (confirm("Are you sure you want to logout?")) {
+ auth.signOut().finally();
+ }
};
return (
@@ -100,10 +128,11 @@ function App() {
alt="instagram"
className="app__header__img"
/>
-
- {user ? (
+ {processingAuth ? (
+
+ ) : user ? (