1- import { View , Pressable } from "react-native" ;
2- import { useScrollToTop } from "@react-navigation/native" ;
3- import { FlashList } from "@shopify/flash-list" ;
4- import { eq } from "drizzle-orm" ;
5- import { Link , Stack } from "expo-router" ;
1+ import { View , Pressable , Platform } from "react-native" ;
2+ import { useScrollToTop } from "@react-navigation/native" ;
3+ import { FlashList } from "@shopify/flash-list" ;
4+ import { eq } from "drizzle-orm" ;
5+ import { Link , Stack } from "expo-router" ;
66import * as React from "react" ;
7- import { useLiveQuery } from "drizzle-orm/expo-sqlite" ;
8-
9-
10- import { Text } from "@/components/ui/text" ;
11- import { habitTable } from "@/db/schema" ;
12- import { Plus } from "@/components/Icons" ;
13- import { useMigrationHelper } from "@/db/drizzle" ;
14- import { useDatabase } from "@/db/provider" ;
15- import { HabitCard } from "@/components/habit" ;
16- import type { Habit } from "@/lib/storage" ;
7+ import { useLiveQuery } from "drizzle-orm/expo-sqlite" ;
8+ import { Text } from "@/components/ui/text" ;
9+ import { habitTable , type Habit } from "@/db/schema" ;
10+ import { Plus } from "@/components/Icons" ;
11+ import { useMigrationHelper } from "@/db/drizzle" ;
12+ import { useDatabase } from "@/db/provider" ;
13+ import { HabitCard } from "@/components/habit" ;
1714
1815export default function Home ( ) {
19- const { success, error} = useMigrationHelper ( ) ;
16+ const { success, error } = useMigrationHelper ( ) ;
2017
2118 if ( error ) {
2219 return (
@@ -37,19 +34,28 @@ export default function Home() {
3734}
3835
3936function ScreenContent ( ) {
40- const { db} = useDatabase ( ) ;
41- const { data : habits , error} = useLiveQuery (
42- db ?. select ( ) . from ( habitTable ) . where ( eq ( habitTable . archived , false ) ) ,
43- ) ;
37+ const { db } = useDatabase ( ) ;
4438
4539 const ref = React . useRef ( null ) ;
4640 useScrollToTop ( ref ) ;
4741
4842 const renderItem = React . useCallback (
49- ( { item} : { item : Habit } ) => < HabitCard { ...item } /> ,
43+ ( { item } : { item : Habit } ) => < HabitCard { ...item } enableNotifications = { item . enableNotifications ?? false } archived = { item . archived ?? false } /> ,
5044 [ ] ,
5145 ) ;
5246
47+ if ( ! db ) {
48+ return (
49+ < View className = "flex-1 items-center justify-center bg-secondary/30" >
50+ < Text > Loading database...</ Text >
51+ </ View >
52+ ) ;
53+ }
54+
55+ const { data : habits , error } = useLiveQuery (
56+ db . select ( ) . from ( habitTable ) . where ( eq ( habitTable . archived , false ) ) ,
57+ ) ;
58+
5359 if ( error ) {
5460 return (
5561 < View className = "flex-1 items-center justify-center bg-secondary/30" >
@@ -76,7 +82,7 @@ function ScreenContent() {
7682 < Text className = "text-sm" >
7783 This example use sql.js on Web and expo/sqlite on native
7884 </ Text >
79- < Text className = "text-sm" >
85+ { Platform . OS !== "web" && < Text className = "text-sm" >
8086 If you change the schema, you need to run{ " " }
8187 < Text className = "text-sm font-mono text-muted-foreground bg-muted" >
8288 bun db:generate
@@ -87,13 +93,13 @@ function ScreenContent() {
8793 < Text className = "text-sm font-mono text-muted-foreground bg-muted" >
8894 bun migrate
8995 </ Text >
90- </ Text >
96+ </ Text > }
9197 </ View >
9298 ) }
9399 ItemSeparatorComponent = { ( ) => < View className = "p-2" /> }
94100 data = { habits }
95101 renderItem = { renderItem }
96- keyExtractor = { ( _ , index ) => `item-${ index } ` }
102+ keyExtractor = { ( _ , index ) => `item-${ index } ` }
97103 ListFooterComponent = { < View className = "py-4" /> }
98104 />
99105 < View className = "absolute web:bottom-20 bottom-10 right-8" >
0 commit comments