cach response hook for all project
This commit is contained in:
parent
d49b1c46e1
commit
2fb9a217c2
|
|
@ -1,7 +1,8 @@
|
||||||
import HeaderLink from '../Ui/HeaderLink'
|
import HeaderLink from '../Ui/HeaderLink'
|
||||||
import { InfoProps } from '../../type/InfoProps';
|
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();
|
const {t} = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -12,11 +13,13 @@ const Info = ({headerText,title,response}:InfoProps) => {
|
||||||
<img className="info_image" src="/App/WhiteBg.png" alt="MDN" />
|
<img className="info_image" src="/App/WhiteBg.png" alt="MDN" />
|
||||||
</picture>
|
</picture>
|
||||||
|
|
||||||
<div className="info_content">
|
{isLoading? <Spinner/> :
|
||||||
<HeaderLink text={headerText}/>
|
<div className="info_content">
|
||||||
<h1>{t(title)}</h1>
|
<HeaderLink text={headerText}/>
|
||||||
<p>{response}</p>
|
<h1>{t(title)}</h1>
|
||||||
</div>
|
<p>{response}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { THeaderPage, TPageHeader } from '../../type/app'
|
import { THeaderPage} from '../../type/app'
|
||||||
import HeaderLink from '../Ui/HeaderLink'
|
import HeaderLink from '../Ui/HeaderLink'
|
||||||
import LoadingAntd from '../Utils/Loading/LoadingAntd'
|
|
||||||
import Spinner from '../Utils/Loading/Spinner'
|
import Spinner from '../Utils/Loading/Spinner'
|
||||||
import ContactOneSection from './ContactOneSection'
|
import ContactOneSection from './ContactOneSection'
|
||||||
|
|
||||||
|
|
|
||||||
19
src/Hooks/useFetchData.tsx
Normal file
19
src/Hooks/useFetchData.tsx
Normal file
|
|
@ -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,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -3,17 +3,19 @@ import SingleLink from '../Components/Ui/SingleLink';
|
||||||
import { HomelinksArray, QuicklinksArray, ServicelinksArray } from '../data/Links';
|
import { HomelinksArray, QuicklinksArray, ServicelinksArray } from '../data/Links';
|
||||||
import FooterTItleWithSeparator from '../Components/Ui/FooterTItleWithSeperator';
|
import FooterTItleWithSeparator from '../Components/Ui/FooterTItleWithSeperator';
|
||||||
import ContactInfo from '../Components/Ui/ContactInfo';
|
import ContactInfo from '../Components/Ui/ContactInfo';
|
||||||
import { useGetHome } from '../api/home';
|
|
||||||
import { BaseURL_IMAGE } from '../api/config';
|
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 { t } = useTranslation();
|
||||||
const {data} = useGetHome();
|
|
||||||
const mediaArray = data?.Social_media
|
const mediaArray = data?.Social_media
|
||||||
const contactNumber = data?.Static_info[3]
|
const contactNumber = data?.Static_info[3]
|
||||||
const contactEmail = data?.Static_info[4]
|
const contactEmail = data?.Static_info[4]
|
||||||
const Logo = data?.Static_info[5]
|
const Logo = data?.Static_info[5]
|
||||||
|
if (isLoading){
|
||||||
|
return <Spinner/>
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className='footer_contianer'>
|
<div className='footer_contianer'>
|
||||||
<img className='footer_image' src="/Layout/FooterImage.png" alt="footer_image" />
|
<img className='footer_image' src="/Layout/FooterImage.png" alt="footer_image" />
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
import { HedaerLinksArray } from '../../data/HeaderLinks'
|
import { HedaerLinksArray } from '../../data/HeaderLinks'
|
||||||
import AnimationButton from '../../Components/Ui/AnimationButton';
|
import AnimationButton from '../../Components/Ui/AnimationButton';
|
||||||
import HeaderMenu from './HeaderMenu';
|
import HeaderMenu from './HeaderMenu';
|
||||||
import { useGetHome } from '../../api/home';
|
|
||||||
import { BaseURL_IMAGE } from '../../api/config';
|
import { BaseURL_IMAGE } from '../../api/config';
|
||||||
|
import { THeaderPage } from '../../type/app';
|
||||||
|
import Spinner from '../../Components/Utils/Loading/Spinner';
|
||||||
|
|
||||||
const Header = () => {
|
const Header = ({data, isLoading}:THeaderPage) => {
|
||||||
const {data} = useGetHome();
|
|
||||||
const Logo = data?.Static_info[5]
|
const Logo = data?.Static_info[5]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='header_container'>
|
<div className='header_container'>
|
||||||
|
|
||||||
<div className='image_container'>
|
<div className='image_container'>
|
||||||
|
{ isLoading ? <Spinner/> :
|
||||||
<img src={BaseURL_IMAGE + Logo?.value} alt='Misbar Logo' width={65}/>
|
<img src={BaseURL_IMAGE + Logo?.value} alt='Misbar Logo' width={65}/>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<div className='Header_links'>
|
<div className='Header_links'>
|
||||||
{
|
{
|
||||||
|
isLoading ? <Spinner/> :
|
||||||
HedaerLinksArray.map((link,index) => (
|
HedaerLinksArray.map((link,index) => (
|
||||||
<Link style={link.isOnlyDrawer ? {display:"none"}:{display:"flex"}} key={index} to={link.href} className='Link'><h4>{link.name}</h4></Link>
|
<Link style={link.isOnlyDrawer ? {display:"none"}:{display:"flex"}} key={index} to={link.href} className='Link'><h4>{link.name}</h4></Link>
|
||||||
))
|
))
|
||||||
|
|
@ -25,7 +28,7 @@ const Header = () => {
|
||||||
<AnimationButton link='/contact' text='Contact Us Now' icon={<FaTelegram/>}/>
|
<AnimationButton link='/contact' text='Contact Us Now' icon={<FaTelegram/>}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<HeaderMenu/>
|
<HeaderMenu data={data} isLoading={isLoading}/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,13 @@ import { Button } from 'antd';
|
||||||
import { MenuOutlined } from '@ant-design/icons';
|
import { MenuOutlined } from '@ant-design/icons';
|
||||||
import { HedaerLinksArray } from '../../data/HeaderLinks';
|
import { HedaerLinksArray } from '../../data/HeaderLinks';
|
||||||
import DrawerLink from '../../Components/Ui/DrawerLink';
|
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 (
|
return (
|
||||||
<div className='menu_nav'>
|
<div className='menu_nav'>
|
||||||
<WithDrawer
|
<WithDrawer
|
||||||
|
|
@ -14,7 +19,9 @@ const HeaderMenu = () => {
|
||||||
{({ closeDrawer }) => (
|
{({ closeDrawer }) => (
|
||||||
<>
|
<>
|
||||||
<div className='header_logo'>
|
<div className='header_logo'>
|
||||||
<img src='./Logo/MisbarLogo.png' alt='logo' className='logo_drawer' />
|
{ isLoading ? <Spinner/> :
|
||||||
|
<img src={BaseURL_IMAGE + Logo?.value} alt='Misbar Logo' width={65}/>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<ul className='DrawerLinks'>
|
<ul className='DrawerLinks'>
|
||||||
{HedaerLinksArray.map((drawerLink, index) => (
|
{HedaerLinksArray.map((drawerLink, index) => (
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import Footer from '../Footer';
|
import Footer from '../Footer';
|
||||||
|
import { useFetchData } from '../../Hooks/useFetchData';
|
||||||
|
|
||||||
const Layout = (({ children, className = "" }: { children: React.ReactNode, className?: string }) => {
|
const Layout = (({ children, className = "" }: { children: React.ReactNode, className?: string }) => {
|
||||||
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='Layout'>
|
<div className='Layout'>
|
||||||
<Header />
|
<Header data={data} isLoading={isLoading} />
|
||||||
<main className={`${className} Layout_Body`}>
|
<main className={`${className} Layout_Body`}>
|
||||||
{children}
|
{children}
|
||||||
</main>
|
</main>
|
||||||
<Footer />
|
<Footer data={data} isLoading={isLoading}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import About from '../../Components/about/About'
|
import About from '../../Components/about/About'
|
||||||
import { useGetHome } from '../../api/home';
|
import { useFetchData } from '../../Hooks/useFetchData';
|
||||||
|
|
||||||
const AboutUS = () => {
|
const AboutUS = () => {
|
||||||
const {data} = useGetHome();
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<About data={data} isHaveHeader={true} />
|
<About data={data} isHaveHeader={true} isLoading={isLoading} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import Contact from "../../Components/contact/Contact"
|
import Contact from "../../Components/contact/Contact"
|
||||||
import { useGetHome } from "../../api/home"
|
import { useFetchData } from "../../Hooks/useFetchData";
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const {data} = useGetHome();
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='contact_container'>
|
<div className='contact_container'>
|
||||||
<Contact data={data} isHaveHeader={true}/>
|
<Contact isLoading={isLoading} data={data} isHaveHeader={true} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,16 @@ import Service from "../../Components/Service/Service";
|
||||||
import Works from "../../Components/Works/Works";
|
import Works from "../../Components/Works/Works";
|
||||||
import About from "../../Components/about/About";
|
import About from "../../Components/about/About";
|
||||||
import Contact from "../../Components/contact/Contact";
|
import Contact from "../../Components/contact/Contact";
|
||||||
import { useGetHome } from "../../api/home";
|
import { useFetchData } from "../../Hooks/useFetchData";
|
||||||
|
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const {data,isLoading} = useGetHome()
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HeroSection data={data} isLoading={isLoading}/>
|
<HeroSection data={data} isLoading={isLoading} />
|
||||||
<About isHaveHeader={false} data={data} isLoading={isLoading} />
|
<About isHaveHeader={false} data={data} isLoading={isLoading} />
|
||||||
<Service data={data} isHaveHeader={false} isLoading={isLoading} />
|
<Service data={data} isHaveHeader={false} isLoading={isLoading} />
|
||||||
<Works data={data} isLoading={isLoading} />
|
<Works data={data} isLoading={isLoading} />
|
||||||
<Contact data={data} isHaveHeader={false} isLoading={isLoading} />
|
<Contact data={data} isHaveHeader={false} isLoading={isLoading} />
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
import Info from "../../Components/Info/Info"
|
import Info from "../../Components/Info/Info"
|
||||||
import { useGetHome } from "../../api/home";
|
import { useFetchData } from "../../Hooks/useFetchData";
|
||||||
import { PrivacyData } from "../../data/Info"
|
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const {data} = useGetHome();
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
console.log(data?.Static_info);
|
|
||||||
|
|
||||||
const privacyData = data?.Static_info[2];
|
const privacyData = data?.Static_info[2];
|
||||||
return (
|
return (
|
||||||
<Info
|
<Info
|
||||||
headerText="Privacy Policy"
|
headerText="Privacy Policy"
|
||||||
title={privacyData?.key}
|
title={privacyData?.key}
|
||||||
response={privacyData?.value}
|
response={privacyData?.value}
|
||||||
/>
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
import { IoIosArrowDroprightCircle } from "react-icons/io";
|
import { IoIosArrowDroprightCircle } from "react-icons/io";
|
||||||
import AnimationButton from "../../Components/Ui/AnimationButton";
|
import AnimationButton from "../../Components/Ui/AnimationButton";
|
||||||
import HeaderLink from "../../Components/Ui/HeaderLink"
|
import HeaderLink from "../../Components/Ui/HeaderLink"
|
||||||
import { ProjectsArray } from "../../data/Projects";
|
|
||||||
import ProjectCard from "../../Components/Projects/ProjectCard";
|
import ProjectCard from "../../Components/Projects/ProjectCard";
|
||||||
import { useGetProject } from "../../api/project";
|
|
||||||
import Spinner from "../../Components/Utils/Loading/Spinner";
|
import Spinner from "../../Components/Utils/Loading/Spinner";
|
||||||
|
import { useFetchData } from "../../Hooks/useFetchData";
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
const {data ,isLoading} = useGetProject();
|
const { data, isLoading} = useFetchData('api/project');
|
||||||
console.log(data);
|
|
||||||
// const projectData = data?.
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="projects">
|
<div className="projects">
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
import Service from '../../Components/Service/Service'
|
import Service from '../../Components/Service/Service'
|
||||||
|
import { useFetchData } from '../../Hooks/useFetchData';
|
||||||
import { useGetHome } from '../../api/home';
|
import { useGetHome } from '../../api/home';
|
||||||
|
|
||||||
const Services = () => {
|
const Services = () => {
|
||||||
const {data} = useGetHome();
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Service data={data} isHaveHeader={true}/>
|
<Service isLoading={isLoading} data={data} isHaveHeader={true} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ import { useParams } from 'react-router-dom';
|
||||||
import { IoIosArrowDroprightCircle } from "react-icons/io";
|
import { IoIosArrowDroprightCircle } from "react-icons/io";
|
||||||
import AnimationButton from "../../Components/Ui/AnimationButton";
|
import AnimationButton from "../../Components/Ui/AnimationButton";
|
||||||
import HeaderLink from "../../Components/Ui/HeaderLink";
|
import HeaderLink from "../../Components/Ui/HeaderLink";
|
||||||
import { useGetProject } from '../../api/project';
|
|
||||||
import { BaseURL_IMAGE } from '../../api/config';
|
import { BaseURL_IMAGE } from '../../api/config';
|
||||||
import Spinner from '../../Components/Utils/Loading/Spinner';
|
import Spinner from '../../Components/Utils/Loading/Spinner';
|
||||||
import ReactPlayer from 'react-player';
|
import ReactPlayer from 'react-player';
|
||||||
|
import { useFetchData } from '../../Hooks/useFetchData';
|
||||||
|
|
||||||
const SingleProjectPage = () => {
|
const SingleProjectPage = () => {
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
const { data, isLoading } = useGetProject();
|
const { data, isLoading} = useFetchData('api/project');
|
||||||
const [playing, setPlaying] = useState(false);
|
|
||||||
|
|
||||||
|
const [playing, setPlaying] = useState(false);
|
||||||
const project = data?.find((p: { id: { toString: () => string | undefined; }; }) => p.id.toString() === id);
|
const project = data?.find((p: { id: { toString: () => string | undefined; }; }) => p.id.toString() === id);
|
||||||
|
|
||||||
const handlePlayPause = () => {
|
const handlePlayPause = () => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import Info from "../../Components/Info/Info"
|
import Info from "../../Components/Info/Info"
|
||||||
import { useGetHome } from "../../api/home";
|
import { useFetchData } from "../../Hooks/useFetchData";
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const {data} = useGetHome();
|
const { data, isLoading } = useFetchData('api/home');
|
||||||
|
|
||||||
const TermsData = data?.Static_info[1];
|
const TermsData = data?.Static_info[1];
|
||||||
return (
|
return (
|
||||||
|
|
@ -10,6 +10,7 @@ const Page = () => {
|
||||||
headerText="Terms & Conditions"
|
headerText="Terms & Conditions"
|
||||||
title={TermsData?.key}
|
title={TermsData?.key}
|
||||||
response={TermsData?.value}
|
response={TermsData?.value}
|
||||||
|
isLoading={isLoading}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import useGetQuery from "./helper/useGetQuery"
|
import useGetQuery from "./helper/useGetQuery"
|
||||||
|
|
||||||
const API = {
|
const API = {
|
||||||
GET:"/api/home",
|
GET:"api/home",
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY = "Home"
|
const KEY = "Home"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import useGetQuery from "./helper/useGetQuery"
|
import useGetQuery from "./helper/useGetQuery"
|
||||||
|
|
||||||
const API = {
|
const API = {
|
||||||
GET:"/api/project",
|
GET:"api/project",
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY = "PROJECT"
|
const KEY = "PROJECT"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,15 @@ import { QueryClient, QueryClientProvider } from 'react-query'
|
||||||
|
|
||||||
function QueryProvider({ children }: any) {
|
function QueryProvider({ children }: any) {
|
||||||
|
|
||||||
const queryClient = new QueryClient()
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
refetchOnWindowFocus:false,
|
||||||
|
cacheTime:Infinity,
|
||||||
|
staleTime: Infinity,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@ export interface InfoProps{
|
||||||
headerText:string,
|
headerText:string,
|
||||||
title:string,
|
title:string,
|
||||||
response:string,
|
response:string,
|
||||||
|
isLoading:boolean
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user