-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Django RN demo app: fix some issues picked up during Django backend c…
…leanup (#217) Co-authored-by: Steven Ontong <[email protected]>
- Loading branch information
1 parent
f58c287
commit 9842df6
Showing
29 changed files
with
393 additions
and
623 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'django-react-native-todolist': minor | ||
--- | ||
|
||
Use react hooks. Remove Mobx stores. |
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 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
77 changes: 15 additions & 62 deletions
77
demos/django-react-native-todolist/app/views/todos/edit/[id].tsx
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,76 +1,29 @@ | ||
import * as React from 'react'; | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { ScrollView, View, Text } from 'react-native'; | ||
import { FAB } from 'react-native-elements'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Stack, useLocalSearchParams } from 'expo-router'; | ||
import prompt from 'react-native-prompt-android'; | ||
import { View, Text, ActivityIndicator } from 'react-native'; | ||
import { useLocalSearchParams } from 'expo-router'; | ||
import { useQuery } from '@powersync/react'; | ||
import { ListTodosWidget } from '../../../../library/widgets/ListTodosWidget'; | ||
import { LIST_TABLE, ListRecord } from '../../../../library/powersync/AppSchema'; | ||
|
||
import { useSystem } from '../../../../library/stores/system'; | ||
import { TodoItemWidget } from '../../../../library/widgets/TodoItemWidget'; | ||
|
||
const TodoView = observer(() => { | ||
const { listStore, todoStore } = useSystem(); | ||
const TodoView = () => { | ||
const params = useLocalSearchParams<{ id: string }>(); | ||
|
||
const id = params.id; | ||
const listModel = React.useMemo(() => { | ||
if (!id) { | ||
return null; | ||
} | ||
const listModel = listStore.getById(id); | ||
|
||
return listModel; | ||
}, [id]); | ||
const { data: result, isLoading } = useQuery<ListRecord>(`SELECT * FROM ${LIST_TABLE} WHERE id = ?`, [id]); | ||
const listRecord = result[0]; | ||
|
||
if (!listModel) { | ||
if (!listRecord && !isLoading) { | ||
return ( | ||
<View> | ||
<Text>No matching List found</Text> | ||
<Text>No matching list found</Text> | ||
</View> | ||
); | ||
} | ||
|
||
return ( | ||
<View style={{ flexGrow: 1 }}> | ||
<Stack.Screen | ||
options={{ | ||
title: listModel.record.name | ||
}} | ||
/> | ||
<FAB | ||
style={{ zIndex: 99, bottom: 0 }} | ||
icon={{ name: 'add', color: 'white' }} | ||
size="small" | ||
placement="right" | ||
onPress={() => { | ||
prompt( | ||
'Add a new Todo', | ||
'', | ||
(text) => { | ||
if (!text) { | ||
return; | ||
} | ||
|
||
todoStore.createModel({ | ||
list_id: listModel.id, | ||
description: text, | ||
completed: false | ||
}); | ||
}, | ||
{ placeholder: 'Todo description', style: 'shimo' } | ||
); | ||
}} | ||
/> | ||
<ScrollView style={{ maxHeight: '90%' }}> | ||
{listModel.todos.map((t) => { | ||
return <TodoItemWidget key={t.id} model={t} />; | ||
})} | ||
</ScrollView> | ||
if (isLoading) { | ||
return <ActivityIndicator />; | ||
} | ||
|
||
<StatusBar style={'light'} /> | ||
</View> | ||
); | ||
}); | ||
return <ListTodosWidget record={listRecord} />; | ||
}; | ||
|
||
export default TodoView; |
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 +1 @@ | ||
create publication powersync for table api_list, api_todo; | ||
create publication powersync for table lists, todos; |
Oops, something went wrong.