diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 94e2c43..b27e807 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -10,27 +10,36 @@ import { createNativeStackNavigator } from "@react-navigation/native-stack"; import { useAtomValue } from "@effect/atom-react"; import * as Option from "effect/Option"; import { AsyncResult } from "effect/reactivity"; +import { View } from "react-native"; import { IconButton } from "./components/ui/IconButton"; import { ConnectScreen } from "./features/connect/ConnectScreen"; import { EnterDetailsScreen } from "./features/connect/EnterDetailsScreen"; import { ScanPairingCodeScreen } from "./features/connect/ScanPairingCodeScreen"; import { ComponentCatalogScreen } from "./features/development/ComponentCatalogScreen"; +import { KindleScreen } from "./features/kindle/KindleScreen"; import { BookScreen } from "./features/library/BookScreen"; import { LibraryScreen } from "./features/library/LibraryScreen"; import { useAppearance } from "./features/settings/appearance/AppearanceProvider"; import { SettingsScreen } from "./features/settings/SettingsScreen"; import { connectionAtom } from "./state/connection"; -function SettingsButton() { +function LibraryHeaderButtons() { const navigation = useNavigation(); return ( - navigation.navigate("Settings")} - /> + + navigation.navigate("Kindle")} + /> + navigation.navigate("Settings")} + /> + ); } @@ -64,13 +73,18 @@ const RootStack = createNativeStackNavigator({ Library: { screen: LibraryScreen, linking: "", - options: { title: "Dropcap", headerRight: SettingsButton }, + options: { title: "Dropcap", headerRight: LibraryHeaderButtons }, }, Book: { screen: BookScreen, linking: "book/:id", options: { title: "" }, }, + Kindle: { + screen: KindleScreen, + linking: "kindle", + options: { title: "Kindle" }, + }, Settings: { screen: SettingsScreen, linking: "settings", diff --git a/apps/mobile/src/components/ui/Notice.tsx b/apps/mobile/src/components/ui/Notice.tsx index 8341d57..e3ac5f7 100644 --- a/apps/mobile/src/components/ui/Notice.tsx +++ b/apps/mobile/src/components/ui/Notice.tsx @@ -12,6 +12,8 @@ export function Notice(props: { readonly floating?: boolean; readonly onDismiss?: () => void; readonly dismissLabel?: string; + /** One short verb, such as "Try again", shown before the dismiss button. */ + readonly action?: { readonly label: string; readonly onPress: () => void }; }) { const danger = props.tone === "danger"; @@ -42,6 +44,24 @@ export function Notice(props: { > {props.message} + {props.action ? ( + + + {props.action.label} + + + ) : null} {props.onDismiss ? ( setNoticeVisible(false)} /> ) : null} + {} }} + onDismiss={() => {}} + /> diff --git a/apps/mobile/src/features/kindle/KindleScreen.tsx b/apps/mobile/src/features/kindle/KindleScreen.tsx new file mode 100644 index 0000000..1a1d0d0 --- /dev/null +++ b/apps/mobile/src/features/kindle/KindleScreen.tsx @@ -0,0 +1,272 @@ +import { useAtom, useAtomRefresh, useAtomValue } from "@effect/atom-react"; +import { + Command, + type BookPath, + type CommandId, + type Device, + type QueuedCommand, +} from "@kindle-drop/worker/Api"; +import { useFocusEffect } from "@react-navigation/native"; +import type * as DateTime from "effect/DateTime"; +import * as Option from "effect/Option"; +import { AsyncResult } from "effect/reactivity"; +import { useState, type ReactNode } from "react"; +import { ScrollView, View } from "react-native"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; + +import { AppText, AppTextInput } from "../../components/ui/AppText"; +import { Button } from "../../components/ui/Button"; +import * as Dialog from "../../components/ui/Dialog"; +import { EmptyState } from "../../components/ui/EmptyState"; +import { ErrorBanner } from "../../components/ui/ErrorBanner"; +import { IconButton } from "../../components/ui/IconButton"; +import { ListActionRow } from "../../components/ui/ListActionRow"; +import { ListRowLayout } from "../../components/ui/ListRowLayout"; +import { ListSection } from "../../components/ui/ListSection"; +import { Notice } from "../../components/ui/Notice"; +import { Progress } from "../../components/ui/Progress"; +import { MOBILE_RADIUS } from "../../lib/designTokens"; +import { booksState } from "../../state/books"; +import { nowAtom } from "../../state/clock"; +import { kindleState } from "../../state/kindle"; +import { statusError } from "../library/libraryCopy"; +import { + commandError, + deviceSummary, + failures, + libraryEntries, + rescanPending, + searchEntries, + type LibraryEntry, +} from "./kindleCopy"; + +function Tile(props: { + readonly label: string; + readonly value: string; + readonly children?: ReactNode; +}) { + return ( + + + {props.label} + + + {props.value} + + {props.children} + + ); +} + +function DeviceTiles(props: { readonly device: Device; readonly now: DateTime.Utc }) { + const { checkedIn, battery, free } = deviceSummary(props.device, props.now); + + return ( + + + {Option.isSome(battery) ? ( + + ) : null} + {Option.isSome(free) ? ( + + {Option.isSome(free.value.used) ? ( + + ) : null} + + ) : null} + + + {checkedIn} + + + ); +} + +function FailureNotice(props: { + readonly id: CommandId; + readonly command: Command; + readonly text: string; +}) { + const [dismissed, dismiss] = useAtom(kindleState.dismissAtom(props.id)); + const [retried, retry] = useAtom(kindleState.retryAtom(props.id)); + + return ( + retry(props.command) }} + dismissLabel="Dismiss" + onDismiss={() => dismiss()} + /> + ); +} + +function BookRow(props: { readonly entry: LibraryEntry; readonly onDelete: () => void }) { + const { book, deleting } = props.entry; + const title = book.title || "Untitled"; + + return Option.match(deleting, { + onNone: () => ( + + Dialog.confirm({ + title: `Delete ${title}?`, + message: "Removed from your Kindle when it next wakes", + confirmText: "Delete", + cancelText: "Cancel", + destructive: true, + onConfirm: props.onDelete, + }) + } + /> + ), + onSome: ({ id }) => , + }); +} + +function DeletingRow(props: { readonly id: CommandId; readonly title: string }) { + const [undone, undo] = useAtom(kindleState.dismissAtom(props.id)); + + return ( + undo()} /> + } + /> + ); +} + +function Library(props: { + readonly device: Device; + readonly commands: ReadonlyArray; + readonly onDelete: (path: BookPath) => void; + readonly onRescan: () => void; + readonly rescanDisabled: boolean; +}) { + const [searching, setSearching] = useState(false); + const [query, setQuery] = useState(""); + const entries = libraryEntries(props.device.books, props.commands); + const shown = searchEntries(entries, query); + const rescanning = rescanPending(props.commands); + + return ( + + + + {`Library · ${entries.length}`} + + { + setSearching(!searching); + setQuery(""); + }} + /> +