diff --git a/src/App.jsx b/src/App.jsx index 3eba68e..acfa0c6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,35 +1,50 @@ +import React, { lazy, Suspense, useState } from "react"; import { ThemeProvider } from "@/components/theme-provider"; import { Route, Routes } from "react-router-dom"; -import { useState } from "react"; -// Data -import menus from "./pages/tree-view/data"; -// Layouts +// layout import Header from "@/layouts/header"; // components import Starfield from "react-starfield"; import Cursor from "./components/Cursor"; -// Pages -import Home from "@/pages/Home"; -import NotFound from "@/pages/404"; -import Accordion from "@/pages/accordion/accordion"; -import RandomColor from "@/pages/RandomColor"; -import StarRating from "@/pages/StarRating"; -import ImageSlider from "@/pages/ImageSlider"; -import LoadMoreData from "./pages/LoadMoreData"; -import TreeView from "./pages/tree-view/TreeView"; -import QRCodeGenerator from "./pages/QRCodeGenerator"; -import LightDarkMode from "./pages/light-dark-mode/Light-dark-mode"; -import TabTest from "./pages/tree-view/custom-tabs/Tab-test"; -import { ModalPopup } from "./pages/CustomModalPopup/ModalPopup"; -import { GithubProfileFinder } from "./pages/GithubProfileFinder/GithubProfileFinder"; -import { SearchAutoComplete } from "./pages/SearchAutoComplete/SearchAutoComplete"; -import { TicTacToe } from "./pages/TicTacToe"; -import FeatureFlagGlobalState from "./pages/Feature-flag/context/FeatureFlagsContext"; -import { FeatureFlags } from "./pages/Feature-flag/FeatureFlags"; -import UseFetchHookTest from "./pages/CustomHooks/use-fetch/test"; -import UseOnClickOutsideTest from "./pages/CustomHooks/use-outside-click/test"; -import { UseWindowResizeTest } from "./pages/CustomHooks/use-window-resize/test"; -import ScrollToSection from "./pages/ScrollToSection"; +// Data +import menus from "./pages/tree-view/data"; + +// pages +const Home = lazy(() => import("@/pages/Home")); +const NotFound = lazy(() => import("@/pages/404")); +const Accordion = lazy(() => import("@/pages/accordion/accordion")); +const RandomColor = lazy(() => import("@/pages/RandomColor")); +const StarRating = lazy(() => import("@/pages/StarRating")); +const ImageSlider = lazy(() => import("@/pages/ImageSlider")); +const LoadMoreData = lazy(() => import("@/pages/LoadMoreData")); +const TreeView = lazy(() => import("@/pages/tree-view/TreeView")); +const QRCodeGenerator = lazy(() => import("@/pages/QRCodeGenerator")); +const LightDarkMode = lazy( + () => import("@/pages/light-dark-mode/Light-dark-mode"), +); +const TabTest = lazy(() => import("@/pages/tree-view/custom-tabs/Tab-test")); +const ModalPopup = lazy(() => import("@/pages/CustomModalPopup/ModalPopup")); +const GithubProfileFinder = lazy( + () => import("@/pages/GithubProfileFinder/GithubProfileFinder"), +); +const SearchAutoComplete = lazy( + () => import("@/pages/SearchAutoComplete/SearchAutoComplete"), +); +const TicTacToe = lazy(() => import("@/pages/TicTacToe")); +const FeatureFlagGlobalState = lazy( + () => import("@/pages/Feature-flag/context/FeatureFlagsContext"), +); +const FeatureFlags = lazy(() => import("@/pages/Feature-flag/FeatureFlags")); +const UseFetchHookTest = lazy( + () => import("@/pages/CustomHooks/use-fetch/test"), +); +const UseOnClickOutsideTest = lazy( + () => import("./pages/CustomHooks/use-outside-click/test"), +); +const UseWindowResizeTest = lazy( + () => import("./pages/CustomHooks/use-window-resize/test"), +); +const ScrollToSection = lazy(() => import("./pages/ScrollToSection")); function App() { const [cursorVariant, setCursorVariant] = useState("default"); @@ -46,78 +61,64 @@ function App() {
- - - - {" "} - {" "} - {" "} - - } - /> - - {/* Accordion component */} - } /> - {/* Random color generator */} - } /> - {/* Star Rating */} - } /> - {/* image Slider */} - - } - /> - {/* load more data button */} - } /> - {/* tree view */} - } /> - {/* generate QR code */} - } /> - {/* Light Dark Mode */} - } /> - {/* Custom tabs component */} - } /> - {/* Custom Modal Popup */} - } /> - {/* Github Profile Finder */} - } - /> - {/* Search Auto-Complete */} - } /> - {/* Tic Tac Toe */} - } /> - {/* Feature Flag */} - - - - } - /> - {/* useFetch */} - } /> - {/* useOutsideClick */} - } /> - {/* useWindowResize */} - } /> - {/* scroll to particular section */} - } - /> - - {/* Error Page */} - } /> - - + Loading...}> + + + + + + + } + /> + } /> + } /> + } /> + + } + /> + } /> + } /> + } /> + } /> + } /> + } /> + } + /> + } + /> + } /> + + + + } + /> + } /> + } + /> + } /> + } + /> + } /> + + + ); } diff --git a/src/layouts/header.jsx b/src/layouts/header.jsx index 20226ff..cd97e7f 100644 --- a/src/layouts/header.jsx +++ b/src/layouts/header.jsx @@ -1,3 +1,4 @@ +import { memo } from "react"; // Assets import githubLogoDark from "@/assets/svg/github-mark-white.svg"; import githubLogoLight from "@/assets/svg/github-mark.svg"; @@ -10,22 +11,22 @@ import NavLinks from "@/components/ui/NavLinks"; import { Button } from "@/components/ui/button"; import useWhatTheme from "@/lib/utils"; -function Header({ setCursorVariant }) { +const Header = memo(function Header({ setCursorVariant }) { + const handleMouseEnter = () => setCursorVariant("text"); + const handleMouseLeave = () => setCursorVariant("default"); + const { theme } = useWhatTheme(); return (
- setCursorVariant("text")} - onMouseLeave={() => setCursorVariant("default")} - > + - +
); -} +}); function Logo() { return ( @@ -40,32 +41,26 @@ function Logo() { ); } -function Navigation({ setCursorVariant }) { - const { theme } = useWhatTheme() +const Navigation = ({ setCursorVariant, theme }) => { + const handleMouseEnter = () => setCursorVariant("text"); + const handleMouseLeave = () => setCursorVariant("default"); return ( ); -} +}; function DonateToPalestine() { return ( diff --git a/src/pages/CustomHooks/use-window-resize/test.jsx b/src/pages/CustomHooks/use-window-resize/test.jsx index b1571bf..bbb082d 100644 --- a/src/pages/CustomHooks/use-window-resize/test.jsx +++ b/src/pages/CustomHooks/use-window-resize/test.jsx @@ -1,6 +1,6 @@ import useWindowResize from "./useWindowResize"; -export const UseWindowResizeTest = () => { +const UseWindowResizeTest = () => { const windowSize = useWindowResize(); const { width, height } = windowSize; @@ -20,3 +20,5 @@ export const UseWindowResizeTest = () => { ); }; + +export default UseWindowResizeTest diff --git a/src/pages/CustomModalPopup/ModalPopup.jsx b/src/pages/CustomModalPopup/ModalPopup.jsx index 47dfd24..eabbad4 100644 --- a/src/pages/CustomModalPopup/ModalPopup.jsx +++ b/src/pages/CustomModalPopup/ModalPopup.jsx @@ -2,7 +2,7 @@ import { Button } from "@/components/ui/button"; import { useState } from "react"; import { Modal } from "./Modal"; -export const ModalPopup = () => { +const ModalPopup = () => { const [showModalPopup, setShowModalPopup] = useState(false) function handleToggleModalPopup() { @@ -21,3 +21,5 @@ export const ModalPopup = () => { ); }; + +export default ModalPopup diff --git a/src/pages/Feature-flag/FeatureFlags.jsx b/src/pages/Feature-flag/FeatureFlags.jsx index 6dd4ddc..7592bdd 100644 --- a/src/pages/Feature-flag/FeatureFlags.jsx +++ b/src/pages/Feature-flag/FeatureFlags.jsx @@ -1,42 +1,45 @@ -import RandomColor from "../RandomColor"; -import { TicTacToe } from "../TicTacToe"; -import Accordion from "../accordion/accordion"; -import LightDarkMode from "../light-dark-mode/Light-dark-mode"; -import TreeView from "../tree-view/TreeView"; +import React, { lazy, useContext } from "react"; import { FeatureFlagsContext } from "./context/FeatureFlagsContext"; import menus from "../tree-view/data"; -import TabTest from "../tree-view/custom-tabs/Tab-test"; -import { useContext } from "react"; -export const FeatureFlags = () => { +// Lazy loading components +const LazyLightDarkMode = lazy( + () => import("../light-dark-mode/Light-dark-mode"), +); +const LazyTicTacToe = lazy(() => import("../TicTacToe")); +const LazyRandomColor = lazy(() => import("../RandomColor")); +const LazyAccordion = lazy(() => import("../accordion/accordion")); +const LazyTreeView = lazy(() => import("../tree-view/TreeView")); +const LazyTabTest = lazy(() => import("../tree-view/custom-tabs/Tab-test")); + +export default function FeatureFlags() { const { loading, enabledFlags } = useContext(FeatureFlagsContext); const componentsToRender = [ { key: "showLightAndDarkMode", - component: , + component: , }, - { key: "showTicTacToeBoard", - component: , + component: , }, { key: "showRandomColorGenerator", - component: , + component: , }, { key: "showAccordion", - component: , + component: , }, { key: "showTreeView", - component: , + component: , }, { - key : 'showTabs', - component : - } + key: "showTabs", + component: , + }, ]; function checkEnabledFlags(getCurrentKey) { @@ -47,7 +50,9 @@ export const FeatureFlags = () => { return (
-

Feature Flags

+

+ Feature Flags +

{componentsToRender.map((componentItem) => checkEnabledFlags(componentItem.key) ? componentItem.component : null, )} diff --git a/src/pages/GithubProfileFinder/GithubProfileFinder.jsx b/src/pages/GithubProfileFinder/GithubProfileFinder.jsx index 821dead..80069ea 100644 --- a/src/pages/GithubProfileFinder/GithubProfileFinder.jsx +++ b/src/pages/GithubProfileFinder/GithubProfileFinder.jsx @@ -3,7 +3,7 @@ import { Input } from "@/components/ui/input"; import { useEffect, useState } from "react"; import { User } from "./User"; -export const GithubProfileFinder = () => { +const GithubProfileFinder = () => { const [userName, setUserName] = useState("No0ne003"); const [userData, setUserData] = useState(null); const [loading, setLoading] = useState(false); @@ -54,3 +54,5 @@ export const GithubProfileFinder = () => {
); }; + +export default GithubProfileFinder diff --git a/src/pages/SearchAutoComplete/SearchAutoComplete.jsx b/src/pages/SearchAutoComplete/SearchAutoComplete.jsx index 24eadfb..b476601 100644 --- a/src/pages/SearchAutoComplete/SearchAutoComplete.jsx +++ b/src/pages/SearchAutoComplete/SearchAutoComplete.jsx @@ -2,7 +2,7 @@ import { Input } from "@/components/ui/input"; import { useEffect, useState } from "react"; import { Suggesstions } from "./Suggesstions"; -export const SearchAutoComplete = () => { +const SearchAutoComplete = () => { const [loading, setLoading] = useState(false); const [users, setUsers] = useState([]); const [error, setError] = useState(null); @@ -73,3 +73,5 @@ export const SearchAutoComplete = () => { ); }; + +export default SearchAutoComplete diff --git a/src/pages/TicTacToe.jsx b/src/pages/TicTacToe.jsx index b9615af..1b69747 100644 --- a/src/pages/TicTacToe.jsx +++ b/src/pages/TicTacToe.jsx @@ -1,7 +1,7 @@ import { Button } from "@/components/ui/button"; import { useState } from "react"; -export const TicTacToe = () => { +const TicTacToe = () => { const [squares, setSquares] = useState(Array(9).fill("")); const [isXTurn, setIsXTurn] = useState(true); const [winner, setWinner] = useState(null); @@ -115,3 +115,5 @@ export const Square = ({ value, onClick }) => { ); }; + +export default TicTacToe