Skip to content

Conversation

gmaclennan
Copy link
Member

@gmaclennan gmaclennan commented Feb 7, 2025

This is an initial attempt at implementing invite hooks, fixing #8.

NB: this PR removes the export of <ClientApiContext> which should now be considered an implementation detail - I can't see a reason for using this outside of this module.

The implementation adds a PendingInviteStore which provides a stable "oldest pending invite" and the option to subscribe to when this changes, however subscribing manually should be discouraged, and we could perhaps only return the getPendingInvite() method from the store.

The proposed usage is:

import {
  usePendingInviteStore,
  usePendingInviteListener,
  useCancelledInviteListener
} from '@comapeo/core-react'

const RootNavigationComponent = () => {
  const {
    canShowNewInvite,
    screenIsOpenForInvite,
    showNewInvite,
    showCanceledInvite
  } = useInviteNavigationHelpers() // Some hook to wrap navigation library used

  const pendingInviteStore = usePendingInviteStore()

  usePendingInviteListener(invite => {
    if (!canShowNewInvite()) return
    showNewInvite(invite)
  })

  useCancelledInviateListener(invite => {
    if (screenIsOpenForInvite(invite.inviteId)) {
      showCanceledInvite(invite)
    }
  })

  useNavigationScreenChangedListener(screenName => {
    if (!canShowNewInvite()) return
    const invite = pendingInviteStore.getSnapshot()
    if (invite) showNewInvite(invite)
  })

  // ...rest of component
}

@gmaclennan gmaclennan self-assigned this Feb 7, 2025
@gmaclennan gmaclennan marked this pull request as draft February 7, 2025 15:54
@awana-lockfile-bot
Copy link

package-lock.json changes

Click to toggle table visibility
Name Status Previous Current
eslint-plugin-react-hooks ADDED - 5.1.0

@achou11
Copy link
Member

achou11 commented May 6, 2025

Closing this since this was addressed via #68

@achou11 achou11 closed this May 6, 2025
@achou11 achou11 deleted the feat/invite-hooks branch May 6, 2025 20:18
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.

2 participants