From 97887db61a22e06fb08aae8bcdb96ae08708ea68 Mon Sep 17 00:00:00 2001 From: franco sanchez Date: Fri, 23 Feb 2024 15:01:16 -0300 Subject: [PATCH] chore: profile improvements --- src/components/modals/ModalConfirmation.tsx | 3 +- src/components/modals/ModalOptions.tsx | 5 +- src/components/types.d.ts | 1 + src/contexts/AuthContext.tsx | 3 + src/pages/profile/Profile.tsx | 161 ++++++++++++-------- src/pages/profile/account/MyAccount.tsx | 9 +- src/routes.tsx | 3 +- 7 files changed, 117 insertions(+), 68 deletions(-) diff --git a/src/components/modals/ModalConfirmation.tsx b/src/components/modals/ModalConfirmation.tsx index f2e652c..879e891 100644 --- a/src/components/modals/ModalConfirmation.tsx +++ b/src/components/modals/ModalConfirmation.tsx @@ -58,7 +58,8 @@ export function ModalConfirmation({ onClick={onDeleteBook} fontWeight='normal' fontSize='sm' - bg='red.400' + bg='red.500' + color='white' loadingText='Eliminando...' isLoading={isPending} _hover={{ color: 'none' }} diff --git a/src/components/modals/ModalOptions.tsx b/src/components/modals/ModalOptions.tsx index 858ea03..80515aa 100644 --- a/src/components/modals/ModalOptions.tsx +++ b/src/components/modals/ModalOptions.tsx @@ -26,11 +26,12 @@ export function ModalOptions({ diff --git a/src/components/types.d.ts b/src/components/types.d.ts index 6e40367..b8d8ab8 100644 --- a/src/components/types.d.ts +++ b/src/components/types.d.ts @@ -186,6 +186,7 @@ interface MenuType { interface AuthContextType { currentUser: User | null; loading: boolean; + token: string; } interface AuthProviderType { diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 525fd28..21a2ce9 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -8,6 +8,7 @@ const AuthContext = createContext(undefined); function AuthProvider({ children }: AuthProviderType) { const [currentUser, setCurrentUser] = useState(null); const [loading, setLoading] = useState(true); + const [token, setToken] = useState(''); const auth = getAuth(); useEffect(() => { @@ -17,6 +18,7 @@ function AuthProvider({ children }: AuthProviderType) { try { const token = await user.getIdToken(true); window.localStorage.setItem('app_tk', token); + setToken(token); // document.cookie = `app_tk=${token}; SameSite=None; path=/;`; } catch (error) { console.error('Error al actualizar el token:', error); @@ -46,6 +48,7 @@ function AuthProvider({ children }: AuthProviderType) { const value: AuthContextType = { currentUser, loading, + token, }; return {children}; diff --git a/src/pages/profile/Profile.tsx b/src/pages/profile/Profile.tsx index 50632ee..ac9ca64 100644 --- a/src/pages/profile/Profile.tsx +++ b/src/pages/profile/Profile.tsx @@ -1,6 +1,14 @@ -import React from 'react'; -import { useParams } from 'react-router-dom'; -import { Box, Flex, Image, useColorModeValue } from '@chakra-ui/react'; +import React, { useState, useEffect } from 'react'; +import { NavLink, useParams } from 'react-router-dom'; +import { + Box, + Flex, + Image, + Link, + Icon, + useColorModeValue, +} from '@chakra-ui/react'; +import { AiOutlineCloudUpload } from 'react-icons/ai'; import { MySimpleGrid } from '@components/MySimpleGrid'; import { Card } from '@components/cards/Card'; @@ -14,13 +22,98 @@ import { useAuth } from '@contexts/AuthContext'; import { NoData } from '@assets/assets'; // import { logOut } from '../../services/firebase/auth'; -export default function Profile() { +export function Profile() { const getToken = window.localStorage.getItem('app_tk'); const { currentUser } = useAuth(); const uid = currentUser?.uid; const { username } = useParams(); const { data } = useProfile(username, uid, getToken); const bgCover = useColorModeValue('gray.100', 'gray.700'); + let asideAndCardsUI; + + if (data.books.length > 0) { + asideAndCardsUI = ( + <> + + + {data.books.map( + ({ + id, + category, + language, + title, + authors, + synopsis, + sourceLink, + pathUrl, + image, + }: CardType) => ( + + + + ), + )} + + + ); + } else { + asideAndCardsUI = ( + + + Bienvenido a XBuniverse + + + + Aún no hay publicacione + + + + + Crear publicación + + + + ); + } return ( <> @@ -72,65 +165,7 @@ export default function Profile() { m='0 auto' px={{ base: 5, md: 10, '2xl': 16 }} > - - {data.books.length > 0 ? ( - - {data.books.map( - ({ - id, - category, - language, - title, - authors, - synopsis, - sourceLink, - pathUrl, - image, - }: CardType) => ( - - - - ), - )} - - ) : ( - - - - Aún no hay publicaciones - - - )} + {asideAndCardsUI} ); diff --git a/src/pages/profile/account/MyAccount.tsx b/src/pages/profile/account/MyAccount.tsx index 01217c3..edb2d60 100644 --- a/src/pages/profile/account/MyAccount.tsx +++ b/src/pages/profile/account/MyAccount.tsx @@ -38,7 +38,14 @@ export function MyAccount() { - import('@pages/PrivacyPolicies')); const Explore = lazy(() => import('@pages/Explore')); const Book = lazy(() => import('@pages/Book')); const Search = lazy(() => import('@pages/Search')); const NewBook = lazy(() => import('@pages/NewBook')); -const Profile = lazy(() => import('@pages/profile/Profile')); +// const Profile = lazy(() => import('@pages/profile/Profile')); const routes = createBrowserRouter([ {