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

Feature Request: autoEnter for SpaceProvider #241

Open
pchr-srf opened this issue Nov 6, 2023 · 4 comments
Open

Feature Request: autoEnter for SpaceProvider #241

pchr-srf opened this issue Nov 6, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@pchr-srf
Copy link

pchr-srf commented Nov 6, 2023

Would it be possible to optionally enter spaces automatically? Personally, I see more use cases where I immediately want to enter a space than not.

Suggestion:

  <SpacesProvider client={spaces}>
    <SpaceProvider name="my-space" autoEnter={true} user={{ name: 'Luigi'}}>
      <App />
    </SpaceProvider>
  </SpacesProvider>

Right now we're solving this in a "hacky" way so we don't have to do it in each component separately:

<SpacesProvider client={spaces}>
  <SpaceProvider name="my-space">
    <EnterSpace user={user}>
      {children}
    </EnterSpace>
  </SpaceProvider>
</SpacesProvider>

...

const EnterSpace = ({ children, user }) => {
  const { space } = useSpace();
  const [spaceEntered, setSpaceEntered] = useState(false);
  useEffect(() => {
    const enterSpace = async () => {
      await space.enter(user);
      setSpaceEntered(true);
    };
    const leaveSpace = async () => {
      await space.leave();
    };
    if (space) {
      enterSpace();
    }
    return () => {
      if (space) {
        leaveSpace();
      }
    };
  }, [space, user]);

  if (!spaceEntered) {
    return <LoadingIndicator />
  }

  return <>{children}</>;
};

Or is there something we're missing?

@mattheworiordan
Copy link
Member

mattheworiordan commented Nov 15, 2023

Thanks for the suggested improvement @pchr-srf. One of our React engineers will reply shortly.

@dpiatek
Copy link
Contributor

dpiatek commented Nov 15, 2023

Thanks, @pchr-srf. This looks like a very practical improvement. I imagine you'd expect a way to pass something like <LoadingIndicator /> too.

I'll put this forward to our product team.

@pchr-srf
Copy link
Author

Hi @dpiatek and @mattheworiordan ! yeah exactly, that would be the idea 🙂
Thanks!

@dpiatek dpiatek added the enhancement New feature or request label Nov 28, 2023
@kobeaerts
Copy link

Hey, love the React Hooks implementation of Ably!

Do you guys have any indications when this feature would be available?
It's been a while since the "enhancement" label was added to this issue 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

4 participants