Skip to content

Commit

Permalink
Merge pull request #11 from TDW-2023/new-feature
Browse files Browse the repository at this point in the history
verificar btn disabled para add to readlist
  • Loading branch information
DinaX02 authored Dec 2, 2023
2 parents ce5732b + 1b5e991 commit 7d6a32f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/DetailPage/ContentDetailBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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 <Spacetop>
Expand All @@ -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 (
Expand All @@ -292,7 +304,7 @@ const ContentDetailBook = () => {
</CategoriesContainer>
)}
<BookButtonsContainer>
<Link to="/to-read-page"><AddBookToListButton1 onClick={handleAddToReadButton}>To Read</AddBookToListButton1></Link>
<Link to="/to-read-page"><AddBookToListButton1 onClick={handleAddToReadButton} disabled={isBookInToReadList}>To Read</AddBookToListButton1></Link>
<AddBookToListButton2>Have Read</AddBookToListButton2>
</BookButtonsContainer>

Expand Down

0 comments on commit 7d6a32f

Please sign in to comment.