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

Implement hook for getting pending invites #8

Open
achou11 opened this issue Dec 12, 2024 · 0 comments
Open

Implement hook for getting pending invites #8

achou11 opened this issue Dec 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@achou11
Copy link
Member

achou11 commented Dec 12, 2024

Rough sketch of what we initially thought about:

export function usePendingInvites() {
	const queryClient = useQueryClient()
	const clientApi = useClientApi()

	const { data, isFetching } = useQuery(
		pendingInvitesQueryOptions({ clientApi }),
	)

	useEffect(() => {
		function onInviteEvent() {
			queryClient.invalidateQueries({ queryKey: getInvitesQueryKey() })
		}

		clientApi.invite.addListener('invite-received', onInviteEvent)
		clientApi.invite.addListener('invite-removed', onInviteEvent)

		return () => {
			clientApi.invite.removeListener('invite-received', onInviteEvent)
			clientApi.invite.removeListener('invite-removed', onInviteEvent)
		}
	}, [queryClient, clientApi.invite])


	// Not sure what this return value should be...
	return { data: dedupeInvites(data || []), isFetching }
}

Questions:

  • We had doubts about whether we wanted this hook to be suspense-based. Given that, not entirely sure what we want the return value to look like. Are we okay with this being one of those weird exceptions to the rest of the read hooks?

  • We had mentioned needing to dedupe the invites payload. Not exactly sure why or what that looks like right now.

  • Should we extract the effect to its own hook and expose that separately?

@achou11 achou11 added the enhancement New feature or request label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant