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 ( +