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

chore: handle invites to projects #70

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

cimigree
Copy link
Contributor

@cimigree cimigree commented Dec 17, 2024

closes #42
Adds files to listen for invites, handle them when they come in, and accept or reject an invite to a project.
Used this notion doc: https://www.notion.so/digidem/Desktop-Invites-Architecture-15a1b08162d58053b27dd7b6133e7e33

@cimigree cimigree requested a review from ErikSin December 17, 2024 17:05
@cimigree cimigree requested review from achou11 and removed request for ErikSin January 6, 2025 16:38
Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

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

Only an initial code review and didn't actually try out the feature (can I even do that?).

Upgrading to @comapeo/core-react to v2 will reduce the diff here a bit. I have a separate PR for that via #85

Didn't take a good look at the test just yet but I think our testing setup needs to be improved in order to make it less tedious to write (Erik had started work on it but I think it's worth revisiting - I had lots of feedback on it and might just work on it myself)

Comment on lines 6 to 8
return useSuspenseQuery({
...pendingInvitesQueryOptions({ clientApi }),
})
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary spread operator

Suggested change
return useSuspenseQuery({
...pendingInvitesQueryOptions({ clientApi }),
})
return useSuspenseQuery(
pendingInvitesQueryOptions({ clientApi }),
)

import { pendingInvitesQueryOptions, useClientApi } from '@comapeo/core-react'
import { useSuspenseQuery } from '@tanstack/react-query'

export function usePendingInvites() {
Copy link
Member

Choose a reason for hiding this comment

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

might want to consider having this hook implemented in a way similar to what's outlined in digidem/comapeo-core-react#8, the main difference being adding a listener that invalidates the relevant query cache.

Ideally implementing this yourself isn't needed - but haven't gotten around to doing it yet 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I tried to do this and the dedupe...Will be curious if I did it as you imagined.

Copy link
Member

@achou11 achou11 Jan 16, 2025

Choose a reason for hiding this comment

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

Seeing if (invite) { ... } within event handlers and fallbacks in the render body to account for the invite no longer being available is usually a smell to me. Would suggest accounting for the two discrete states explicitly and separately:

  1. When the invite is no longer available and cannot be responded to
  2. When the invite is available and can be responded to

Something along the lines of this:

function JoinProjectScreenComponent() {
    // Same logic as you currently have for getting the inviteId and all
    const invite = pendingInvites.find((i) => i.inviteId === inviteId)
  
    // If the associated invite is no longer available, render content that's specific to that state
    if (!invite) {
      return <div>...</div>
    }
    
    // Otherwise, render the content as though the invite is still valid
    return <div>...</div> 
}

This becomes less prone to type-related issues and workarounds, as well as a clearer UI. There may be some parts of the screen that are the same in both of the states (duplication is fine IMO), but for example it doesn't make sense to render the buttons if we know that pressing them won't do anything because the invite is no longer valid. Not detailed in the design but I think that's a fair observation 😄

Copy link
Contributor Author

@cimigree cimigree Jan 16, 2025

Choose a reason for hiding this comment

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

Ok. UI is not awesome, but it is basic and is there. Will wait for a design and the proper wording before I spend more time thinking about it.
Screenshot 2025-01-16 at 5 45 40 PM

@cimigree
Copy link
Contributor Author

@achou11 I did as you requested, but I also added a Dev feature to be able to simulate an invite... Seen on every screen but it only works on the CreateJoin Project screen.
When you click it once, it takes you to the invite not found screen.
When you click it once you are on that screen, you can see the actual Join Project Screen.
The buttons to accept or decline do nothing except log the error.
I left the other logic there to be valid when a real invite is emitted and the other logic that works for dev simulation.
Screenshot 2025-01-16 at 5 45 51 PM

@cimigree cimigree requested a review from achou11 January 16, 2025 22:54
@ErikSin
Copy link
Contributor

ErikSin commented Jan 20, 2025

Hey, thanks for all the work on this. Gregor and I realized that there are some blockers with this architecture. If we delete CoMapeo on desktop, we don't actually delete the data. This would mean if the user tries to delete CoMapeo in order to get back to the "join a project screen", it would not work. Lets put a pause on this work as we will need to change the design to account for this.

Thanks for doing the work and sorry that we caught this a little too late.

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.

Onboarding Screens
3 participants