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

[WIP] fix: add invite hooks #47

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[WIP] fix: add invite hooks #47

wants to merge 1 commit into from

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

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.

1 participant