Skip to content

Commit

Permalink
last clicked book to store & Selected Books Sidebar to component for …
Browse files Browse the repository at this point in the history
…testing
  • Loading branch information
Foleas committed Aug 8, 2023
1 parent 24a3ad7 commit d430423
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 50 deletions.
54 changes: 4 additions & 50 deletions pruebas/01-reading-list/foleas/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import PageRangeFilter from "./components/PageRangeFilter";
import GenreFilter from "./components/GenreFilter";
import { UseGetData } from "./hooks/useGetData";
import SearchFilter from "./components/SearchFilter";
import { Book } from "./types";
import ColorThemeSwitch from "./components/ColorThemeSwitch";
import { stickyTop, textColorAnimationClass } from "./utils/tailwind";
import Paginator from "./components/Paginator";
import { getMaxPage } from "./utils/books";
import PerPageFilter from "./components/PerPageFilter";
import SelectedBooksSidebar from "./components/SelectedBooksSidebar";

function App() {
const {
Expand All @@ -25,12 +25,12 @@ function App() {
setFilteredBooks,
selectedBooks,
setSelectedBooks,
lastBookClicked,
setLastBookClicked,
} = useStore();

const { loading } = UseGetData("./books.json");

const [lastBookClicked, setLastBookClicked] = useState<string>("");

useEffect(() => {
if (!loading) {
setFilteredBooks(
Expand Down Expand Up @@ -120,53 +120,7 @@ function App() {
})}
</div>
</div>
<div className={`lecture-books-wrapper p-5 pl-0 flex-1 max-h-full`}>
{selectedBooks.length > 0 && (
<div
className={`lecture-books-inner overflow-y-auto h-full ${
selectedBooks.length &&
"transition duration-300 border-black border bg-gray-300 dark:border-white dark:bg-gray-800 rounded-md"
}`}
>
<div
className={`list-title rounded-md p-5 mb-5 bg-gray-300 ${stickyTop}`}
>
<h2
className={`text-3xl font-bold ${textColorAnimationClass}`}
>
Lista de Lectura
</h2>
</div>
<div className="box-border pb-5 h-full lecture-books">
<div className="pl-5 pr-5 grid grid-cols-4 sm:grid-cols-6 md:grid-cols-2 gap-10 pb-4">
{selectedBooks.map((v, i) => {
const selectedBook = books.find(
({ book: { ISBN } }) => ISBN === v
) as Book;
if (!selectedBook) return false;
const { ISBN, title, cover } = selectedBook.book;
return (
<BookCard
key={ISBN}
index={lastBookClicked === ISBN ? 0 : i}
title={title}
imageUrl={cover}
showInfo={false}
withRemoveBnt={true}
onClickHandler={() => {
setLastBookClicked(ISBN);
setSelectedBooks(
selectedBooks.filter((v) => v !== ISBN)
);
}}
/>
);
})}
</div>
</div>
</div>
)}
</div>
<SelectedBooksSidebar />
</>
)}
</main>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useStore } from "../../store/store";
import { Book } from "../../types";
import { stickyTop, textColorAnimationClass } from "../../utils/tailwind";
import BookCard from "../common/BookCard";

const SelectedBooksSidebar = () => {
const {
books,
selectedBooks,
setSelectedBooks,
lastBookClicked,
setLastBookClicked,
} = useStore();
return (
<div className={`lecture-books-wrapper p-5 pl-0 flex-1 max-h-full`}>
{selectedBooks.length > 0 && (
<div
className={`lecture-books-inner overflow-y-auto h-full ${
selectedBooks.length &&
"transition duration-300 border-black border bg-gray-300 dark:border-white dark:bg-gray-800 rounded-md"
}`}
>
<div
className={`list-title rounded-md p-5 mb-5 bg-gray-300 ${stickyTop}`}
>
<h2 className={`text-3xl font-bold ${textColorAnimationClass}`}>
Lista de Lectura
</h2>
</div>
<div className="box-border pb-5 h-full lecture-books">
<div
role="selected-books"
className="pl-5 pr-5 grid grid-cols-4 sm:grid-cols-6 md:grid-cols-2 gap-10 pb-4"
>
{selectedBooks.map((v, i) => {
const selectedBook = books.find(
({ book: { ISBN } }) => ISBN === v
) as Book;
if (!selectedBook) return false;
const { ISBN, title, cover } = selectedBook.book;
return (
<BookCard
key={ISBN}
index={lastBookClicked === ISBN ? 0 : i}
title={title}
imageUrl={cover}
showInfo={false}
withRemoveBnt={true}
onClickHandler={() => {
setLastBookClicked(ISBN);
setSelectedBooks(selectedBooks.filter((v) => v !== ISBN));
}}
/>
);
})}
</div>
</div>
</div>
)}
</div>
);
};

export default SelectedBooksSidebar;
2 changes: 2 additions & 0 deletions pruebas/01-reading-list/foleas/src/store/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ export const useStore = create<Store>((set) => ({
setLocalStorage("selectedBooks", selectedBooks);
return { selectedBooks };
}),
lastBookClicked: "",
setLastBookClicked: (lastBookClicked) => set(() => ({ lastBookClicked })),
}));
2 changes: 2 additions & 0 deletions pruebas/01-reading-list/foleas/src/store/storeTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ export type Store = {
setFilteredBooks: (filteredBooks: Array<string>) => void;
selectedBooks: Array<string>;
setSelectedBooks: (selectedBooks: Array<string>) => void;
lastBookClicked: string;
setLastBookClicked: (lastBookClicked: string) => void;
};

0 comments on commit d430423

Please sign in to comment.