From edbf8c9319c714527c638254583da2acc75e9ed3 Mon Sep 17 00:00:00 2001 From: franco sanchez Date: Tue, 3 Sep 2024 12:54:21 -0300 Subject: [PATCH] chore: a toast was added when adding a favorite --- src/components/forms/FormEdit.tsx | 8 +++---- src/components/forms/NewBook.tsx | 6 ++---- src/hooks/useMyToast.tsx | 15 +++++++++---- src/pages/Book.tsx | 36 ++++++++++++++++++++++++------- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/components/forms/FormEdit.tsx b/src/components/forms/FormEdit.tsx index bd94bf5..1a507f0 100644 --- a/src/components/forms/FormEdit.tsx +++ b/src/components/forms/FormEdit.tsx @@ -184,13 +184,12 @@ export function FormEdit({ icon: FaCheckCircle, iconColor: 'green.700', bgColor: 'black', - position: 'top-right', width: '300px', color: 'white', align: 'center', - padding: '2', + padding: '1', fntSize: 'md', - bxSize: 4, + bxSize: 5, }); navigate('/explore', { replace: true }); @@ -201,11 +200,10 @@ export function FormEdit({ icon: IoWarningSharp, iconColor: 'red.400', bgColor: 'black', - position: 'top-right', width: '300px', color: 'white', align: 'center', - padding: '2', + padding: '1', fntSize: 'md', bxSize: 5, }); diff --git a/src/components/forms/NewBook.tsx b/src/components/forms/NewBook.tsx index b9a436f..2fa6de9 100644 --- a/src/components/forms/NewBook.tsx +++ b/src/components/forms/NewBook.tsx @@ -167,11 +167,10 @@ export function FormNewBook() { icon: FaCheckCircle, iconColor: 'green.700', bgColor: 'black', - position: 'top-right', width: '300px', color: 'white', align: 'center', - padding: '2', + padding: '1', fntSize: 'md', bxSize: 5, }); @@ -184,11 +183,10 @@ export function FormNewBook() { icon: IoWarningSharp, iconColor: 'red.400', bgColor: 'black', - position: 'top-right', width: '300px', color: 'white', align: 'center', - padding: '2', + padding: '1', fntSize: 'md', bxSize: 5, }); diff --git a/src/hooks/useMyToast.tsx b/src/hooks/useMyToast.tsx index ad5d935..5520422 100644 --- a/src/hooks/useMyToast.tsx +++ b/src/hooks/useMyToast.tsx @@ -1,10 +1,12 @@ import React from 'react'; +import type { JSX } from 'react'; import type { IconType } from 'react-icons'; import { Box, CloseButton, Flex, Icon, + useBreakpointValue, // useColorModeValue, useToast, } from '@chakra-ui/react'; @@ -26,8 +28,8 @@ interface ToastType { fntSize: number | string; bgColor: string; iconColor?: string; - title: string; - position: ToastPosition | undefined; + title: string | JSX.Element; + position?: ToastPosition | undefined; description?: string; icon?: IconType; color: string; @@ -35,6 +37,10 @@ interface ToastType { export function useMyToast() { const toast = useToast(); + const responsivePosition = useBreakpointValue({ + base: 'top', + md: 'top-right', + }); function myToast({ width, @@ -52,7 +58,7 @@ export function useMyToast() { color, }: ToastType) { toast({ - position: `${position as ToastPosition}`, + position: (position as ToastPosition) || responsivePosition, duration: 3000, containerStyle: { fontFamily: 'sans-serif', @@ -66,10 +72,11 @@ export function useMyToast() { border={`1px solid ${color}`} boxShadow='md' mt={marginT} + justify='space-between' > - + {title} diff --git a/src/pages/Book.tsx b/src/pages/Book.tsx index 4f34243..2857614 100644 --- a/src/pages/Book.tsx +++ b/src/pages/Book.tsx @@ -94,9 +94,15 @@ export default function Book() { } const [isFavorite, setIsFavorite] = useState(bookObject.isFavorite); - - const { mutate: mutateFavorite } = useFavoriteBook(bookObject.id, isFavorite); - const { mutate: mutateDelete, isSuccess, isPending } = useDeleteBook(); + const { mutate: mutateFavorite, isSuccess: successFavorite } = useFavoriteBook( + bookObject.id, + isFavorite, + ); + const { + mutate: mutateDelete, + isSuccess: successDelete, + isPending, + } = useDeleteBook(); const isCurrentUserAuthor = currentUser && currentUser.uid === bookObject.userId; @@ -128,6 +134,21 @@ export default function Book() { return await mutateFavorite(currentUser?.uid); } + if (successFavorite) { + myToast({ + title: isFavorite ? 'Se agrego a favoritos' : 'Se quito de favoritos', + icon: FaCheckCircle, + iconColor: 'green.700', + bgColor: 'black', + width: '200px', + color: 'whitesmoke', + align: 'center', + padding: '1', + fntSize: 'md', + bxSize: 5, + }); + } + if (currentUser) { btnFavorite = ( @@ -188,7 +208,7 @@ export default function Book() {