From 8a248016417e090d1ffe30e250775633c4bb13c2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 8 Jun 2023 16:29:49 +0300 Subject: [PATCH] add favoritesPage --- src/pages/Favorites/index.tsx | 77 +++++++++++++++++++++++++++++++++++ src/pages/Main/index.tsx | 2 +- src/router.tsx | 5 +++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/pages/Favorites/index.tsx diff --git a/src/pages/Favorites/index.tsx b/src/pages/Favorites/index.tsx new file mode 100644 index 0000000..c21c589 --- /dev/null +++ b/src/pages/Favorites/index.tsx @@ -0,0 +1,77 @@ +import react, { useEffect, useRef, useState } from 'react' +import { useNavigate } from 'react-router-dom'; +import { backend, updateBackend } from '../../consts'; + +import { RusPassHeader } from '../../elements/Header'; +// import './style.css' + +import { EventCard } from '../../elements/EventCard'; +import { Spin } from 'antd'; + +export const Favorites: react.FC = () => { + const [favorites, setFavorites] = useState([]) + let navigate = useNavigate() + + + const queried = useRef(false); + + useEffect(()=>{ + updateBackend() + + const dataLoad = async () =>{ + const favorites = await backend.get('user/favorite') + return { + favorites + } + } + + if (!queried.current && localStorage.getItem('token') != null && localStorage.getItem('firstAuth') != 'true') { + queried.current = true; + dataLoad().then((data) => { + setFavorites(data.favorites.data as any); + }) + } + + if (null == localStorage.getItem('token')){ + navigate('/login') + } + }) + + return ( +
+ + +
+

Избранное

+
+ { + favorites.length == 0? + : + favorites.map((favorite:any, index)=>{ + return + + }) + } +
+
+ + Документация + +
+ + + + + +
+ +
© 2023 A project of the Government of Moscow
+
+ + ); +} \ No newline at end of file diff --git a/src/pages/Main/index.tsx b/src/pages/Main/index.tsx index 70d17c7..1cc8756 100644 --- a/src/pages/Main/index.tsx +++ b/src/pages/Main/index.tsx @@ -112,7 +112,7 @@ export const Main: react.FC = () => { }
- +
diff --git a/src/router.tsx b/src/router.tsx index 73a5ff3..2022b0a 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -9,6 +9,7 @@ import { EventMatch } from './pages/EventMatch'; import { GenerateTour } from './pages/GenerateTour'; import { SearchPage } from './pages/SearchPage'; import { Prefernces } from './elements/Prefernces'; +import { Favorites } from './pages/Favorites'; const routes = [ @@ -43,6 +44,10 @@ const routes = [ { path: '/prefs', element: + }, + { + path:'/favorites', + element: } ]