|
1 | | -import * as React from 'react'; |
2 | | -import { StatusBar } from 'expo-status-bar'; |
3 | | -import { ScrollView, View, Text } from 'react-native'; |
4 | | -import { FAB } from 'react-native-elements'; |
5 | | -import { observer } from 'mobx-react-lite'; |
6 | | -import { Stack, useLocalSearchParams } from 'expo-router'; |
7 | | -import prompt from 'react-native-prompt-android'; |
| 1 | +import { View, Text, ActivityIndicator } from 'react-native'; |
| 2 | +import { useLocalSearchParams } from 'expo-router'; |
| 3 | +import { useQuery } from '@powersync/react'; |
| 4 | +import { ListTodosWidget } from '../../../../library/widgets/ListTodosWidget'; |
| 5 | +import { LIST_TABLE, ListRecord } from '../../../../library/powersync/AppSchema'; |
8 | 6 |
|
9 | | -import { useSystem } from '../../../../library/stores/system'; |
10 | | -import { TodoItemWidget } from '../../../../library/widgets/TodoItemWidget'; |
11 | | - |
12 | | -const TodoView = observer(() => { |
13 | | - const { listStore, todoStore } = useSystem(); |
| 7 | +const TodoView = () => { |
14 | 8 | const params = useLocalSearchParams<{ id: string }>(); |
15 | 9 |
|
16 | 10 | const id = params.id; |
17 | | - const listModel = React.useMemo(() => { |
18 | | - if (!id) { |
19 | | - return null; |
20 | | - } |
21 | | - const listModel = listStore.getById(id); |
22 | | - |
23 | | - return listModel; |
24 | | - }, [id]); |
| 11 | + const { data: result, isLoading } = useQuery<ListRecord>(`SELECT * FROM ${LIST_TABLE} WHERE id = ?`, [id]); |
| 12 | + const listRecord = result[0]; |
25 | 13 |
|
26 | | - if (!listModel) { |
| 14 | + if (!listRecord && !isLoading) { |
27 | 15 | return ( |
28 | 16 | <View> |
29 | | - <Text>No matching List found</Text> |
| 17 | + <Text>No matching list found</Text> |
30 | 18 | </View> |
31 | 19 | ); |
32 | 20 | } |
33 | 21 |
|
34 | | - return ( |
35 | | - <View style={{ flexGrow: 1 }}> |
36 | | - <Stack.Screen |
37 | | - options={{ |
38 | | - title: listModel.record.name |
39 | | - }} |
40 | | - /> |
41 | | - <FAB |
42 | | - style={{ zIndex: 99, bottom: 0 }} |
43 | | - icon={{ name: 'add', color: 'white' }} |
44 | | - size="small" |
45 | | - placement="right" |
46 | | - onPress={() => { |
47 | | - prompt( |
48 | | - 'Add a new Todo', |
49 | | - '', |
50 | | - (text) => { |
51 | | - if (!text) { |
52 | | - return; |
53 | | - } |
54 | | - |
55 | | - todoStore.createModel({ |
56 | | - list_id: listModel.id, |
57 | | - description: text, |
58 | | - completed: false |
59 | | - }); |
60 | | - }, |
61 | | - { placeholder: 'Todo description', style: 'shimo' } |
62 | | - ); |
63 | | - }} |
64 | | - /> |
65 | | - <ScrollView style={{ maxHeight: '90%' }}> |
66 | | - {listModel.todos.map((t) => { |
67 | | - return <TodoItemWidget key={t.id} model={t} />; |
68 | | - })} |
69 | | - </ScrollView> |
| 22 | + if (isLoading) { |
| 23 | + return <ActivityIndicator />; |
| 24 | + } |
70 | 25 |
|
71 | | - <StatusBar style={'light'} /> |
72 | | - </View> |
73 | | - ); |
74 | | -}); |
| 26 | + return <ListTodosWidget record={listRecord} />; |
| 27 | +}; |
75 | 28 |
|
76 | 29 | export default TodoView; |
0 commit comments