From 009178a9cf2d61185d43b069724e2e5be9795322 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 15 Feb 2024 18:50:49 +0100 Subject: [PATCH] refactoring pages with animatedComponent --- src/pages/Country.jsx | 44 +++++++++++++++++ src/pages/Game.jsx | 5 +- src/pages/Home.jsx | 26 +++++----- src/pages/Profile.jsx | 109 ++++++++++++++++++++++++++++-------------- src/pages/Results.jsx | 11 +++-- 5 files changed, 141 insertions(+), 54 deletions(-) create mode 100644 src/pages/Country.jsx diff --git a/src/pages/Country.jsx b/src/pages/Country.jsx new file mode 100644 index 0000000..b764595 --- /dev/null +++ b/src/pages/Country.jsx @@ -0,0 +1,44 @@ +import React from "react"; +import CountrySelect from "../components/ui/CountrySelect"; +import Menu from "../components/ui/Menu"; +import { motion } from "framer-motion"; +import { useLocation, useNavigate } from "react-router-dom"; + +// import screensTranslations from "../data/screensTranslations.json"; +import { useUser } from "../hooks/useUser"; + +export default function Country() { + const navigate = useNavigate(); + const location = useLocation(); + + const { language, screensTranslations } = useUser(); + + if (!screensTranslations || !screensTranslations.country) return

loading

; + const currentScreenTranslations = screensTranslations.country; + + return ( + +
+ +
+

{currentScreenTranslations.profile}

+

{currentScreenTranslations.iam}...

+ + + +
+
+
+ ); +} diff --git a/src/pages/Game.jsx b/src/pages/Game.jsx index 9cc31b0..4b942a4 100644 --- a/src/pages/Game.jsx +++ b/src/pages/Game.jsx @@ -9,11 +9,12 @@ import GameContainer from "../components/game/GameContainer.jsx"; import Tutorial from "../components/game/Tutorial.jsx"; import Logo from "../components/ui/Logo.jsx"; import GameModal from "../components/game/GameModal.jsx"; +import AnimatedPage from "../components/AnimatedPage.jsx"; export default function Game() { return ( <> -
+
@@ -23,7 +24,7 @@ export default function Game() {
-
+ ); } diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 76f5dc6..83dcda1 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -4,26 +4,28 @@ import coverWorker from "../assets/img/cover_worker.svg"; import screenWorker1 from "../assets/img/screen_worker_1.svg"; import screenWorker2 from "../assets/img/screen_worker_2.svg"; import { Link } from "react-router-dom"; -import { useEffect, useState } from "react"; + +import AnimatedPage from "../components/AnimatedPage"; +// import screensTranslations from "../data/screensTranslations.json"; +import { useUser } from "../hooks/useUser"; +import { useEffect } from "react"; export default function Home() { - const welcomeScreenDatas = useWordpressCustomData("/screen/welcome"); + const { language, screensTranslations } = useUser(); + + if (!screensTranslations || !screensTranslations.home) return

loading

; + const currentScreenTranslations = screensTranslations.home; - if (!welcomeScreenDatas) { - return
Chargement...
; - } return ( -
+
-

{welcomeScreenDatas.applicationTitle}

-

- {welcomeScreenDatas.applicationSubtitle} -

+

stay safe

+

interactive

- {welcomeScreenDatas.applicationDescription} + {currentScreenTranslations.app_description}

-
+ ); } diff --git a/src/pages/Profile.jsx b/src/pages/Profile.jsx index 937c285..e8aad7a 100644 --- a/src/pages/Profile.jsx +++ b/src/pages/Profile.jsx @@ -1,56 +1,93 @@ import React from "react"; import Menu from "../components/ui/Menu"; -import CountrySelect from "../components/ui/CountrySelect"; -import ProfileSelect from "../components/ui/ProfileSelect"; -import { Link } from "react-router-dom"; -import { useWordpressCustomData } from "../services/WordpressFetchData"; -import { motion } from "framer-motion"; -import { useNavigate } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; +import { motion } from "framer-motion"; +import { useUser } from "../hooks/useUser"; +// import screensTranslations from "../data/screensTranslations.json"; + +import lhoistEmployee from "../assets/img/profiles/lhoist-employee.svg"; +import subcontractorEmployee from "../assets/img/profiles/subcontractor-employee.svg"; +import driver from "../assets/img/profiles/driver.svg"; +import civilian from "../assets/img/profiles/civilian.svg"; + +import AnimatedPage from "../components/AnimatedPage"; export default function Profile() { const navigate = useNavigate(); + const location = useLocation(); - const profileScreenDatas = useWordpressCustomData("/screen/profile"); - // const { language } = useUserContext(); + const { profile, changeProfile } = useUser(); - if (!profileScreenDatas) { - return
Chargement...
; + const { language, screensTranslations } = useUser(); + + if (!screensTranslations || !screensTranslations.profile) return

loading

; + const currentScreenTranslations = screensTranslations.profile; + + function handleChangeProfile(e) { + changeProfile(e.target.getAttribute("value")); } - const { profileScreenTitle, profileOptions, profileSelectTitle, profileCountrySelectTitle } = - profileScreenDatas; - // console.log(profileScreenDatas); - return ( -
- {/* */} -
+ +
-

{profileScreenTitle}

-
-

{profileSelectTitle}

- -
-
-

{profileCountrySelectTitle}

- -
+

{currentScreenTranslations.profile}

+

{currentScreenTranslations.iam}...

- {/* */} +
    +
  • + +

    + {currentScreenTranslations.profiles.civilian} +

    +
  • +
  • + +

    + {currentScreenTranslations.profiles.driver} +

    +
  • +
  • + +

    + {currentScreenTranslations.profiles.lhoist_employee} +

    +
  • +
  • + +

    + { + currentScreenTranslations.profiles + .subcontractor_employee + } +

    +
  • +
- { - navigate("/play"); - }}> + navigate("/select-country"); + }}>
-
+ ); } diff --git a/src/pages/Results.jsx b/src/pages/Results.jsx index d7295bb..03721de 100644 --- a/src/pages/Results.jsx +++ b/src/pages/Results.jsx @@ -2,22 +2,25 @@ import React from "react"; import Menu from "../components/ui/Menu"; import { postGameStatisticsData } from "../services/WordpressFetchData"; import { useLanguage } from "../hooks/useLanguage"; +import AnimatedPage from "../components/AnimatedPage"; +import { useUser } from "../hooks/useUser"; export default function Results() { - const { language } = useLanguage(); - + const { language, screenTranslations } = useUser(); + if (!screenTranslations) return

loading

; + function addPost(language) { postGameStatisticsData("/statistics/post", "BE"); } return ( -
+
-
+ ); }