-
Notifications
You must be signed in to change notification settings - Fork 50
Sync progress #555
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
Sync progress #555
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c4181c6
Add sync progress APIs
simolus3 51541c9
Track progress for sync lines
simolus3 49bf3bf
Try testing sync with mock fetch
simolus3 7b1102c
Actually get the thing to connect
simolus3 cc4a081
Add sync tests
simolus3 cb58548
Format
simolus3 2912a49
Doc comments
simolus3 ed11438
Add changeset
simolus3 b569cb7
Merge branch 'main' into sync-progress
simolus3 6a3e3c2
Simplify sync API
simolus3 6fa0b6a
Merge remote-tracking branch 'origin/main' into sync-progress
simolus3 e577134
Update docs on fraction
simolus3 149db50
Review feedback
simolus3 edf138b
Merge branch 'main' into sync-progress
simolus3 654b784
Add progress indicator to demos
simolus3 d064f08
Reformat
simolus3 143ff12
Update react-native-quick-sqlite
simolus3 a309531
Update lockfile
simolus3 c45e84e
Mention entrypoint to progress API
simolus3 1de9e65
Merge remote-tracking branch 'origin/main' into sync-progress
simolus3 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,8 @@ | ||
--- | ||
'@powersync/common': minor | ||
'@powersync/web': minor | ||
'@powersync/node': minor | ||
'@powersync/react-native': minor | ||
--- | ||
|
||
Report progress information about downloaded rows. Sync progress is available through `SyncStatus.downloadProgress`. |
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
40 changes: 40 additions & 0 deletions
40
demos/react-native-supabase-todolist/library/widgets/GuardBySync.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useStatus } from '@powersync/react'; | ||
import { FC, ReactNode } from 'react'; | ||
import { View } from 'react-native'; | ||
import { Text, LinearProgress } from '@rneui/themed'; | ||
|
||
/** | ||
* A component that renders its child if the database has been synced at least once and shows | ||
* a progress indicator otherwise. | ||
*/ | ||
export const GuardBySync: FC<{ children: ReactNode; priority?: number }> = ({ children, priority }) => { | ||
const status = useStatus(); | ||
|
||
const hasSynced = priority == null ? status.hasSynced : status.statusForPriority(priority).hasSynced; | ||
if (hasSynced) { | ||
return children; | ||
} | ||
|
||
// If we haven't completed a sync yet, show a progress indicator! | ||
const allProgress = status.downloadProgress; | ||
const progress = priority == null ? allProgress : allProgress?.untilPriority(priority); | ||
|
||
return ( | ||
<View> | ||
{progress != null ? ( | ||
<> | ||
<LinearProgress variant="determinate" value={progress.downloadedFraction} /> | ||
{progress.downloadedOperations == progress.totalOperations ? ( | ||
<Text>Applying server-side changes</Text> | ||
) : ( | ||
<Text> | ||
Downloaded {progress.downloadedOperations} out of {progress.totalOperations}. | ||
</Text> | ||
)} | ||
</> | ||
) : ( | ||
<LinearProgress variant="indeterminate" /> | ||
)} | ||
</View> | ||
); | ||
}; |
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
41 changes: 41 additions & 0 deletions
41
demos/react-supabase-todolist/src/components/widgets/GuardBySync.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Box, LinearProgress, Stack, Typography } from '@mui/material'; | ||
import { useStatus } from '@powersync/react'; | ||
import { FC, ReactNode } from 'react'; | ||
|
||
/** | ||
* A component that renders its child if the database has been synced at least once and shows | ||
* a progress indicator otherwise. | ||
*/ | ||
export const GuardBySync: FC<{ children: ReactNode; priority?: number }> = ({ children, priority }) => { | ||
const status = useStatus(); | ||
|
||
const hasSynced = priority == null ? status.hasSynced : status.statusForPriority(priority).hasSynced; | ||
if (hasSynced) { | ||
return children; | ||
} | ||
|
||
// If we haven't completed a sync yet, show a progress indicator! | ||
const allProgress = status.downloadProgress; | ||
const progress = priority == null ? allProgress : allProgress?.untilPriority(priority); | ||
|
||
return ( | ||
<Stack direction="column" spacing={1} sx={{ p: 4 }} alignItems="stretch"> | ||
{progress != null ? ( | ||
<> | ||
<LinearProgress variant="determinate" value={progress.downloadedFraction * 100} /> | ||
<Box sx={{ alignSelf: 'center' }}> | ||
{progress.downloadedOperations == progress.totalOperations ? ( | ||
<Typography>Applying server-side changes</Typography> | ||
) : ( | ||
<Typography> | ||
Downloaded {progress.downloadedOperations} out of {progress.totalOperations}. | ||
</Typography> | ||
)} | ||
</Box> | ||
</> | ||
) : ( | ||
<LinearProgress variant="indeterminate" /> | ||
)} | ||
</Stack> | ||
); | ||
}; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.