Skip to content

Commit

Permalink
Back button to Books List
Browse files Browse the repository at this point in the history
  • Loading branch information
karlosos committed Dec 28, 2023
1 parent 2a95877 commit f134bd9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/features/clippings/books-list/BookItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import bookExport from './bookExport';

dayjs.extend(relativeTime);

const BookItem = ({ book }) => {
const BookItem = ({ book, page }) => {
const store = useStore();
const dispatch = useDispatch();
const navigate = useNavigate();
Expand All @@ -43,7 +43,7 @@ const BookItem = ({ book }) => {

const handleNavigateBook = () => {
dispatch(setActiveSidebarItem(book.id.toString()));
navigate(`/highlights/${book.title}`);
navigate(`/highlights/${book.title}?booksListPage=${page}`);
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/clippings/books-list/BooksList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const BooksList = () => {
<Wrapper ref={wrapperRef}>
<BooksContainer>
{booksFiltered.map((book) => (
<BookItem key={book.id} book={book} />
<BookItem key={book.id} book={book} page={page} />
))}
</BooksContainer>
<PaginationWrapper>
Expand Down
18 changes: 17 additions & 1 deletion src/app/features/clippings/highlights/HighlightsList.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ChevronLeft } from 'lucide-react';
import React, { useRef } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { Pagination } from 'semantic-ui-react';

import HighlightItem from './HighlightItem';
import {
AdditionalButtons,
BackButton,
Content,
Footer,
MainHeader,
Expand All @@ -12,8 +15,10 @@ import {
} from './HighlightsList.style';

const HighlightsList = ({ title, highlights, bookInfoVisible }) => {
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const page = searchParams.get('page') ?? 1;
const booksListPage = searchParams.get('booksListPage');
const wrapperRef = useRef();

const itemsPerPage = 20;
Expand All @@ -28,6 +33,7 @@ const HighlightsList = ({ title, highlights, bookInfoVisible }) => {
// eslint-disable-next-line no-shadow
const handlePaginationChange = (e, { activePage }) => {
setSearchParams({
booksListPage,
page: activePage,
});
wrapperRef.current.scrollTo(0, 0);
Expand All @@ -36,6 +42,16 @@ const HighlightsList = ({ title, highlights, bookInfoVisible }) => {
return (
<Wrapper ref={wrapperRef}>
<MainHeader>
{booksListPage && (
<AdditionalButtons>
<BackButton
onClick={() => navigate(`/?page=${booksListPage}`)}
>
<ChevronLeft />
Go back
</BackButton>
</AdditionalButtons>
)}
<Title as="h1">{title}</Title>
</MainHeader>
<Content>
Expand Down
33 changes: 32 additions & 1 deletion src/app/features/clippings/highlights/HighlightsList.style.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export const Wrapper = styled.div`
`;

export const MainHeader = styled.div`
padding-top: 24px;
padding-top: 22px;
display: inline-flex;
flex-direction: column;
position: sticky;
top: 0;
left: 0;
Expand All @@ -22,6 +23,7 @@ export const MainHeader = styled.div`
`;

export const Title = styled(Header)`
margin-top: 5px;
color: rgb(37, 56, 52);
`;

Expand All @@ -44,3 +46,32 @@ export const Footer = styled.div`
box-shadow: -16px -1px 0 #e5e5e5;
user-select: none;
`;

export const BackButton = styled.div`
background: #ffffff;
color: #4d5d50;
border: 1px solid #f2f6f3;
border-radius: 4px;
display: flex;
align-items: center;
gap: 4px;
justify-content: center;
padding: 4px 16px;
&:hover {
background: #fafefc;
cursor: pointer;
}
`;

export const BackButtonIcon = styled.div`
display: flex;
align-items: center;
justify-content: center;
`;

export const AdditionalButtons = styled.div`
display: flex;
`

0 comments on commit f134bd9

Please sign in to comment.