-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add stubbed map sharing API #143
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
base: main
Are you sure you want to change the base?
Conversation
ErikSin
left a comment
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.
There are a few event emitters/listeners needed.
- The ui is designed to constantly be listening in the background and notify the user when a map has been shared. So there needs to be some listener function that invalidates the
useManyMapSharesfunction when a map get shared that lives at the top of the app - Similar to invites, the person receiving the map needs to also listen in the background for when the person sending the map has cancelled sending the map. This has to be listener because it can happen at any time during the process.
- As mentioned in the comments, if we want to show progress of the map being downloaded, the map sharing function needs to be an event emitter. As it is now, there is no way to show the progress in the ui as it an async function that will just return one object when resolved at the end.
cimigree
left a comment
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.
I agree with what Erik said. Thanks for the thorough review, Erik. I added a few things that I noticed as well.
| }) { | ||
| return { | ||
| ...baseMutationOptions(), | ||
| mutationFn: async ({ shareId }) => { |
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.
Looks like there could be a parameter mismatch here? projectId? shareId? or like in invites, deviceId? Which should it be?
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.
Yes good question, I'll think about this more tomorrow.
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.
So I think it's possible to implement either shareId or deviceId, where if we used deviceId it would cancel all active map downloads from a device. I think it's better to do shareId like we have right now.
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.
Now I'm further into the implementation I have an answer for this. The code is only going to allow one download per map share (although retries will be allowed in the case of failure). The cancel on the sender side will be with the shareId.
|
Hi, @gmaclennan
|
I can update this branch to export those hooks!
Yes this is branch is based off of main, which includes the changes from #141 . You no longer need to use that hook as it's done automatically when setting up the api client provider.
Can fix this for you.
|
|
I will try and re-visit this API tomorrow now that I've got further into the implementation. We will actually need two similar APIs I think for managing the map shares from the sender side and from the receiver side. They are subtly different and I think this current API design maybe conflates the two. It could be possible to make this current API design work for both I guess - I'll look into this. |
|
@cimigree & @ErikSin : So after implementing this, I realize there is a slight confusion with this API with the distinction between sent map shares and received map shares, which I imagine you have encountered when you are implementing this? For the API we have a couple of options:
Which do you think would be preferable to work with? I am thinking (2) is better because you there would never be a use-case for reading both sent and received map shares at the same time, and it would complicate the effects (e.g. showing the share offer screen) when the value updates. |
See src/hooks/maps.ts for the API with JS Doc comments. The usage is envisaged to be similar to the invite API.
To test in app code, put this comapeo-core-react-7.3.0-mapShare.0.tgz in the comapeo-mobile project root and check it into git, then run
npm install comapeo-core-react-7.3.0-mapShare.0.tgz. Remember to remove the.tgzand switch to a published version before merging any PR.Feedback welcome on this API as I implement it on the backend.
useManyMapShares()List all received map shares.
useSingleMapShare({ shareId })Get a specific map share by ID. Useful for tracking download progress.
useAcceptMapShare()Accept and download a received map share. Promise resolves when download starts (not when it completes).
useRejectMapShare()Reject a received map share.
useSendMapShare({ projectId })Share a map with another device. Promise resolves when recipient accepts, rejects, or already has the map.
useRequestCancelInvite({ projectId })Cancel a previously sent map share invite.