diff --git a/src/Components/Info/Info.tsx b/src/Components/Info/Info.tsx index 9469689..6bd1dc6 100644 --- a/src/Components/Info/Info.tsx +++ b/src/Components/Info/Info.tsx @@ -1,7 +1,8 @@ import HeaderLink from '../Ui/HeaderLink' import { InfoProps } from '../../type/InfoProps'; +import Spinner from '../Utils/Loading/Spinner'; -const Info = ({headerText,title,response}:InfoProps) => { +const Info = ({headerText,title,response,isLoading}:InfoProps) => { const {t} = useTranslation(); return ( @@ -12,11 +13,13 @@ const Info = ({headerText,title,response}:InfoProps) => { MDN -
- -

{t(title)}

-

{response}

-
+ {isLoading? : +
+ +

{t(title)}

+

{response}

+
+ } ) } diff --git a/src/Components/about/About.tsx b/src/Components/about/About.tsx index 1b5fe6e..79a8c1f 100644 --- a/src/Components/about/About.tsx +++ b/src/Components/about/About.tsx @@ -9,7 +9,7 @@ const About = ({isHaveHeader = false, data,isLoading}:THeaderPage) => { const {t} = useTranslation(); const aboutData = data?.Static_info[0] - + return (
diff --git a/src/Components/contact/Contact.tsx b/src/Components/contact/Contact.tsx index 75f0f9f..d2f1aaa 100644 --- a/src/Components/contact/Contact.tsx +++ b/src/Components/contact/Contact.tsx @@ -1,6 +1,5 @@ -import { THeaderPage, TPageHeader } from '../../type/app' +import { THeaderPage} from '../../type/app' import HeaderLink from '../Ui/HeaderLink' -import LoadingAntd from '../Utils/Loading/LoadingAntd' import Spinner from '../Utils/Loading/Spinner' import ContactOneSection from './ContactOneSection' diff --git a/src/Hooks/useFetchData.tsx b/src/Hooks/useFetchData.tsx new file mode 100644 index 0000000..fef546a --- /dev/null +++ b/src/Hooks/useFetchData.tsx @@ -0,0 +1,19 @@ +import { useQuery } from 'react-query'; +import { BaseURL } from '../api/config'; + +const fetchData = async (fetchApi:any) => { + const response = await fetch(`${BaseURL}${fetchApi}`); + + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); +}; + +export const useFetchData = (fetchApi:any) => { + return useQuery(['data', fetchApi], () => fetchData(fetchApi), { + refetchOnWindowFocus: false, + staleTime: Infinity, + cacheTime: Infinity, + }); +}; diff --git a/src/Layout/Footer.tsx b/src/Layout/Footer.tsx index e7af0e3..3d012e3 100644 --- a/src/Layout/Footer.tsx +++ b/src/Layout/Footer.tsx @@ -3,17 +3,19 @@ import SingleLink from '../Components/Ui/SingleLink'; import { HomelinksArray, QuicklinksArray, ServicelinksArray } from '../data/Links'; import FooterTItleWithSeparator from '../Components/Ui/FooterTItleWithSeperator'; import ContactInfo from '../Components/Ui/ContactInfo'; -import { useGetHome } from '../api/home'; import { BaseURL_IMAGE } from '../api/config'; +import { THeaderPage } from '../type/app'; +import Spinner from '../Components/Utils/Loading/Spinner'; -const Footer = () => { +const Footer = ({data, isLoading}:THeaderPage) => { const { t } = useTranslation(); - const {data} = useGetHome(); const mediaArray = data?.Social_media const contactNumber = data?.Static_info[3] const contactEmail = data?.Static_info[4] const Logo = data?.Static_info[5] - + if (isLoading){ + return + } return (
footer_image diff --git a/src/Layout/app/Header.tsx b/src/Layout/app/Header.tsx index d01ff31..d313c4c 100644 --- a/src/Layout/app/Header.tsx +++ b/src/Layout/app/Header.tsx @@ -1,21 +1,24 @@ import { HedaerLinksArray } from '../../data/HeaderLinks' import AnimationButton from '../../Components/Ui/AnimationButton'; import HeaderMenu from './HeaderMenu'; -import { useGetHome } from '../../api/home'; import { BaseURL_IMAGE } from '../../api/config'; +import { THeaderPage } from '../../type/app'; +import Spinner from '../../Components/Utils/Loading/Spinner'; -const Header = () => { - const {data} = useGetHome(); +const Header = ({data, isLoading}:THeaderPage) => { const Logo = data?.Static_info[5] return (
+ { isLoading ? : Misbar Logo + }
{ + isLoading ? : HedaerLinksArray.map((link,index) => (

{link.name}

)) @@ -25,7 +28,7 @@ const Header = () => { }/>
- +
) } diff --git a/src/Layout/app/HeaderMenu.tsx b/src/Layout/app/HeaderMenu.tsx index a30ee76..7e658c4 100644 --- a/src/Layout/app/HeaderMenu.tsx +++ b/src/Layout/app/HeaderMenu.tsx @@ -3,8 +3,13 @@ import { Button } from 'antd'; import { MenuOutlined } from '@ant-design/icons'; import { HedaerLinksArray } from '../../data/HeaderLinks'; import DrawerLink from '../../Components/Ui/DrawerLink'; +import { THeaderPage } from '../../type/app'; +import { BaseURL_IMAGE } from '../../api/config'; +import Spinner from '../../Components/Utils/Loading/Spinner'; + +const HeaderMenu = ({data, isLoading}:THeaderPage) => { + const Logo = data?.Static_info[5] -const HeaderMenu = () => { return (
{ {({ closeDrawer }) => ( <>
- logo + { isLoading ? : + Misbar Logo + }
    {HedaerLinksArray.map((drawerLink, index) => ( diff --git a/src/Layout/app/Layout.tsx b/src/Layout/app/Layout.tsx index eab34a7..6d1bf68 100644 --- a/src/Layout/app/Layout.tsx +++ b/src/Layout/app/Layout.tsx @@ -1,17 +1,17 @@ import React from 'react'; import Header from './Header'; import Footer from '../Footer'; +import { useFetchData } from '../../Hooks/useFetchData'; const Layout = (({ children, className = "" }: { children: React.ReactNode, className?: string }) => { - - + const { data, isLoading } = useFetchData('api/home'); return (
    -
    +
    {children}
    -
    +
    ); }); diff --git a/src/Pages/About/Page.tsx b/src/Pages/About/Page.tsx index 3f86d54..1c582c9 100644 --- a/src/Pages/About/Page.tsx +++ b/src/Pages/About/Page.tsx @@ -1,11 +1,12 @@ import About from '../../Components/about/About' -import { useGetHome } from '../../api/home'; +import { useFetchData } from '../../Hooks/useFetchData'; const AboutUS = () => { - const {data} = useGetHome(); + const { data, isLoading } = useFetchData('api/home'); + return ( <> - + ) } diff --git a/src/Pages/Contact/Page.tsx b/src/Pages/Contact/Page.tsx index 4823595..0e26e6f 100644 --- a/src/Pages/Contact/Page.tsx +++ b/src/Pages/Contact/Page.tsx @@ -1,12 +1,12 @@ import Contact from "../../Components/contact/Contact" -import { useGetHome } from "../../api/home" +import { useFetchData } from "../../Hooks/useFetchData"; const Page = () => { - const {data} = useGetHome(); - + const { data, isLoading } = useFetchData('api/home'); + return (
    - +
    ) } diff --git a/src/Pages/Home/Page.tsx b/src/Pages/Home/Page.tsx index 65d5f6a..6f89527 100644 --- a/src/Pages/Home/Page.tsx +++ b/src/Pages/Home/Page.tsx @@ -4,17 +4,16 @@ import Service from "../../Components/Service/Service"; import Works from "../../Components/Works/Works"; import About from "../../Components/about/About"; import Contact from "../../Components/contact/Contact"; -import { useGetHome } from "../../api/home"; +import { useFetchData } from "../../Hooks/useFetchData"; const Page = () => { - const {data,isLoading} = useGetHome() - console.log(data); + const { data, isLoading } = useFetchData('api/home'); - return ( + return ( <> - - + + diff --git a/src/Pages/Privacy/Page.tsx b/src/Pages/Privacy/Page.tsx index 7bca360..afec429 100644 --- a/src/Pages/Privacy/Page.tsx +++ b/src/Pages/Privacy/Page.tsx @@ -1,18 +1,17 @@ import Info from "../../Components/Info/Info" -import { useGetHome } from "../../api/home"; -import { PrivacyData } from "../../data/Info" +import { useFetchData } from "../../Hooks/useFetchData"; const Page = () => { - const {data} = useGetHome(); - console.log(data?.Static_info); - + const { data, isLoading } = useFetchData('api/home'); + const privacyData = data?.Static_info[2]; return ( - + ) } diff --git a/src/Pages/Projects/Page.tsx b/src/Pages/Projects/Page.tsx index f422fc9..e8035ee 100644 --- a/src/Pages/Projects/Page.tsx +++ b/src/Pages/Projects/Page.tsx @@ -1,16 +1,14 @@ import { IoIosArrowDroprightCircle } from "react-icons/io"; import AnimationButton from "../../Components/Ui/AnimationButton"; import HeaderLink from "../../Components/Ui/HeaderLink" -import { ProjectsArray } from "../../data/Projects"; import ProjectCard from "../../Components/Projects/ProjectCard"; -import { useGetProject } from "../../api/project"; import Spinner from "../../Components/Utils/Loading/Spinner"; +import { useFetchData } from "../../Hooks/useFetchData"; const Page = () => { const {t} = useTranslation(); - const {data ,isLoading} = useGetProject(); - console.log(data); - // const projectData = data?. + const { data, isLoading} = useFetchData('api/project'); + return (
    diff --git a/src/Pages/Services/Page.tsx b/src/Pages/Services/Page.tsx index 0cde1d6..a9da5f3 100644 --- a/src/Pages/Services/Page.tsx +++ b/src/Pages/Services/Page.tsx @@ -1,12 +1,13 @@ import Service from '../../Components/Service/Service' +import { useFetchData } from '../../Hooks/useFetchData'; import { useGetHome } from '../../api/home'; const Services = () => { - const {data} = useGetHome(); + const { data, isLoading } = useFetchData('api/home'); return ( <> - + ) } diff --git a/src/Pages/SingleProject/Page.tsx b/src/Pages/SingleProject/Page.tsx index 5c56936..c703372 100644 --- a/src/Pages/SingleProject/Page.tsx +++ b/src/Pages/SingleProject/Page.tsx @@ -3,16 +3,16 @@ import { useParams } from 'react-router-dom'; import { IoIosArrowDroprightCircle } from "react-icons/io"; import AnimationButton from "../../Components/Ui/AnimationButton"; import HeaderLink from "../../Components/Ui/HeaderLink"; -import { useGetProject } from '../../api/project'; import { BaseURL_IMAGE } from '../../api/config'; import Spinner from '../../Components/Utils/Loading/Spinner'; import ReactPlayer from 'react-player'; +import { useFetchData } from '../../Hooks/useFetchData'; const SingleProjectPage = () => { const { id } = useParams<{ id: string }>(); - const { data, isLoading } = useGetProject(); + const { data, isLoading} = useFetchData('api/project'); + const [playing, setPlaying] = useState(false); - const project = data?.find((p: { id: { toString: () => string | undefined; }; }) => p.id.toString() === id); const handlePlayPause = () => { diff --git a/src/Pages/Terms/Page.tsx b/src/Pages/Terms/Page.tsx index 867fd14..40f5141 100644 --- a/src/Pages/Terms/Page.tsx +++ b/src/Pages/Terms/Page.tsx @@ -1,15 +1,16 @@ import Info from "../../Components/Info/Info" -import { useGetHome } from "../../api/home"; +import { useFetchData } from "../../Hooks/useFetchData"; const Page = () => { - const {data} = useGetHome(); - + const { data, isLoading } = useFetchData('api/home'); + const TermsData = data?.Static_info[1]; return ( - ) } diff --git a/src/api/home.ts b/src/api/home.ts index 1dc79ba..5f11cc3 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -1,7 +1,7 @@ import useGetQuery from "./helper/useGetQuery" const API = { - GET:"/api/home", + GET:"api/home", } const KEY = "Home" diff --git a/src/api/project.ts b/src/api/project.ts index 51b7a4d..bc21bda 100644 --- a/src/api/project.ts +++ b/src/api/project.ts @@ -1,7 +1,7 @@ import useGetQuery from "./helper/useGetQuery" const API = { - GET:"/api/project", + GET:"api/project", } const KEY = "PROJECT" diff --git a/src/lib/ReactQueryProvider.tsx b/src/lib/ReactQueryProvider.tsx index 72e68d4..7989b53 100644 --- a/src/lib/ReactQueryProvider.tsx +++ b/src/lib/ReactQueryProvider.tsx @@ -3,7 +3,15 @@ import { QueryClient, QueryClientProvider } from 'react-query' function QueryProvider({ children }: any) { - const queryClient = new QueryClient() + const queryClient = new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus:false, + cacheTime:Infinity, + staleTime: Infinity, + }, + }, + }) return ( diff --git a/src/type/InfoProps.ts b/src/type/InfoProps.ts index b914747..162bf7b 100644 --- a/src/type/InfoProps.ts +++ b/src/type/InfoProps.ts @@ -2,4 +2,5 @@ export interface InfoProps{ headerText:string, title:string, response:string, + isLoading:boolean } \ No newline at end of file