import React, { useState, createContext, useContext } from 'react'; import { View, Text, Pressable } from 'react-native'; import { ThemeProvider, useT, T, Screen, Scroll, Header, NavBar, Card, Group, Row, Button, Segmented, Chip, Pill, Stat, Ring, Bars, Progress, TabBar, Tabs, Stack, Icon, Spacer, SectionTitle, SearchBar, alpha } from './ui/kit'; const ACCENT = '#E8B04B'; const THEME = { dark: { bg: '#0F0D09', card: '#1A1711', card2: '#262118', line: '#2B261C', text2: '#A89F8C', text3: '#6C6557' }, light: { bg: '#FAF6EE', card: '#FFFFFF', card2: '#F0E8D8' } }; const BOOKS_INIT = [ { id: 1, title: 'The Overstory', author: 'Richard Powers', pages: 502, read: 322, c: '#2A9D8F', genre: 'Fiction', rating: 5 }, { id: 2, title: 'Project Hail Mary', author: 'Andy Weir', pages: 476, read: 130, c: '#4DA3FF', genre: 'Sci-fi', rating: 4 }, { id: 3, title: 'Klara and the Sun', author: 'Kazuo Ishiguro', pages: 303, read: 276, c: '#E8B04B', genre: 'Fiction', rating: 4 }, { id: 4, title: 'Thinking, Fast and Slow', author: 'Daniel Kahneman', pages: 499, read: 40, c: '#A78BFA', genre: 'Non-fiction', rating: 0 }, { id: 5, title: 'Piranesi', author: 'Susanna Clarke', pages: 245, read: 245, c: '#FF6B9D', genre: 'Fantasy', rating: 5 }, { id: 6, title: 'Educated', author: 'Tara Westover', pages: 334, read: 334, c: '#F0743A', genre: 'Memoir', rating: 5 }, ]; const WEEK = [24, 40, 12, 36, 48, 60, 22]; const DAYS = ['M', 'T', 'W', 'T', 'F', 'S', 'S']; const Store = createContext(null); function Cover({ b, w, h, radius }) { const t = useT(); return ( {b.title} ); } function ReadingScreen({ nav }) { const t = useT(); const { books } = useContext(Store); const current = books.filter((b) => b.read < b.pages).sort((a, b) => b.read / b.pages - a.read / a.pages); const main = current[0]; const readYear = 18, goal = 30; return (
} /> nav.push('book', { id: main.id })} style={{ flexDirection: 'row', gap: 16 }}> Continue {main.title} {main.author} Page {main.read} of {main.pages}{Math.round((main.read / main.pages) * 100)}% {readYear} {readYear} of {goal} books 3 books ahead of schedule. At this pace you finish in October. {current.slice(1).map((b) => } title={b.title} subtitle={b.author} value={Math.round((b.read / b.pages) * 100) + '%'} valueColor={t.text2} chevron onPress={() => nav.push('book', { id: b.id })} />)} ); } function LibraryScreen({ nav }) { const t = useT(); const { books } = useContext(Store); const [f, setF] = useState('all'); const [q, setQ] = useState(''); const list = books.filter((b) => (f === 'all' ? true : f === 'done' ? b.read >= b.pages : b.read < b.pages)).filter((b) => b.title.toLowerCase().includes(q.toLowerCase())); return (
} /> {list.map((b) => ( nav.push('book', { id: b.id })} style={({ pressed }) => [{ width: '30%', flexGrow: 1 }, pressed && { opacity: 0.7 }]}> {b.title} {b.author} ))} ); } function StatsScreen() { const t = useT(); return (
{[['Fiction', 0.44, '#2A9D8F'], ['Non-fiction', 0.28, '#A78BFA'], ['Sci-fi', 0.17, '#4DA3FF'], ['Memoir', 0.11, '#F0743A']].map((g) => ( {g[0]}{Math.round(g[1] * 100)}% ))} ); } function BookDetail({ nav, params }) { const t = useT(); const { books, addPages } = useContext(Store); const b = books.find((x) => x.id === params.id) || books[0]; const done = b.read >= b.pages; return ( } /> {b.title} {b.author} {[1, 2, 3, 4, 5].map((i) => )} Progress{b.read} / {b.pages} {done ? 'You finished this book.' : 'About ' + Math.ceil((b.pages - b.read) / 46) + ' hours left at your pace.'} {done ?