From 1b5e9912f5880d05a07700952b4eb26d1fa19667 Mon Sep 17 00:00:00 2001 From: DinaX Date: Sat, 2 Dec 2023 02:16:20 +0000 Subject: [PATCH] verificar btn disabled para add to readlist --- src/components/DetailPage/ContentDetailBook.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/DetailPage/ContentDetailBook.js b/src/components/DetailPage/ContentDetailBook.js index 1cdf551..67a9560 100644 --- a/src/components/DetailPage/ContentDetailBook.js +++ b/src/components/DetailPage/ContentDetailBook.js @@ -2,6 +2,7 @@ import React from 'react'; import { useSelector } from 'react-redux'; import { useDispatch } from 'react-redux'; import { selectSelectedBook } from '../../redux/slices/bookSliceRedux'; +import { selectToReadBooks } from '../../redux/slices/bookSliceRedux'; import { addToRead } from '../../redux/slices/bookSliceRedux'; import styled from 'styled-components'; import ArrowBack from '../../assets/back.png'; @@ -210,6 +211,13 @@ vertical-align: middle; &:active { opacity: 0.5; } + +&:disabled { + background: #ccc; + border: 1px solid #ccc; + color: #666; + cursor: not-allowed; + `; const AddBookToListButton2 = styled.button` @@ -255,6 +263,7 @@ const ContentDetailBook = () => { const dispatch = useDispatch(); const selectedBook = useSelector(selectSelectedBook); const navigate = useNavigate(); + const toReadBooks = useSelector(selectToReadBooks); if (!selectedBook) { // caso nenhum livro tiver sido selecionado return @@ -272,6 +281,9 @@ const ContentDetailBook = () => { } }; + + const isBookInToReadList = toReadBooks.some(book => book.id === selectedBook.id); // verificar a existencia de um livro com o mesmo id na lista --> funcionalidade para dar disabled no btn de add to read list + const verifyIfBookHaveDescription = selectedBook.volumeInfo.description || "Sorry, this book doesn't have a description available :(" //caso livro nao tiver descricao return ( @@ -292,7 +304,7 @@ const ContentDetailBook = () => { )} - To Read + To Read Have Read