Skip to content
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

feat(recipes): add recipe for local first data using powersync #147

Closed

Conversation

trevor-coleman
Copy link
Contributor

@trevor-coleman trevor-coleman commented Mar 22, 2024

Adds a recipe for using PowerSync and Supabase to sync local and backend data.

Topcis include:

  • Installing the SDK and Dependencies
  • Authenticating with Supabase
  • Connecting PowerSync to Supabase
  • Fetching and Managing TodoLists
  • Sharing the Database With Screens
  • Fetching and Managing Todos

@trevor-coleman trevor-coleman force-pushed the trevor-coleman/local-first-data-with-powersync branch from f9508b2 to 924c550 Compare March 22, 2024 23:33
@trevor-coleman trevor-coleman changed the title Add recipe for local first data using powersync feat(recipes): add recipe for local first data using powersync Mar 25, 2024
@trevor-coleman trevor-coleman marked this pull request as ready for review March 25, 2024 17:02
Copy link
Contributor

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, nice job as it's a pretty large topic to cover!

Left some comments that can maybe help spruce a few things up.

docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Show resolved Hide resolved
Copy link
Contributor

@morganick morganick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is as far as I made it today. I'll wrap the review up in the morning.

docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
@trevor-coleman
Copy link
Contributor Author

Appreciate the comments -- it's hard to keep everything consistent because I have a working app, and then make changes to make the writing simpler and it's hard to keep them both in sync.

docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
@trevor-coleman
Copy link
Contributor Author

Here's what the finished app looks like:

CleanShot 2024-03-28 at 13 04 33

Copy link
Contributor

@morganick morganick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the things that I ran into. This was a much better experience than the first run through. For some reason it isn't syncing through to Supabase so I'll have to check my configuration there. I can pull data from Supabase into PowerSync, but the application doesn't push anything.

I'm able to create things inside the application. It just stays locally.

docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved

```tsx
import {Button, Icon, ListItem, Screen, Text, TextField} from "app/components"
import {SignedInNavigatorProp} from "app/navigators"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import {SignedInNavigatorProp} from "app/navigators"
import {SignedInNavigatorScreenProps} from "app/navigators"

docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
@trevor-coleman
Copy link
Contributor Author

trevor-coleman commented Apr 1, 2024

Thanks for that @morganick -- integrated it all and made a few extra tweaks:

  1. moved use-auth into /services/database/use-auth.tsx -- it's the same service (supabase) and it puts all our stuff in one place
  2. went through and added comments with the filename to all codeblocks where it makes sense (// app/path/to/file.tsx)
  3. Made all text references PowerSync and all variables powersync (this matches their code)
  4. replaced uuid with expo-crypto -- single install instead of two, and it's better and more react-nativey

@trevor-coleman
Copy link
Contributor Author

I think we're pretty close -- at least I feel good enough to share it with PowerSync now.

Copy link
Contributor

@morganick morganick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my version, I'm still getting:

LOG  PowerSync status changed {"connected": true, "dataFlow": {"downloading": false, "uploading": false}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": true, "dataFlow": {"downloading": false, "uploading": false}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": true, "dataFlow": {"downloading": false, "uploading": true}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": true, "dataFlow": {"downloading": false, "uploading": true}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": true, "dataFlow": {"downloading": false, "uploading": false}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": true, "dataFlow": {"downloading": false, "uploading": false}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": false, "dataFlow": {"downloading": false, "uploading": false}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 LOG  PowerSync status changed {"connected": false, "dataFlow": {"downloading": false, "uploading": false}, "lastSyncedAt": 2024-04-02T14:53:18.701Z}
 DEBUG  [PowerSyncStream] Stream input empty

After about 5 seconds from successfully signing in. Not sure why this happens.

docs/recipes/LocalFirstDataWithPowerSync.md Outdated Show resolved Hide resolved
docs/recipes/LocalFirstDataWithPowerSync.md Show resolved Hide resolved
Copy link
Contributor

@morganick morganick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dev dep.

docs/recipes/LocalFirstDataWithPowerSync.md Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants