-
Notifications
You must be signed in to change notification settings - Fork 81
Implement events for sync status #353
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
paulgb
merged 18 commits into
main
from
paul/dis-2740-y-sweet-flag-for-connection-status
Dec 12, 2024
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3ffc030
Rewrite provider
paulgb 62af956
remove eventlistener which doesn't work on some nodes
paulgb 612b76d
improve reconnect logic
paulgb 29bff55
improve reconnect logic
paulgb c388f7b
Events for sync status
paulgb 5fd16c0
synced field works as in y-websocket
paulgb 3b9ff80
remove console log
paulgb 670edd3
rm unnecessary check
paulgb f60ec34
fix accidental revert
paulgb 2bc9ec2
format
paulgb 37fbd54
simplify internal status representation
paulgb a5981a9
many improvements and demo
paulgb 33b6704
fix tests
paulgb 55b2d18
simplify websocket checks
paulgb d7acf2b
Merge branch 'main' into paul/dis-2740-y-sweet-flag-for-connection-st…
paulgb 42bd0f6
deprecate y-websocket compat functions
paulgb a9f4610
rm unused helper
paulgb 963f722
inline setupWs
paulgb 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
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,12 +1,16 @@ | ||
| import { YDocProvider } from '@y-sweet/react' | ||
| import { randomId } from '@/lib/utils' | ||
| import { ColorGrid } from './ColorGrid' | ||
| import StateIndicator from '@/components/StateIndicator' | ||
|
|
||
| export default function Home({ searchParams }: { searchParams: { doc: string } }) { | ||
| const docId = searchParams.doc ?? randomId() | ||
| return ( | ||
| <YDocProvider docId={docId} setQueryParam="doc" authEndpoint="/api/auth"> | ||
| <ColorGrid /> | ||
| <div className="p-4 lg:p-8"> | ||
| <StateIndicator /> | ||
| <ColorGrid /> | ||
| </div> | ||
| </YDocProvider> | ||
| ) | ||
| } |
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,29 @@ | ||
| 'use client' | ||
|
|
||
| import { STATUS_CONNECTED } from '@y-sweet/client' | ||
| import { useConnectionStatus, useHasLocalChanges } from '@y-sweet/react' | ||
|
|
||
| export default function StateIndicator() { | ||
| let connectionStatus = useConnectionStatus() | ||
| let hasLocalChanges = useHasLocalChanges() | ||
|
|
||
| let statusColor = connectionStatus === STATUS_CONNECTED ? 'bg-green-500' : 'bg-red-500' | ||
| let syncedColor = hasLocalChanges ? 'bg-red-500' : 'bg-green-500' | ||
|
|
||
| return ( | ||
| <div className="mb-4"> | ||
| <div className="flex flex-row items-center text-xs space-x-1 w-fit bg-white rounded-md p-1 text-gray-500"> | ||
| <div>CONNECTED:</div> | ||
| <div | ||
| className={`w-3 h-3 rounded-full transition-colors ${statusColor}`} | ||
| title={connectionStatus} | ||
| ></div> | ||
| <div>SYNCED:</div> | ||
| <div | ||
| className={`w-3 h-3 rounded-full transition-colors ${syncedColor}`} | ||
| title={hasLocalChanges ? 'Unsynced local changes.' : 'No unsynced local changes.'} | ||
| ></div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
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.
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.
unrelated change that snuck in, but it's just removing an unnecessary import