Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verificar btn disabled para add to readlist #11

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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