From 1a2c28080d98c0f51af7dda2e30b6eacaf5320e3 Mon Sep 17 00:00:00 2001 From: VividTruthKeeper Date: Sat, 10 Sep 2022 19:13:19 +0500 Subject: [PATCH] category page --- public/.htaccess => .htaccess | 0 src/App.tsx | 14 ++++++-- src/assets/styles/_category.scss | 61 ++++++++++++++++++++++++++++++++ src/assets/styles/style.scss | 1 + src/components/Aside.tsx | 10 ++++++ src/components/Nav.tsx | 4 ++- src/pages/Category.tsx | 35 ++++++++++++++++++ src/pages/Login.tsx | 8 ----- src/pages/Main.tsx | 15 +------- 9 files changed, 123 insertions(+), 25 deletions(-) rename public/.htaccess => .htaccess (100%) create mode 100644 src/assets/styles/_category.scss create mode 100644 src/pages/Category.tsx diff --git a/public/.htaccess b/.htaccess similarity index 100% rename from public/.htaccess rename to .htaccess diff --git a/src/App.tsx b/src/App.tsx index 4af4099..41186ee 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ // Modules import { useMemo, useState, useEffect } from "react"; -import { Routes, Route } from "react-router-dom"; +import { Routes, Route, useNavigate } from "react-router-dom"; import { UserContext } from "./context/UserContext"; import { PostContext } from "./context/PostContext"; @@ -17,8 +17,10 @@ import Dashboard from "./pages/Dashboard"; import Posts from "./pages/Posts"; import Details from "./pages/Details"; import Post from "./pages/Post"; +import Category from "./pages/Category"; const App = () => { + const navigate = useNavigate(); const date = new Date("0.0.0000"); const [posts, setPosts] = useState([ { @@ -40,7 +42,6 @@ const App = () => { useEffect(() => { const userData = localStorage.getItem("userData"); - if (userData) { setUser(JSON.parse(userData)); } @@ -49,6 +50,14 @@ const App = () => { const userValue = useMemo(() => ({ user, setUser }), [user, setUser]); const postValue = useMemo(() => ({ posts, setPosts }), [posts, setPosts]); + useEffect(() => { + if (!user.username) { + navigate("/login"); + } else { + navigate(localStorage.getItem("lastLocation") || "/dashboard"); + } + }, [user]); + return ( @@ -57,6 +66,7 @@ const App = () => { } /> } />} /> } />} /> + } />} /> } />} /> { Posts +
  • + localStorage.setItem("lastLocation", "/category")} + > + + Category + +
  • Account

    diff --git a/src/components/Nav.tsx b/src/components/Nav.tsx index f65aa8b..08a5882 100644 --- a/src/components/Nav.tsx +++ b/src/components/Nav.tsx @@ -27,7 +27,9 @@ const Nav = ({ aside, setAside }: Props) => { localStorage.setItem("lastLocation", "/dashboard")} + onClick={() => { + localStorage.setItem("lastLocation", "/dashboard"); + }} > diff --git a/src/pages/Category.tsx b/src/pages/Category.tsx new file mode 100644 index 0000000..4877be3 --- /dev/null +++ b/src/pages/Category.tsx @@ -0,0 +1,35 @@ +// Icons +import { IoIosCreate } from "react-icons/io"; + +const Category = () => { + return ( +
    +
    +
    +
    + +

    Category

    +
    +
    ) => + e.preventDefault() + } + > +
    + + +
    + +
    +
    +
    +
    + ); +}; + +export default Category; diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index 92781f4..f4b4687 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -7,7 +7,6 @@ import { useNavigate } from "react-router-dom"; import { cred } from "../user"; const Login = () => { - const lastLocation = localStorage.getItem("lastLocation"); const [valid, setValid] = useState({ username: "", password: "", @@ -17,7 +16,6 @@ const Login = () => { }); const { user, setUser } = useContext(UserContext); - const navigate = useNavigate(); useEffect(() => { if (valid.username === cred.username && valid.password === cred.password) { @@ -27,12 +25,6 @@ const Login = () => { } }, [valid.username, valid.password]); - useEffect(() => { - if (user.username) { - navigate(lastLocation || "/dashboard"); - } - }, [user]); - return (
    diff --git a/src/pages/Main.tsx b/src/pages/Main.tsx index 94aa6ff..fcd3574 100644 --- a/src/pages/Main.tsx +++ b/src/pages/Main.tsx @@ -1,26 +1,13 @@ // Modules -import { useState, useContext, useEffect } from "react"; -import { useNavigate } from "react-router-dom"; -import { UserContext } from "../context/UserContext"; +import { useState } from "react"; // Components import Nav from "../components/Nav"; import Aside from "../components/Aside"; -// Types -import { userContextType } from "../types/user"; - const Main = ({ child }: any) => { - const navigate = useNavigate(); - const { user, setUser }: userContextType = useContext(UserContext); const [aside, setAside] = useState(true); - useEffect(() => { - if (!user.username) { - navigate("/login"); - } - }, [user]); - return (