From 66cfc908147b7f76ce97d5744286b356681ad8ce Mon Sep 17 00:00:00 2001 From: Leonid Chelakhov Date: Fri, 20 Dec 2024 19:24:36 +0300 Subject: [PATCH 1/7] Changed the behavior of cookies --- .../components/CookieAcception/CookieMod.jsx | 15 +- FrontEnd/src/routes/ClientRouter.jsx | 187 ++++++++++-------- 2 files changed, 105 insertions(+), 97 deletions(-) diff --git a/FrontEnd/src/components/CookieAcception/CookieMod.jsx b/FrontEnd/src/components/CookieAcception/CookieMod.jsx index 7b8e0d0b..c9338d05 100644 --- a/FrontEnd/src/components/CookieAcception/CookieMod.jsx +++ b/FrontEnd/src/components/CookieAcception/CookieMod.jsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import { useCookies } from 'react-cookie'; import { Link } from 'react-router-dom'; @@ -7,11 +7,7 @@ import styles from './CookieMod.module.css'; const CookieMod = ({ active, setActive }) => { const [cookies, setCookie] = useCookies(['cookies']); - useEffect(() => { - if (cookies.cookies !== undefined) { - setActive(false); - } - }, [cookies, setActive]); + const shouldShowModal = cookies.cookies === undefined; const allowCookies = () => { const expirationDate = new Date(); @@ -26,8 +22,7 @@ const CookieMod = ({ active, setActive }) => { setCookie('cookies', false, { expires: expirationDate, sameSite: 'lax' }); setActive(false); }; - - return active ? ( + return shouldShowModal && active ? (
@@ -43,11 +38,11 @@ const CookieMod = ({ active, setActive }) => {

Дізнатися більше - + про файли cookie.

-
+
diff --git a/FrontEnd/src/routes/ClientRouter.jsx b/FrontEnd/src/routes/ClientRouter.jsx index 217970bf..e02b5264 100644 --- a/FrontEnd/src/routes/ClientRouter.jsx +++ b/FrontEnd/src/routes/ClientRouter.jsx @@ -2,6 +2,7 @@ import { ToastContainer } from 'react-toastify'; import { Route, Routes, Navigate } from 'react-router-dom'; import { ConfigProvider } from 'antd'; import { SWRConfig } from 'swr'; +import React, { useState } from 'react'; import 'react-toastify/dist/ReactToastify.css'; import customTheme from '../pages/CustomThemes/customTheme.js'; @@ -12,6 +13,7 @@ import CookiesPolicyComponent from '../pages/CookiesPolicyPage/CookiesPolicyComp import Footer from '../components/Footer/Footer'; import Header from '../components/Header/Header'; import Loader from '../components/Loader/Loader'; +import CookieMod from '../components/CookieAcception/CookieMod'; import MainPage from '../pages/LandingPage/MainPage'; import PrivacyPolicy from '../pages/PrivacyPolicyPage/PrivacyPolicyPage'; import ProfileDetailPage from '../pages/ProfileDetail/ProfileDetailPage'; @@ -39,6 +41,7 @@ import PageWrapper from '../components/PageWrapper/PageWrapper'; function ClientRouter() { const { isAuth, user, logout, isLoading } = useAuth(); + const [isCookieModalActive, setCookieModalActive] = useState(true); return ( @@ -57,98 +60,108 @@ function ClientRouter() { {isLoading ? ( ) : ( - - - } /> - } /> - {isAuth ? ( - } /> - ) : ( - } /> - )} - } - /> - } - /> - } - /> - {isAuth ? ( + <> + + + + } /> + } /> + {isAuth ? ( + } /> + ) : ( + } /> + )} } + path="/profile-detail/:id" + element={} /> - ) : ( - } /> - )} - {isAuth ? ( } + path="/profiles" + element={ + + } /> - ) : ( - } /> - )} - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } /> - } - /> - } - /> - } /> - } - /> - } - /> - } /> - - + + } + /> + {isAuth ? ( + } + /> + ) : ( + } /> + )} + {isAuth ? ( + } + /> + ) : ( + } /> + )} + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + } /> + } + /> + } + /> + } /> + } + /> + } + /> + } /> + + + )} -