From 9c3dd41df527085f6d6280dfca84479bb4ca2a43 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:50:34 -0700 Subject: [PATCH] doc: create Profile function --- src/components/Profile/Profile.jsx | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/components/Profile/Profile.jsx b/src/components/Profile/Profile.jsx index e69de29..41cae2a 100644 --- a/src/components/Profile/Profile.jsx +++ b/src/components/Profile/Profile.jsx @@ -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 ( + + + My Profile + + + {!favoriteMovies?.results?.length && !watchlistMovies?.results?.length + ? Add favourite or watchlist same movies to see them here! + : ( + + + + + )} + + ); +} + +export default Profile;