react-typescript-chess-fede.../src/pages/AboutUs.tsx

206 lines
6.8 KiB
TypeScript
Raw Normal View History

2022-07-27 15:55:46 +00:00
// Modules
import React, { useState, useEffect } from "react";
import Skeleton from "react-loading-skeleton";
2022-08-20 14:06:03 +00:00
import { ErrorBoundary } from "react-error-boundary";
2022-07-27 15:55:46 +00:00
// Helpers
2022-08-03 19:34:07 +00:00
import { getAbout, getVideos } from "../helpers/apiRequests";
2022-07-27 15:55:46 +00:00
import { highlightColor } from "../helpers/otherVariables";
import { hosting } from "../links";
2022-08-15 08:51:56 +00:00
// Hooks
import useMediaQuery from "../hooks/useMediaQuery";
2022-07-29 10:20:28 +00:00
// Components
import Statistic from "../components/about_us/Statistic";
2022-08-03 19:34:07 +00:00
import VideoPlayer from "../components/global/VideoPlayer";
import SectionTitle from "../components/global/SectionTitle";
import TeamSlider from "../components/about_us/TeamSlider";
2022-08-20 14:06:03 +00:00
import EmptyState from "../components/global/EmptyState";
2022-07-29 10:20:28 +00:00
2022-08-19 18:17:50 +00:00
// Types
import { Video } from "../types/video";
2022-08-19 18:27:45 +00:00
import { About } from "../types/about";
2022-08-19 18:17:50 +00:00
2022-07-27 15:55:46 +00:00
const AboutUs = () => {
2022-08-19 18:27:45 +00:00
const [about, setAbout]: [About, React.Dispatch<About>] = useState({
id: -1,
header: "",
txt: "",
img: "",
tournment_title: "",
tournment_number: -1,
organisation_title: "",
organisation_number: -1,
graduate_title: "",
graduate_number: -1,
places_title: "",
places_number: -1,
translation: [{ model_id: "", locale: "", attribute_date: "" }],
});
2022-08-19 18:17:50 +00:00
const [video, setVideo]: [Video[], React.Dispatch<Video[]>] = useState([
{
id: -1,
video: "",
poster: "",
},
]);
2022-07-27 15:55:46 +00:00
useEffect(() => {
window.scrollTo(0, 0);
getAbout(setAbout);
2022-08-19 18:17:50 +00:00
getVideos(setVideo, () => null);
2022-07-27 15:55:46 +00:00
}, []);
2022-08-15 08:51:56 +00:00
const breakpoint = useMediaQuery("(max-width: 500px)");
2022-07-27 15:55:46 +00:00
return (
2022-08-20 14:06:03 +00:00
<ErrorBoundary fallback={<EmptyState page={true} />}>
<main className="about-us">
<div className="container">
<div className="about-us-inner">
<div className="about-us-top">
<div className="aut-left">
{about.id !== -1 ? (
<h2>{about.header}</h2>
) : (
2022-07-29 10:20:28 +00:00
<Skeleton
highlightColor={highlightColor}
2022-08-20 14:06:03 +00:00
height={"5.4rem"}
width={"45%"}
2022-07-29 10:20:28 +00:00
/>
2022-08-20 14:06:03 +00:00
)}
{about.id !== -1 ? (
<p>{about.txt}</p>
) : (
2022-07-29 10:20:28 +00:00
<Skeleton
highlightColor={highlightColor}
2022-08-20 14:06:03 +00:00
height={"1.4rem"}
width={"100%"}
count={12}
2022-07-29 10:20:28 +00:00
/>
2022-08-20 14:06:03 +00:00
)}
</div>
<div className="aut-right">
{about.id !== -1 ? (
<div>
<img
src={hosting + "/storage/app/media" + about.img}
alt=""
/>
</div>
) : (
<Skeleton height={"49.8rem"} />
)}
</div>
</div>
<div className="about-us-middle">
{about.id !== -1 ? (
<div className="aub-wrapper">
<Statistic
count={about.tournment_number}
title={about.tournment_title}
2022-07-29 10:20:28 +00:00
/>
2022-08-20 14:06:03 +00:00
<Statistic
count={about.organisation_number}
title={about.organisation_title}
2022-07-29 10:20:28 +00:00
/>
2022-08-20 14:06:03 +00:00
<Statistic
count={about.graduate_number}
title={about.graduate_title}
2022-07-29 10:20:28 +00:00
/>
2022-08-20 14:06:03 +00:00
<Statistic
count={about.places_number}
title={about.places_title}
2022-07-29 10:20:28 +00:00
/>
</div>
2022-08-20 14:06:03 +00:00
) : (
<div className="group-skeleton">
<div className="group">
<Skeleton
className="fchild"
highlightColor={highlightColor}
width={"13.5rem"}
height={"13.5rem"}
style={{ borderRadius: "0.5rem" }}
/>
<Skeleton
highlightColor={highlightColor}
height={"2.14rem"}
width={breakpoint ? "13rem" : "18rem"}
count={2}
/>
</div>
<div className="group">
<Skeleton
className="fchild"
highlightColor={highlightColor}
width={"13.5rem"}
height={"13.5rem"}
style={{ borderRadius: "0.5rem" }}
/>
<Skeleton
highlightColor={highlightColor}
height={"2.14rem"}
width={breakpoint ? "13rem" : "18rem"}
count={2}
/>
</div>
<div className="group">
<Skeleton
className="fchild"
highlightColor={highlightColor}
width={"13.5rem"}
height={"13.5rem"}
style={{ borderRadius: "0.5rem" }}
/>
<Skeleton
highlightColor={highlightColor}
height={"2.14rem"}
width={breakpoint ? "13rem" : "18rem"}
count={2}
/>
</div>
<div className="group">
<Skeleton
className="fchild"
highlightColor={highlightColor}
width={"13.5rem"}
height={"13.5rem"}
style={{ borderRadius: "0.5rem" }}
/>
<Skeleton
highlightColor={highlightColor}
height={"2.14rem"}
width={breakpoint ? "13rem" : "18rem"}
count={2}
/>
</div>
2022-07-29 10:20:28 +00:00
</div>
2022-08-20 14:06:03 +00:00
)}
</div>
<div className="about-us-slider">
<SectionTitle title="Сборная Туркменистана" />
<ErrorBoundary fallback={<EmptyState />}>
<TeamSlider />
</ErrorBoundary>
</div>
<div className="about-us-video">
<SectionTitle title="Вводный видео ролик" />
{video[0].id !== -1 ? (
<ErrorBoundary fallback={<EmptyState />}>
<VideoPlayer videoUrl={video[0].video} />
</ErrorBoundary>
) : (
<Skeleton highlightColor={highlightColor} height={"40rem"} />
)}
</div>
2022-08-03 19:34:07 +00:00
</div>
2022-07-27 15:55:46 +00:00
</div>
2022-08-20 14:06:03 +00:00
</main>
</ErrorBoundary>
2022-07-27 15:55:46 +00:00
);
};
export default AboutUs;