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: add Sync screen #241

Merged
merged 13 commits into from
Apr 24, 2024
Merged

feat: add Sync screen #241

merged 13 commits into from
Apr 24, 2024

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Apr 9, 2024

Closes #118

Intentional omissions/departures:

  • no line of text displaying connection to cloud server
  • no mention of map sync in the sync progress title
  • no animation between different screen states
  • no wifi screen being primarily white instead of primarily blue
  • no wiggle animation for button when pressing during "up-to-date" state

Important changes:

  • completely refactored the useSyncState() hook because I was noticing stale closure issues with the implementation. using a class-based approach seemed easier to work with and easier to get working.
  • introduces useSyncProgress() hook, derived from the same sync store instance as useSyncState()

TODOs that may block merging:

  • use correct color for project icon in ProjectSyncDisplay
  • figure out what settings button in top right of ProjectSyncDisplay is supposed to do
  • decide if we want to suspend data sync when app is not focused
  • figure out how to calculate progress based on sync state
  • review changes to useSyncState hook

Pretty difficult to test the sync states right now, so previews are working with mocked situations:

  • No project joined/created:

image

  • Nothing to sync / sync done state:
image
  • Something to sync state:
image
  • Syncing state:
image

@achou11 achou11 force-pushed the 118/sync-screens branch 5 times, most recently from 1572d25 to d2f0952 Compare April 15, 2024 21:48
@achou11 achou11 requested a review from ErikSin April 15, 2024 21:52
@achou11 achou11 marked this pull request as ready for review April 15, 2024 21:52
@achou11
Copy link
Member Author

achou11 commented Apr 15, 2024

There are some TODOs that I scattered in the PR in the earlier days of working on this. I haven't looked at them in a while but will revisit tomorrow to see if they're still relevant

@ErikSin
Copy link
Contributor

ErikSin commented Apr 17, 2024

Can you rebase/merge from main? It will be easier to test once I can invite someone to a project

@achou11
Copy link
Member Author

achou11 commented Apr 17, 2024

Can you rebase/merge from main? It will be easier to test once I can invite someone to a project

done!

@ErikSin
Copy link
Contributor

ErikSin commented Apr 17, 2024

Were you able to make 2 devices sync? I am testing with 2 devices that are both on the same project and network and they are not discovering each other. My phone has this problem with sync in mapeo-mobile, so it could be my device.

@achou11
Copy link
Member Author

achou11 commented Apr 17, 2024

Were you able to make 2 devices sync? I am testing with 2 devices that are both on the same project and network and they are not discovering each other. My phone has this problem with sync in mapeo-mobile, so it could be my device.

honestly haven't tried actually syncing yet (needed the invite stuff merged before I could test it). expecting there to be some issues that I need to resolve, so consider this PR "ready to review but probably needs lots of work based on real testing" 😅

as for your issue, are you talking about discovery when inviting or during sync?

@ErikSin
Copy link
Contributor

ErikSin commented Apr 17, 2024

as for your issue, are you talking about discovery when inviting or during sync?

I was able to discover the other device and invite them to a project. But on the sync screen, both devices are saying "0 devices nearby" even when they are on the same wifi network

@achou11
Copy link
Member Author

achou11 commented Apr 17, 2024

as for your issue, are you talking about discovery when inviting or during sync?

I was able to discover the other device and invite them to a project. But on the sync screen, both devices are saying "0 devices nearby" even when they are on the same wifi network

ah that might be an issue in my implementation then. will need to look into it but thanks for noting it 👍

@achou11 achou11 marked this pull request as draft April 17, 2024 22:28
@achou11
Copy link
Member Author

achou11 commented Apr 17, 2024

converting to a draft until I revisit this and test it out given the recent updates, which are relevant for this

@ErikSin
Copy link
Contributor

ErikSin commented Apr 17, 2024

I did a quick code review (not a functionality review) and no glaring problems. I didn't go to deep into it though because it seems like there will some code changes when trying to make it work

@ErikSin ErikSin marked this pull request as ready for review April 24, 2024 16:19
Copy link
Contributor

@EvanHahn EvanHahn left a comment

Choose a reason for hiding this comment

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

LGTM with a small question and a few nitpicks.

isSubscribedInternal = true;
project.$sync
#onSyncState = (state: SyncState) => {
console.log({from: 'listener', ...state});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: should we remove this?

Suggested change
console.log({from: 'listener', ...state});

src/frontend/hooks/server/projects.ts Outdated Show resolved Hide resolved
Comment on lines +150 to +152
.then(this.#onSyncState)
.catch(e => {
error = e;
listeners.forEach(listener => listener());
this.#error = e;
this.#notifyListeners();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do anything special if we've unsubscribed before this promise resolves? I imagine the following scenario:

  1. #startSubscription is called, kicking off this.#project.$sync.getState().
  2. #stopSubscription is called.
  3. The getState() promise resolves.

Copy link
Member Author

@achou11 achou11 Apr 24, 2024

Choose a reason for hiding this comment

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

i think it's okay because resolving will eventually call the subscribed listeners (in #onSyncState), but if #stopSubscription is called it's because there are no more listeners, so it should result in a no-op.

that's my initial thinking, anyways

Copy link
Member Author

@achou11 achou11 Apr 24, 2024

Choose a reason for hiding this comment

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

i'm hoping this is a useful shared component for us moving forward. basically creates a layout that includes a fixed position "dock" at the bottom and a scrollable content area above it. this is to account for allowing dynamic content area size without needing to scroll down to the bottom of the view to see the content in the dock. the overflow from the content area gets clipped by the fixed dock area. usually this dock area contains big, actionable buttons, and we don't want these to get hidden due to being pushed by an overflowing content area

image

// TODO: Replace with proper check of being a part of a shared project
if (data && data.length === 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

highlighting this, even though this needs to be addressed later due to core limitations

}

export const SyncScreen = ({navigation}: NativeRootNavigationProps<'Sync'>) => {
// TODO: Is this the right field to use?
Copy link
Member Author

Choose a reason for hiding this comment

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

can probably remove this?

// TODO: Is this the right field to use?
const wifiStatus = useLocalDiscoveryState(state => state.wifiStatus);

// TODO: Handle error case
Copy link
Member Author

Choose a reason for hiding this comment

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

is this something we can address in this PR, or should be leave it for later? not sure what the error state would look like (would it use the bottom sheet modal pattern?)

Comment on lines 90 to 95
React.useEffect(() => {
if (isSyncDone) {
project.$sync.stop();
queryClient.invalidateQueries({queryKey: [OBSERVATION_KEY]});
}
}, [isSyncDone, project, queryClient]);
Copy link
Member Author

@achou11 achou11 Apr 24, 2024

Choose a reason for hiding this comment

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

discussed elsewhere but this check should probably be done when leaving the screen e.g. navigation.addListener('beforeRemove', ...)

@ErikSin ErikSin merged commit de78926 into main Apr 24, 2024
3 checks passed
@ErikSin ErikSin deleted the 118/sync-screens branch April 24, 2024 21:14
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.

Sync Screen/No Wifi Screen
3 participants