doc: create Profile function
This commit is contained in:
1 parent
3d95c500c5
commit
9c3dd41df5
1 file changed
+44
@@ -0,0 +1,44 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Box, Button, Typography } from '@mui/material';
|
||||
import { ExitToApp } from '@mui/icons-material';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import { useGetListQuery } from '../../services/TMDB';
|
||||
import { RatedCards } from '../index';
|
||||
|
||||
function Profile() {
|
||||
const { user } = useSelector((state) => state.user);
|
||||
const { data: favoriteMovies, refetch: refetchFavorites } = useGetListQuery({ listName: 'favorite/movies', accountId: user.id, sessionId: localStorage.getItem('session_id'), page: 1 });
|
||||
const { data: watchlistMovies, refetch: refetchWatchlisted } = useGetListQuery({ listName: 'watchlist/movies', accountId: user.id, sessionId: localStorage.getItem('session_id'), page: 1 });
|
||||
|
||||
useEffect(() => {
|
||||
refetchFavorites();
|
||||
refetchWatchlisted();
|
||||
}, []);
|
||||
|
||||
const logout = () => {
|
||||
localStorage.clear();
|
||||
window.location.href = '/';
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Box display="flex" justifyContent="space-between">
|
||||
<Typography variant="h4" gutterBottom>My Profile</Typography>
|
||||
<Button color="inherit" onClick={logout}>
|
||||
Logout <ExitToApp />
|
||||
</Button>
|
||||
</Box>
|
||||
{!favoriteMovies?.results?.length && !watchlistMovies?.results?.length
|
||||
? <Typography variant="h5">Add favourite or watchlist same movies to see them here!</Typography>
|
||||
: (
|
||||
<Box>
|
||||
<RatedCards title="Favorite Movies" movies={favoriteMovies} />
|
||||
<RatedCards title="Watchlist" movies={watchlistMovies} />
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default Profile;
|
||||
Reference in new issue
Block a user