Skip to content

Commit

Permalink
removed the error for the loggedIn variable not able to stay same for…
Browse files Browse the repository at this point in the history
… the whole program
  • Loading branch information
Anshpatel2434 committed Jun 30, 2024
1 parent 2f7f8b7 commit 3ae190b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 12 deletions.
12 changes: 10 additions & 2 deletions frontend/src/Components/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ const DropDown = () => {
<span>{">"}</span>
</a>
<a
href="/addFurniture"
href=""
className="sub-menu-link no-underline flex items-center justify-start space-x-3 text-white text-[1rem]"
onClick={() => {
navigate("/addFurniture");
}}
>
<RiArmchairFill size={30} />
<p>Rent Your Furniture</p>
Expand All @@ -71,8 +74,13 @@ const DropDown = () => {
<div className="w-full h-[1px] bg-[#c0c0c0]"></div>

<a
href="#"
href=""
className="sub-menu-link no-underline flex items-center justify-start space-x-3 text-white text-[1rem]"
onClick={() => {
navigate("/");
localStorage.setItem("token", "");
localStorage.setItem("loggedIn", "" + false);
}}
>
<MdLogout size={30} />
<p className="text-red-600">Logout</p>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Components/EditFurnitureCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const EditFurnitureCard = () => {
<Card />
<Card />
<Card />
<Card />
<Card />
</div>
);
};
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/Components/GoogleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FcGoogle } from "react-icons/fc";
type User = Omit<TokenResponse, "error" | "error_description" | "error_uri">;

const GoogleButton = ({ type }: { type: "SignUp" | "Login" }) => {
const { setLoggedIn, setUsername, setLogUser } = useContext(
const { loggedIn, setLoggedIn, setUsername, setLogUser } = useContext(
AppContext
) as Context;
const navigate = useNavigate();
Expand All @@ -38,9 +38,9 @@ const GoogleButton = ({ type }: { type: "SignUp" | "Login" }) => {
localStorage.setItem("token", data.message);
setUsername(data.name);
navigate("/setpassword");
} else if (data.status == 403) {
setLoggedIn(true);
googleLogout();
localStorage.setItem("loggedIn", "" + true);
} else if (data.status == 403) {
localStorage.setItem("token", data.message);
setUsername(data.name);
navigate("/");
Expand All @@ -61,8 +61,9 @@ const GoogleButton = ({ type }: { type: "SignUp" | "Login" }) => {
);
const data = res.data;
if (data.status == 200) {
googleLogout();
setLoggedIn(true);
setUsername(data.name);
localStorage.setItem("loggedIn", "" + true);
localStorage.setItem("token", data.message);
navigate("/");
} else alert(data.message);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Hero = () => {
<div className="container mx-auto h-full sm:p-10">
<nav className="flex px-4 justify-between items-center">
<div className="text-4xl font-bold mt-6">
DallaSphere<span className="text-blue-700">.</span>
FurnitureSphere<span className="text-blue-700">.</span>
</div>
</nav>
<header className="container px-4 lg:flex mt-2 items-center h-full lg:mt-0">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Components/LogInInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const LogInInput = () => {
});
const data = res.data;
if (data.status == 200) {
console.log(res.data);
console.log("in login :", res.data);
localStorage.setItem("token", data.token);
setLoggedIn(true);
localStorage.setItem("loggedIn", "" + true);
setUsername(data.name);
navigate("/");
} else alert(data.message);
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/Components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const Navbar = () => {
const [search, setSearch] = useState("");
const navigate = useNavigate();

const [loggedInl, setLoggedInl] = useState(() => {
return localStorage.getItem("loggedIn") === "true";
});

function handleKey(e: React.KeyboardEvent<HTMLInputElement>) {
if (e.key == "Enter") {
Search(search);
Expand All @@ -62,7 +66,7 @@ const Navbar = () => {
href=""
className="md:border max-w-[12rem] h-full md:flex-shrink-0 flex items-center justify-center md:px-4 lg:px-6 xl:px-8"
>
<span className="text-xl font-bold">DallaSphere</span>
<span className="text-xl font-bold">FurtinureSphere</span>
</a>
<div className="md:hidden border w-[4rem] flex items-center justify-center">
<a>
Expand Down Expand Up @@ -100,7 +104,7 @@ const Navbar = () => {
</nav>

<div className="border items-center px-4 lg:px-6 hidden md:flex xl:px-8 gap-6">
{loggedIn ? (
{loggedInl ? (
Photo(username, dropdown, setDropdown)
) : (
<>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/Components/SignUpInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const SignUpInput = () => {
if (data.status == 200) {
localStorage.setItem("token", data.message);
setLoggedIn(true);
localStorage.setItem("loggedIn", "" + true);
setUsername(data.name);
navigate("/");
} else if (data.status == 403) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Context/UseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const AppContextProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const [loggedIn, setLoggedIn] = useState<boolean>(false);
const [username, setUsername] = useState<string>("");
const [username, setUsername] = useState<string>("Ansh Patel");
const [dropdown, setDropdown] = useState<boolean>(false);
const [logUser, setLogUser] = useState<User>({
name: "",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/Pages/AddFurniture.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React, { useState } from "react";
import React, { useContext, useState } from "react";
import EditFurnitureCard from "../Components/EditFurnitureCard";
import Navbar from "../Components/Navbar";
import { MdAddBusiness } from "react-icons/md";
import TagCard from "../Components/TagCard";
import image from "../assets/chair.jpg";
import { useNavigate } from "react-router-dom";
import { AppContext, Context } from "../Context/UseContext";

const AddFurniture = () => {
const [showChildCards, setshowChildCards] = useState<boolean>(false);
const navigate = useNavigate();
const { loggedIn } = useContext(AppContext) as Context;

return (
<div className="flex flex-col overflow-x-hidden relative min-h-screen bg-slate-600">
Expand Down

0 comments on commit 3ae190b

Please sign in to comment.