-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
146 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,89 @@ | ||
import React, { FC } from 'react'; | ||
import { Text } from 'react-native'; | ||
import { Q, Query } from '@nozbe/watermelondb'; | ||
|
||
import { Box, Text } from 'components/theme'; | ||
import { RecyclerList } from 'components/recycler-list'; | ||
import { ScrollView, TouchableOpacity } from 'react-native'; | ||
import { Thumbnail } from 'components'; | ||
import { getNavigation } from 'services'; | ||
import { MainRoutes } from 'navigation/routes'; | ||
import Book from 'store/book'; | ||
import { useObservable } from 'utils/use-observable'; | ||
import { allListsObserver, listBooksQuery, readBooksQuery, wishBooksQuery } from '../home.queries'; | ||
import List from 'store/list'; | ||
|
||
const LIMIT = 10; | ||
|
||
const openReadList = () => getNavigation().push(MainRoutes.ReadList); | ||
const openWishList = () => getNavigation().push(MainRoutes.WishList); | ||
const openList = (list: List) => () => | ||
getNavigation().push(MainRoutes.WishList, { listId: list.id, listName: list.name }); | ||
|
||
export const BookshelvesScreen: FC = () => { | ||
return <Text>BookshelvesScreen</Text>; | ||
const lists = useObservable(allListsObserver, [], []); | ||
|
||
return ( | ||
<ScrollView contentContainerStyle={{ padding: 16 }}> | ||
<BookList title='Read books' query={readBooksQuery} onViewAllPress={openReadList} /> | ||
<BookList mt={4} title='Want to read' query={wishBooksQuery} onViewAllPress={openWishList} /> | ||
|
||
{lists.map(list => ( | ||
<BookList | ||
key={list.id} | ||
mt={4} | ||
title={list.name} | ||
query={() => listBooksQuery(list.id)} | ||
onViewAllPress={openList(list)} | ||
/> | ||
))} | ||
</ScrollView> | ||
); | ||
}; | ||
|
||
type ListProps = { mt?: number; query(): Query<Book>; title?: string; onViewAllPress?() }; | ||
function BookList({ mt, title, query, onViewAllPress }: ListProps) { | ||
const books = useObservable(() => query().extend(Q.experimentalTake(LIMIT)).observe(), [], []); | ||
const totalCount = useObservable(() => query().observeCount(), 0, []); | ||
|
||
return ( | ||
<Box mt={mt}> | ||
{!!title && ( | ||
<Box flexDirection='row' justifyContent='space-between'> | ||
<Text variant='body'>{title}</Text> | ||
|
||
<TouchableOpacity onPress={onViewAllPress}> | ||
<Text variant='body'> | ||
{'View all'} | ||
{totalCount > 0 ? ` (${totalCount})` : ''} | ||
</Text> | ||
</TouchableOpacity> | ||
</Box> | ||
)} | ||
|
||
<Box mt={1} height={144}> | ||
<RecyclerList | ||
data={books} | ||
itemHeight={144} | ||
itemWidth={96} | ||
rowRenderer={renderBook} | ||
isHorizontal | ||
showsHorizontalScrollIndicator={false} | ||
/> | ||
</Box> | ||
</Box> | ||
); | ||
} | ||
|
||
function renderBook(type, book: Book) { | ||
return ( | ||
<TouchableOpacity onPress={() => getNavigation().push(MainRoutes.Details, { bookId: book.id })}> | ||
<Thumbnail cache style={{ borderRadius: 10 }} width={80} height={120} title={book.title} url={book.thumbnail} /> | ||
|
||
<Box mr={2} mt={1} alignItems='center'> | ||
<Text variant='small' numberOfLines={1}> | ||
{book.title} | ||
</Text> | ||
</Box> | ||
</TouchableOpacity> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.