diff --git a/src/Api/tournaments.json b/src/Api/tournaments.json index 6cf721c..ec604f9 100644 --- a/src/Api/tournaments.json +++ b/src/Api/tournaments.json @@ -55,9 +55,9 @@ "date": "2023-07-16", "players": [ { "member_id": "39", "win": 2, "defeat": 3, "position": 3 }, - { "member_id": "57", "win": 0, "defeat": 3, "position": 1 }, + { "member_id": "57", "win": 0, "defeat": 3, "position": 4 }, { "member_id": "5", "win": 0, "defeat": 3, "position": 4 }, - { "member_id": "85", "win": 5, "defeat": 0, "position": 4 }, + { "member_id": "85", "win": 5, "defeat": 0, "position": 1 }, { "member_id": "76", "win": 4, "defeat": 2, "position": 2 } ] }, @@ -182,6 +182,16 @@ { "member_id": "11", "win": 5, "defeat": 1, "position": 2 }, { "member_id": "1", "win": 3, "defeat": 3, "position": 3 } ] + }, + { + "date": "2024-05-19", + "players": [ + { "member_id": "30", "win": 0, "defeat": 8, "position": 5 }, + { "member_id": "85", "win": 5, "defeat": 6, "position": 4 }, + { "member_id": "76", "win": 6, "defeat": 3, "position": 2 }, + { "member_id": "57", "win": 6, "defeat": 4, "position": 3 }, + { "member_id": "1", "win": 7, "defeat": 3, "position": 1 } + ] } ] } diff --git a/src/App.js b/src/App.js index 297eecf..b81c439 100644 --- a/src/App.js +++ b/src/App.js @@ -18,11 +18,9 @@ function App() { }> } />F - } /> } /> } /> - }> } /> diff --git a/src/Layout/Layout.jsx b/src/Layout/Layout.jsx index a5be209..d0fca78 100644 --- a/src/Layout/Layout.jsx +++ b/src/Layout/Layout.jsx @@ -4,8 +4,32 @@ import { Footer } from "../components/Footer/Footer"; import { ScrollToTopButton } from "../components/ScrollToTopButton/ScrollToTopButton"; import { ContactsSection } from "../components/ContactsSection/ContactsSection"; import { LastUpdateSection } from "../components/LastUpdateSection/LastUpdateSection"; +import { useEffect } from "react"; +import { useStateContext } from "../state/stateContext"; +import { membersApi, photosApi, tournamentsApi } from "../Api/ApiRequest"; const Layout = () => { + const { setGlobalState } = useStateContext(); + + useEffect(() => { + const members = membersApi(); + members?.sort((a, b) => a.name.localeCompare(b.name)); + + const tournaments = tournamentsApi(); + tournaments?.sort((a, b) => a.name.localeCompare(b.name)); + + const photos = photosApi(); + photos?.sort((a, b) => b.date.localeCompare(a.date)); + + setGlobalState((prev) => ({ + ...prev, + members, + tournaments, + photos, + })); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return ( <> diff --git a/src/components/ImageGallery/ImageGalleryModal.jsx b/src/components/ImageGallery/ImageGalleryModal.jsx index 44725ed..f0b12dc 100644 --- a/src/components/ImageGallery/ImageGalleryModal.jsx +++ b/src/components/ImageGallery/ImageGalleryModal.jsx @@ -14,9 +14,12 @@ import sprite from "../../sprite.svg"; import { Loader } from "../Loaders/Loaders"; import { Modal } from "../Modal/Modal"; import { Portal } from "../../Routes/Portal/Portal"; -import { photosApi } from "../../Api/ApiRequest"; +import { useStateContext } from "../../state/stateContext"; export const ImageGalleryModal = () => { + const { globalState } = useStateContext(); + const { photos } = globalState; + const { id } = useParams(); const navigate = useNavigate(); @@ -39,9 +42,7 @@ export const ImageGalleryModal = () => { setScrollPosition(rect.y - window.innerHeight / 2 + 100); } - const gallery = photosApi(); - const orderedGallery = - order === "newest" ? gallery : [...gallery].reverse(); + const orderedGallery = order === "newest" ? photos : [...photos].reverse(); setGalleryArray(orderedGallery); const current = orderedGallery.find((el) => String(el.id) === String(id)); @@ -52,7 +53,7 @@ export const ImageGalleryModal = () => { document.documentElement.classList.remove("modal-open"); window.scrollTo(0, scrollPosition); }; - }, [id, liElement, order, scrollPosition]); + }, [id, liElement, order, photos, scrollPosition]); const closeModal = () => { navigate("/gallery"); diff --git a/src/components/LastUpdateSection/LastUpdateSection.jsx b/src/components/LastUpdateSection/LastUpdateSection.jsx index e507a01..da44b6a 100644 --- a/src/components/LastUpdateSection/LastUpdateSection.jsx +++ b/src/components/LastUpdateSection/LastUpdateSection.jsx @@ -11,7 +11,7 @@ export const LastUpdateSection = () => { - Останнє оновлення: 03.05.2024 + Останнє оновлення: 25.05.2024 diff --git a/src/components/MembersList/MembersModal.jsx b/src/components/MembersList/MembersModal.jsx index 6fe454d..1f7e085 100644 --- a/src/components/MembersList/MembersModal.jsx +++ b/src/components/MembersList/MembersModal.jsx @@ -13,9 +13,12 @@ import { import { Modal } from "../Modal/Modal"; import { Portal } from "../../Routes/Portal/Portal"; -import { membersApi } from "../../Api/ApiRequest"; +import { useStateContext } from "../../state/stateContext"; export const MembersModal = () => { + const { globalState } = useStateContext(); + const { members } = globalState; + const { id } = useParams(); const navigate = useNavigate(); @@ -50,8 +53,7 @@ export const MembersModal = () => { document.body.classList.add("modal-open"); document.documentElement.classList.add("modal-open"); - const members = membersApi(); - const current = members.find((el) => String(el.id) === String(id)); + const current = members?.find((el) => String(el.id) === String(id)); setCurrentMember(current); return () => { @@ -59,7 +61,7 @@ export const MembersModal = () => { document.documentElement.classList.remove("modal-open"); window.scrollTo(0, scrollPosition); }; - }, [id, scrollPosition]); + }, [id, members, scrollPosition]); const closeModal = () => { navigate("/members"); diff --git a/src/components/MembersList/avatars/1.jpg b/src/components/MembersList/avatars/1.jpg index 8752f00..cbdcaaa 100644 Binary files a/src/components/MembersList/avatars/1.jpg and b/src/components/MembersList/avatars/1.jpg differ diff --git a/src/components/ParticipantsList/ParticipantsItem.jsx b/src/components/ParticipantsList/ParticipantsItem.jsx index 3275302..a3624c2 100644 --- a/src/components/ParticipantsList/ParticipantsItem.jsx +++ b/src/components/ParticipantsList/ParticipantsItem.jsx @@ -1,17 +1,19 @@ import { Item, ItemText, ItemWrap } from "./ParticipantsList-styled"; -import { membersApi } from "../../Api/ApiRequest"; import { useParams } from "react-router-dom"; import { defineRank } from "../../helpers/defineRank"; +import { useStateContext } from "../../state/stateContext"; +import { isDateHidden } from "../../helpers/isDateHidden"; export const ParticipantsItem = ({ el, index }) => { + const { globalState } = useStateContext(); + const { members } = globalState; + const { id } = useParams(); - const members = membersApi(); const participant = members.find((member) => member.id === el.member_id); const participantRank = defineRank(el.position); - const isHide = - id === "2024-04-07" || id === "2024-04-21" || id === "2024-04-28"; + const isHide = isDateHidden(id); return ( <> diff --git a/src/components/ParticipantsList/ParticipantsList.jsx b/src/components/ParticipantsList/ParticipantsList.jsx index f94c08d..15ce7c8 100644 --- a/src/components/ParticipantsList/ParticipantsList.jsx +++ b/src/components/ParticipantsList/ParticipantsList.jsx @@ -10,22 +10,30 @@ import { import { ParticipantsListHeading } from "./ParticipantsListHeading"; import sprite from "../../sprite.svg"; import { ParticipantsItem } from "./ParticipantsItem"; +import { useStateContext } from "../../state/stateContext"; export const ParticipantsList = () => { - const { state } = useLocation(); + const { globalState } = useStateContext(); + const { tournaments } = globalState; + + const { pathname } = useLocation(); const navigate = useNavigate(); + const parts = pathname.split("/"); + const tournamentId = parts[2]; + const stageId = parts[3]; + + const { stages } = tournaments?.find((t) => t.id === tournamentId); + const currentStage = stages?.find((s) => s.date === stageId); + const handleBack = () => { - navigate(-1); + navigate(`/tournaments/${tournamentId}`); }; return ( <>
- +