@@ -10,7 +10,9 @@ import { TYPE_DIR } from "../types";
1010
1111function 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
0 commit comments