Skip to content

Commit aff27ce

Browse files
committed
Tweak styles of read books
1 parent 3cd1767 commit aff27ce

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/components/List.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { TYPE_DIR } from "../types";
1010

1111
function allRead(folder) {
1212
return (
13-
folder.type === TYPE_DIR && folder.booksInside === folder.booksInsideRead
13+
(folder.type === TYPE_DIR &&
14+
folder.booksInside === folder.booksInsideRead) ||
15+
(folder.type !== TYPE_DIR && folder.read)
1416
);
1517
}
1618

@@ -22,13 +24,46 @@ function bookCount(folder) {
2224
return folder.booksInside === 1 ? "1 book" : `${folder.booksInside} books`;
2325
}
2426

25-
export default function List({ books, isRetina, supportsWebp }) {
27+
export default function List({ books: rawBooks, isRetina, supportsWebp }) {
28+
const readBooks = [];
29+
const unreadBooks = [];
30+
31+
rawBooks.filter(Boolean).forEach((folder) => {
32+
if (allRead(folder)) {
33+
readBooks.push(folder);
34+
} else {
35+
unreadBooks.push(folder);
36+
}
37+
});
38+
39+
return (
40+
<>
41+
<SubList
42+
books={unreadBooks}
43+
isRetina={isRetina}
44+
supportsWebp={supportsWebp}
45+
/>
46+
{readBooks.length > 0 && (
47+
<>
48+
<h2 className={styles.List__heading}>Read</h2>
49+
<SubList
50+
books={readBooks}
51+
isRetina={isRetina}
52+
supportsWebp={supportsWebp}
53+
/>
54+
</>
55+
)}
56+
</>
57+
);
58+
}
59+
60+
function SubList({ books, isRetina, supportsWebp }) {
2661
return (
2762
<ul className={styles.List}>
28-
{books.filter(Boolean).map(folder => {
63+
{books.map((folder) => {
2964
const classes = {
30-
[styles.List__cellAllRead]: allRead(folder),
31-
[styles.List__cellUnread]: unread(folder)
65+
[styles["List__cell--allRead"]]: allRead(folder),
66+
[styles["List__cell--unread"]]: unread(folder),
3267
};
3368
return (
3469
<li

src/components/List.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
grid-gap: 1rem;
2222
}
2323

24+
.List__heading {
25+
margin: 1rem;
26+
line-height: 1.5em;
27+
border-bottom: 1px solid currentcolor;
28+
}
29+
2430
/* Pad each table view item and add dividers */
2531
.List__cell {
2632
padding: 0;

0 commit comments

Comments
 (0)