-
Notifications
You must be signed in to change notification settings - Fork 49
Django RN demo app: fix some issues picked up during Django backend cleanup #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65b0b62
remove annoying auto-caps
kobiebotha da38c2a
standardize table names
kobiebotha 259ae83
remove old observable pattern
kobiebotha a97cc06
boilerplate
kobiebotha 1177fd7
update django app
stevensJourney 72eed42
use react hooks
stevensJourney 6e74304
update readme and token endpoint
stevensJourney 2c68ecc
remove mobx
stevensJourney c19d60c
Merge branch 'main' into chore/polish-django-demo
stevensJourney 83455be
cleanup
stevensJourney 3fd7031
fix signout
stevensJourney af08596
use tableV2
stevensJourney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the URL was hardcoded, but besides that the
get_session
endpoint always returns a valid session. Which makes this logic not really have an affect.The user should now be able to register and login - although that is not strictly required by the backend (it will create tokens for PowerSync either way). This login screen process does at least keep this demo in line with other Todolist demos. Correct session management can be added later. Users will unfortunately have to signin each time the app boots. Alternatively signin could just be dropped altogether.