add favoritesPage

This commit is contained in:
= 2023-06-08 16:29:49 +03:00
parent ba33783464
commit 8a24801641
3 changed files with 83 additions and 1 deletions

View File

@ -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 (
<div className='mainWrapper'>
<RusPassHeader></RusPassHeader>
<div className='mainCard'>
<h2>Избранное</h2>
<div className='fav-wrapper'>
{
favorites.length == 0? <Spin/>
:
favorites.map((favorite:any, index)=>{
return <EventCard category='attraction'
description={favorite.description}
lat={1}
lon={2}
oid={favorite.oid}
title={favorite.title} ></EventCard>
})
}
</div>
</div>
<a href='https://1drv.ms/w/s!AuaFmGWFNV5Np0OhMmVtxPXlG2Ob?e=f7NDCp'>Документация</a>
<div className='mainIconWrapper'>
<img className='mainIcon' src='icons/yt.svg'></img>
<img className='mainIcon' src='icons/vk.svg'></img>
<img className='mainIcon' src='icons/dz.svg'></img>
<img className='mainIcon' src='icons/tg.svg'></img>
<img className='mainIcon' src='icons/ok.svg'></img>
</div>
<div className='grey'>© 2023 A project of the Government of Moscow</div>
</div>
);
}

View File

@ -112,7 +112,7 @@ export const Main: react.FC = () => {
}
</div>
<div>
<Button className=''>Посмотреть все</Button>
<Button onClick={()=>navigate('/favorites')} className=''>Посмотреть все</Button>
</div>
</div>

View File

@ -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: <Prefernces></Prefernces>
},
{
path:'/favorites',
element: <Favorites></Favorites>
}
]